@@ -25,7 +25,7 @@ use crate::{
25
25
FileType , ReadBackend ,
26
26
} ,
27
27
blob:: BlobType ,
28
- error:: { CommandErrorKind , RusticErrorKind , RusticResult } ,
28
+ error:: { CommandErrorKind , IgnoreErrorKind , RusticErrorKind , RusticResult } ,
29
29
id:: Id ,
30
30
progress:: { Progress , ProgressBars } ,
31
31
repository:: { IndexedFull , IndexedTree , Open , Repository } ,
@@ -313,7 +313,11 @@ impl RestoreOptions {
313
313
)
314
314
} ) ?
315
315
. is_dir ( ) )
316
- || ( node. is_file ( ) && !destination. metadata ( ) . unwrap ( ) . is_file ( ) )
316
+ || ( node. is_file ( )
317
+ && !destination
318
+ . metadata ( )
319
+ . map_err ( IgnoreErrorKind :: GenericError ) ?
320
+ . is_file ( ) )
317
321
|| node. is_special ( )
318
322
{
319
323
// if types do not match, first remove the existing file
@@ -369,20 +373,20 @@ impl RestoreOptions {
369
373
if path. starts_with ( stack_path) {
370
374
break ;
371
375
}
372
- self . set_metadata ( dest, stack_path, stack_node) ;
376
+ self . set_metadata ( dest, stack_path, stack_node) ? ;
373
377
_ = dir_stack. pop ( ) ;
374
378
}
375
379
376
380
// push current path to the stack
377
381
dir_stack. push ( ( path, node) ) ;
378
382
} else {
379
- self . set_metadata ( dest, & path, & node) ;
383
+ self . set_metadata ( dest, & path, & node) ? ;
380
384
}
381
385
}
382
386
383
387
// empty dir stack and set metadata
384
388
for ( path, node) in dir_stack. into_iter ( ) . rev ( ) {
385
- self . set_metadata ( dest, & path, & node) ;
389
+ self . set_metadata ( dest, & path, & node) ? ;
386
390
}
387
391
388
392
Ok ( ( ) )
@@ -399,26 +403,57 @@ impl RestoreOptions {
399
403
/// # Errors
400
404
///
401
405
/// If the metadata could not be set.
402
- // TODO: Return a result here, introduce errors and get rid of logging.
403
- fn set_metadata ( self , dest : & LocalDestination , path : & PathBuf , node : & Node ) {
406
+ fn set_metadata (
407
+ self ,
408
+ dest : & LocalDestination ,
409
+ path : & PathBuf ,
410
+ node : & Node ,
411
+ ) -> RusticResult < ( ) > {
404
412
debug ! ( "setting metadata for {:?}" , path) ;
405
- dest. create_special ( path, node)
406
- . unwrap_or_else ( |_| warn ! ( "restore {:?}: creating special file failed." , path) ) ;
413
+
414
+ let mut errors = vec ! [ ] ;
415
+
416
+ if let Err ( err) = dest. create_special ( path, node) {
417
+ debug ! ( "restore {:?}: creating special file failed." , path) ;
418
+ errors. push ( err) ;
419
+ }
420
+
407
421
match ( self . no_ownership , self . numeric_id ) {
408
422
( true , _) => { }
409
- ( false , true ) => dest
410
- . set_uid_gid ( path, & node. meta )
411
- . unwrap_or_else ( |_| warn ! ( "restore {:?}: setting UID/GID failed." , path) ) ,
412
- ( false , false ) => dest
413
- . set_user_group ( path, & node. meta )
414
- . unwrap_or_else ( |_| warn ! ( "restore {:?}: setting User/Group failed." , path) ) ,
423
+ ( false , true ) => {
424
+ if let Err ( err) = dest. set_uid_gid ( path, & node. meta ) {
425
+ debug ! ( "restore {:?}: setting UID/GID failed." , path) ;
426
+ errors. push ( err) ;
427
+ }
428
+ }
429
+ ( false , false ) => {
430
+ if let Err ( err) = dest. set_user_group ( path, & node. meta ) {
431
+ debug ! ( "restore {:?}: setting User/Group failed." , path) ;
432
+ errors. push ( err) ;
433
+ }
434
+ }
415
435
}
416
- dest. set_permission ( path, node)
417
- . unwrap_or_else ( |_| warn ! ( "restore {:?}: chmod failed." , path) ) ;
418
- dest. set_extended_attributes ( path, & node. meta . extended_attributes )
419
- . unwrap_or_else ( |_| warn ! ( "restore {:?}: setting extended attributes failed." , path) ) ;
420
- dest. set_times ( path, & node. meta )
421
- . unwrap_or_else ( |_| warn ! ( "restore {:?}: setting file times failed." , path) ) ;
436
+
437
+ if let Err ( err) = dest. set_permission ( path, node) {
438
+ debug ! ( "restore {:?}: chmod failed." , path) ;
439
+ errors. push ( err) ;
440
+ } ;
441
+
442
+ if let Err ( err) = dest. set_extended_attributes ( path, & node. meta . extended_attributes ) {
443
+ debug ! ( "restore {:?}: setting extended attributes failed." , path) ;
444
+ errors. push ( err) ;
445
+ } ;
446
+
447
+ if let Err ( err) = dest. set_times ( path, & node. meta ) {
448
+ debug ! ( "restore {:?}: setting file times failed." , path) ;
449
+ errors. push ( err) ;
450
+ } ;
451
+
452
+ if !errors. is_empty ( ) {
453
+ return Err ( CommandErrorKind :: ErrorSettingMetadata ( path. clone ( ) , errors) . into ( ) ) ;
454
+ }
455
+
456
+ Ok ( ( ) )
422
457
}
423
458
}
424
459
0 commit comments