@@ -95,23 +95,23 @@ struct RevokeOpts {
95
95
#[ derive( Error , Debug ) ]
96
96
pub enum DeactivateError {
97
97
#[ error( "Failed to execute the rollback command: {0}" ) ]
98
- RollbackError ( std:: io:: Error ) ,
98
+ Rollback ( std:: io:: Error ) ,
99
99
#[ error( "The rollback resulted in a bad exit code: {0:?}" ) ]
100
- RollbackExitError ( Option < i32 > ) ,
100
+ RollbackExit ( Option < i32 > ) ,
101
101
#[ error( "Failed to run command for listing generations: {0}" ) ]
102
- ListGenError ( std:: io:: Error ) ,
102
+ ListGen ( std:: io:: Error ) ,
103
103
#[ error( "Command for listing generations resulted in a bad exit code: {0:?}" ) ]
104
- ListGenExitError ( Option < i32 > ) ,
104
+ ListGenExit ( Option < i32 > ) ,
105
105
#[ error( "Error converting generation list output to utf8: {0}" ) ]
106
- DecodeListGenUtf8Error ( # [ from ] std:: string:: FromUtf8Error ) ,
106
+ DecodeListGenUtf8 ( std:: string:: FromUtf8Error ) ,
107
107
#[ error( "Failed to run command for deleting generation: {0}" ) ]
108
- DeleteGenError ( std:: io:: Error ) ,
108
+ DeleteGen ( std:: io:: Error ) ,
109
109
#[ error( "Command for deleting generations resulted in a bad exit code: {0:?}" ) ]
110
- DeleteGenExitError ( Option < i32 > ) ,
110
+ DeleteGenExit ( Option < i32 > ) ,
111
111
#[ error( "Failed to run command for re-activating the last generation: {0}" ) ]
112
- ReactivateError ( std:: io:: Error ) ,
112
+ Reactivate ( std:: io:: Error ) ,
113
113
#[ error( "Command for re-activating the last generation resulted in a bad exit code: {0:?}" ) ]
114
- ReactivateExitError ( Option < i32 > ) ,
114
+ ReactivateExit ( Option < i32 > ) ,
115
115
}
116
116
117
117
pub async fn deactivate ( profile_path : & str ) -> Result < ( ) , DeactivateError > {
@@ -123,11 +123,11 @@ pub async fn deactivate(profile_path: &str) -> Result<(), DeactivateError> {
123
123
. arg ( "--rollback" )
124
124
. status ( )
125
125
. await
126
- . map_err ( DeactivateError :: RollbackError ) ?;
126
+ . map_err ( DeactivateError :: Rollback ) ?;
127
127
128
128
match nix_env_rollback_exit_status. code ( ) {
129
129
Some ( 0 ) => ( ) ,
130
- a => return Err ( DeactivateError :: RollbackExitError ( a) ) ,
130
+ a => return Err ( DeactivateError :: RollbackExit ( a) ) ,
131
131
} ;
132
132
133
133
debug ! ( "Listing generations" ) ;
@@ -138,14 +138,15 @@ pub async fn deactivate(profile_path: &str) -> Result<(), DeactivateError> {
138
138
. arg ( "--list-generations" )
139
139
. output ( )
140
140
. await
141
- . map_err ( DeactivateError :: ListGenError ) ?;
141
+ . map_err ( DeactivateError :: ListGen ) ?;
142
142
143
143
match nix_env_list_generations_out. status . code ( ) {
144
144
Some ( 0 ) => ( ) ,
145
- a => return Err ( DeactivateError :: ListGenExitError ( a) ) ,
145
+ a => return Err ( DeactivateError :: ListGenExit ( a) ) ,
146
146
} ;
147
147
148
- let generations_list = String :: from_utf8 ( nix_env_list_generations_out. stdout ) ?;
148
+ let generations_list = String :: from_utf8 ( nix_env_list_generations_out. stdout )
149
+ . map_err ( DeactivateError :: DecodeListGenUtf8 ) ?;
149
150
150
151
let last_generation_line = generations_list
151
152
. lines ( )
@@ -167,11 +168,11 @@ pub async fn deactivate(profile_path: &str) -> Result<(), DeactivateError> {
167
168
. arg ( last_generation_id)
168
169
. status ( )
169
170
. await
170
- . map_err ( DeactivateError :: DeleteGenError ) ?;
171
+ . map_err ( DeactivateError :: DeleteGen ) ?;
171
172
172
173
match nix_env_delete_generation_exit_status. code ( ) {
173
174
Some ( 0 ) => ( ) ,
174
- a => return Err ( DeactivateError :: DeleteGenExitError ( a) ) ,
175
+ a => return Err ( DeactivateError :: DeleteGenExit ( a) ) ,
175
176
} ;
176
177
177
178
info ! ( "Attempting to re-activate the last generation" ) ;
@@ -181,11 +182,11 @@ pub async fn deactivate(profile_path: &str) -> Result<(), DeactivateError> {
181
182
. current_dir ( & profile_path)
182
183
. status ( )
183
184
. await
184
- . map_err ( DeactivateError :: ReactivateError ) ?;
185
+ . map_err ( DeactivateError :: Reactivate ) ?;
185
186
186
187
match re_activate_exit_status. code ( ) {
187
188
Some ( 0 ) => ( ) ,
188
- a => return Err ( DeactivateError :: ReactivateExitError ( a) ) ,
189
+ a => return Err ( DeactivateError :: ReactivateExit ( a) ) ,
189
190
} ;
190
191
191
192
Ok ( ( ) )
@@ -194,15 +195,11 @@ pub async fn deactivate(profile_path: &str) -> Result<(), DeactivateError> {
194
195
#[ derive( Error , Debug ) ]
195
196
pub enum ActivationConfirmationError {
196
197
#[ error( "Failed to create activation confirmation directory: {0}" ) ]
197
- CreateConfirmDirError ( std:: io:: Error ) ,
198
+ CreateConfirmDir ( std:: io:: Error ) ,
198
199
#[ error( "Failed to create activation confirmation file: {0}" ) ]
199
- CreateConfirmFileError ( std:: io:: Error ) ,
200
- #[ error( "Failed to create file system watcher instance: {0}" ) ]
201
- CreateWatcherError ( notify:: Error ) ,
202
- #[ error( "Error forking process: {0}" ) ]
203
- ForkError ( i32 ) ,
200
+ CreateConfirmFile ( std:: io:: Error ) ,
204
201
#[ error( "Could not watch for activation sentinel: {0}" ) ]
205
- WatcherError ( #[ from] notify:: Error ) ,
202
+ Watcher ( #[ from] notify:: Error ) ,
206
203
}
207
204
208
205
#[ derive( Error , Debug ) ]
@@ -212,7 +209,7 @@ pub enum DangerZoneError {
212
209
#[ error( "inotify stream ended without activation confirmation" ) ]
213
210
NoConfirmation ,
214
211
#[ error( "inotify encountered an error: {0}" ) ]
215
- WatchError ( notify:: Error ) ,
212
+ Watch ( notify:: Error ) ,
216
213
}
217
214
218
215
async fn danger_zone (
@@ -223,7 +220,7 @@ async fn danger_zone(
223
220
224
221
match timeout ( Duration :: from_secs ( confirm_timeout as u64 ) , events. recv ( ) ) . await {
225
222
Ok ( Some ( Ok ( ( ) ) ) ) => Ok ( ( ) ) ,
226
- Ok ( Some ( Err ( e) ) ) => Err ( DangerZoneError :: WatchError ( e) ) ,
223
+ Ok ( Some ( Err ( e) ) ) => Err ( DangerZoneError :: Watch ( e) ) ,
227
224
Ok ( None ) => Err ( DangerZoneError :: NoConfirmation ) ,
228
225
Err ( _) => Err ( DangerZoneError :: TimesUp ) ,
229
226
}
@@ -242,14 +239,14 @@ pub async fn activation_confirmation(
242
239
if let Some ( parent) = Path :: new ( & lock_path) . parent ( ) {
243
240
fs:: create_dir_all ( parent)
244
241
. await
245
- . map_err ( ActivationConfirmationError :: CreateConfirmDirError ) ?;
242
+ . map_err ( ActivationConfirmationError :: CreateConfirmDir ) ?;
246
243
}
247
244
248
245
debug ! ( "Creating canary file" ) ;
249
246
250
247
fs:: File :: create ( & lock_path)
251
248
. await
252
- . map_err ( ActivationConfirmationError :: CreateConfirmFileError ) ?;
249
+ . map_err ( ActivationConfirmationError :: CreateConfirmFile ) ?;
253
250
254
251
debug ! ( "Creating notify watcher" ) ;
255
252
@@ -342,20 +339,20 @@ pub async fn wait(temp_path: String, closure: String) -> Result<(), WaitError> {
342
339
#[ derive( Error , Debug ) ]
343
340
pub enum ActivateError {
344
341
#[ error( "Failed to execute the command for setting profile: {0}" ) ]
345
- SetProfileError ( std:: io:: Error ) ,
342
+ SetProfile ( std:: io:: Error ) ,
346
343
#[ error( "The command for setting profile resulted in a bad exit code: {0:?}" ) ]
347
- SetProfileExitError ( Option < i32 > ) ,
344
+ SetProfileExit ( Option < i32 > ) ,
348
345
349
346
#[ error( "Failed to execute the activation script: {0}" ) ]
350
- RunActivateError ( std:: io:: Error ) ,
347
+ RunActivate ( std:: io:: Error ) ,
351
348
#[ error( "The activation script resulted in a bad exit code: {0:?}" ) ]
352
- RunActivateExitError ( Option < i32 > ) ,
349
+ RunActivateExit ( Option < i32 > ) ,
353
350
354
351
#[ error( "There was an error de-activating after an error was encountered: {0}" ) ]
355
- DeactivateError ( #[ from] DeactivateError ) ,
352
+ Deactivate ( #[ from] DeactivateError ) ,
356
353
357
354
#[ error( "Failed to get activation confirmation: {0}" ) ]
358
- ActivationConfirmationError ( #[ from] ActivationConfirmationError ) ,
355
+ ActivationConfirmation ( #[ from] ActivationConfirmationError ) ,
359
356
}
360
357
361
358
pub async fn activate (
@@ -376,14 +373,14 @@ pub async fn activate(
376
373
. arg ( & closure)
377
374
. status ( )
378
375
. await
379
- . map_err ( ActivateError :: SetProfileError ) ?;
376
+ . map_err ( ActivateError :: SetProfile ) ?;
380
377
match nix_env_set_exit_status. code ( ) {
381
378
Some ( 0 ) => ( ) ,
382
379
a => {
383
380
if auto_rollback && !dry_activate {
384
381
deactivate ( & profile_path) . await ?;
385
382
}
386
- return Err ( ActivateError :: SetProfileExitError ( a) ) ;
383
+ return Err ( ActivateError :: SetProfileExit ( a) ) ;
387
384
}
388
385
} ;
389
386
}
@@ -402,7 +399,7 @@ pub async fn activate(
402
399
. current_dir ( activation_location)
403
400
. status ( )
404
401
. await
405
- . map_err ( ActivateError :: RunActivateError )
402
+ . map_err ( ActivateError :: RunActivate )
406
403
{
407
404
Ok ( x) => x,
408
405
Err ( e) => {
@@ -420,7 +417,7 @@ pub async fn activate(
420
417
if auto_rollback {
421
418
deactivate ( & profile_path) . await ?;
422
419
}
423
- return Err ( ActivateError :: RunActivateExitError ( a) ) ;
420
+ return Err ( ActivateError :: RunActivateExit ( a) ) ;
424
421
}
425
422
} ;
426
423
@@ -437,7 +434,7 @@ pub async fn activate(
437
434
Ok ( ( ) ) => { }
438
435
Err ( err) => {
439
436
deactivate ( & profile_path) . await ?;
440
- return Err ( ActivateError :: ActivationConfirmationError ( err) ) ;
437
+ return Err ( ActivateError :: ActivationConfirmation ( err) ) ;
441
438
}
442
439
} ;
443
440
}
@@ -446,12 +443,7 @@ pub async fn activate(
446
443
Ok ( ( ) )
447
444
}
448
445
449
- #[ derive( Error , Debug ) ]
450
- pub enum RevokeError {
451
- #[ error( "There was an error de-activating after an error was encountered: {0}" ) ]
452
- DeactivateError ( #[ from] DeactivateError ) ,
453
- }
454
- async fn revoke ( profile_path : String ) -> Result < ( ) , RevokeError > {
446
+ async fn revoke ( profile_path : String ) -> Result < ( ) , DeactivateError > {
455
447
deactivate ( profile_path. as_str ( ) ) . await ?;
456
448
Ok ( ( ) )
457
449
}
@@ -462,7 +454,7 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
462
454
let mut signals = Signals :: new ( & [ SIGHUP ] ) ?;
463
455
std:: thread:: spawn ( move || {
464
456
for _ in signals. forever ( ) {
465
- println ! ( "Received NOHUP - ignoring..." ) ;
457
+ println ! ( "Received SIGHUP - ignoring..." ) ;
466
458
}
467
459
} ) ;
468
460
@@ -471,7 +463,7 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
471
463
deploy:: init_logger (
472
464
opts. debug_logs ,
473
465
opts. log_dir . as_deref ( ) ,
474
- match opts. subcmd {
466
+ & match opts. subcmd {
475
467
SubCommand :: Activate ( _) => deploy:: LoggerType :: Activate ,
476
468
SubCommand :: Wait ( _) => deploy:: LoggerType :: Wait ,
477
469
SubCommand :: Revoke ( _) => deploy:: LoggerType :: Revoke ,
0 commit comments