@@ -110,11 +110,14 @@ pub enum ImageGlobalFlagsError {
110
110
#[ error( "could not create registry key for `{image}`" ) ]
111
111
CreateKey { image : ImageFile , source : io:: Error } ,
112
112
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 } ,
115
118
}
116
119
117
- const GFLAGS_KEY_NAME : & str = "GlobalFlag" ; // Singular
120
+ const GFLAGS_VALUE_NAME : & str = "GlobalFlag" ; // Singular
118
121
const GFLAGS_SHOW_LOADER_SNAPS : u32 = 0x2 ;
119
122
120
123
/// The global flags for an image file.
@@ -132,8 +135,8 @@ impl ImageGlobalFlags {
132
135
pub fn get_value ( & self ) -> Result < u32 , ImageGlobalFlagsError > {
133
136
let value = self
134
137
. 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 {
137
140
source,
138
141
image : self . image . clone ( ) ,
139
142
} ) ?;
@@ -143,8 +146,8 @@ impl ImageGlobalFlags {
143
146
144
147
pub fn set_value ( & self , value : u32 ) -> Result < ( ) , ImageGlobalFlagsError > {
145
148
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 {
148
151
source,
149
152
image : self . image . clone ( ) ,
150
153
} ) ?;
@@ -193,15 +196,19 @@ impl ImageLoaderSnapsGuard {
193
196
}
194
197
195
198
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
+
197
202
value |= GFLAGS_SHOW_LOADER_SNAPS ;
198
203
self . gflags . set_value ( value) ?;
199
204
200
205
Ok ( ( ) )
201
206
}
202
207
203
208
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
+
205
212
value &= !GFLAGS_SHOW_LOADER_SNAPS ;
206
213
self . gflags . set_value ( value) ?;
207
214
0 commit comments