@@ -110,11 +110,14 @@ pub enum ImageGlobalFlagsError {
110110 #[ error( "could not create registry key for `{image}`" ) ]
111111 CreateKey { image : ImageFile , source : io:: Error } ,
112112
113- #[ error( "could not access `GlobalFlag` value of registry key for `{image}`" ) ]
114- AccessValue { image : ImageFile , source : io:: Error } ,
113+ #[ error( "could not get `GlobalFlag` value of registry key for `{image}`" ) ]
114+ GetValue { image : ImageFile , source : io:: Error } ,
115+
116+ #[ error( "could not set `GlobalFlag` value of registry key for `{image}`" ) ]
117+ SetValue { image : ImageFile , source : io:: Error } ,
115118}
116119
117- const GFLAGS_KEY_NAME : & str = "GlobalFlag" ; // Singular
120+ const GFLAGS_VALUE_NAME : & str = "GlobalFlag" ; // Singular
118121const GFLAGS_SHOW_LOADER_SNAPS : u32 = 0x2 ;
119122
120123/// The global flags for an image file.
@@ -132,8 +135,8 @@ impl ImageGlobalFlags {
132135 pub fn get_value ( & self ) -> Result < u32 , ImageGlobalFlagsError > {
133136 let value = self
134137 . create_key ( ) ?
135- . get_value ( GFLAGS_KEY_NAME )
136- . map_err ( |source| ImageGlobalFlagsError :: AccessValue {
138+ . get_value ( GFLAGS_VALUE_NAME )
139+ . map_err ( |source| ImageGlobalFlagsError :: GetValue {
137140 source,
138141 image : self . image . clone ( ) ,
139142 } ) ?;
@@ -143,8 +146,8 @@ impl ImageGlobalFlags {
143146
144147 pub fn set_value ( & self , value : u32 ) -> Result < ( ) , ImageGlobalFlagsError > {
145148 self . create_key ( ) ?
146- . set_value ( GFLAGS_KEY_NAME , & value)
147- . map_err ( |source| ImageGlobalFlagsError :: AccessValue {
149+ . set_value ( GFLAGS_VALUE_NAME , & value)
150+ . map_err ( |source| ImageGlobalFlagsError :: SetValue {
148151 source,
149152 image : self . image . clone ( ) ,
150153 } ) ?;
@@ -193,15 +196,19 @@ impl ImageLoaderSnapsGuard {
193196 }
194197
195198 fn enable ( & self ) -> Result < ( ) , ImageGlobalFlagsError > {
196- let mut value = self . gflags . get_value ( ) ?;
199+ // Value may not yet exist.
200+ let mut value = self . gflags . get_value ( ) . unwrap_or ( 0x0 ) ;
201+
197202 value |= GFLAGS_SHOW_LOADER_SNAPS ;
198203 self . gflags . set_value ( value) ?;
199204
200205 Ok ( ( ) )
201206 }
202207
203208 fn disable ( & self ) -> Result < ( ) , ImageGlobalFlagsError > {
204- let mut value = self . gflags . get_value ( ) ?;
209+ // Value may not yet exist.
210+ let mut value = self . gflags . get_value ( ) . unwrap_or ( 0x0 ) ;
211+
205212 value &= !GFLAGS_SHOW_LOADER_SNAPS ;
206213 self . gflags . set_value ( value) ?;
207214
0 commit comments