Skip to content

Commit 8678e35

Browse files
committed
more results
Signed-off-by: simonsan <[email protected]>
1 parent f68034b commit 8678e35

File tree

4 files changed

+84
-23
lines changed

4 files changed

+84
-23
lines changed

crates/core/src/blob/packer.rs

+12-1
Original file line numberDiff line numberDiff line change
@@ -521,6 +521,7 @@ impl<BE: DecryptWriteBackend> RawPacker<BE> {
521521
if self.has(id) {
522522
return Ok(());
523523
}
524+
524525
self.stats.blobs += 1;
525526
self.stats.data += data_len;
526527
let data_len_packed: u64 = data
@@ -726,8 +727,14 @@ impl Actor {
726727
fn finalize(self) -> RusticResult<()> {
727728
// cancel channel
728729
drop(self.sender);
730+
729731
// wait for items in channel to be processed
730-
self.finish.recv().unwrap()
732+
let _ = self
733+
.finish
734+
.recv()
735+
.map_err(PackerErrorKind::ReceivingCrossbeamMessageFailedForActorFinalizing)?;
736+
737+
Ok(())
731738
}
732739
}
733740

@@ -805,13 +812,15 @@ impl<BE: DecryptFullBackend> Repacker<BE> {
805812
blob.length,
806813
)
807814
.map_err(RusticErrorKind::Backend)?;
815+
808816
self.packer.add_raw(
809817
&data,
810818
&blob.id,
811819
0,
812820
blob.uncompressed_length,
813821
Some(self.size_limit),
814822
)?;
823+
815824
Ok(())
816825
}
817826

@@ -835,8 +844,10 @@ impl<BE: DecryptFullBackend> Repacker<BE> {
835844
blob.length,
836845
blob.uncompressed_length,
837846
)?;
847+
838848
self.packer
839849
.add_with_sizelimit(data, blob.id, Some(self.size_limit))?;
850+
840851
Ok(())
841852
}
842853

crates/core/src/commands/prune.rs

+10-1
Original file line numberDiff line numberDiff line change
@@ -1165,22 +1165,31 @@ impl PrunePlan {
11651165
if !self.existing_packs.is_empty() {
11661166
if opts.instant_delete {
11671167
let p = pb.progress_counter("removing unindexed packs...");
1168+
11681169
let existing_packs: Vec<_> = self.existing_packs.into_keys().collect();
1170+
11691171
be.delete_list(FileType::Pack, true, existing_packs.iter(), p)?;
11701172
} else {
11711173
let p =
11721174
pb.progress_counter("marking unneeded unindexed pack files for deletion...");
1173-
p.set_length(self.existing_packs.len().try_into().unwrap());
1175+
1176+
p.set_length(u64::try_from(self.existing_packs.len()).map_err(|_| {
1177+
CommandErrorKind::TooManyPacksToDelete(self.existing_packs.len())
1178+
})?);
1179+
11741180
for (id, size) in self.existing_packs {
11751181
let pack = IndexPack {
11761182
id,
11771183
size: Some(size),
11781184
time: Some(Local::now()),
11791185
blobs: Vec::new(),
11801186
};
1187+
11811188
indexer.write().add_remove(pack)?;
1189+
11821190
p.inc(1);
11831191
}
1192+
11841193
p.finish();
11851194
}
11861195
}

crates/core/src/commands/restore.rs

+56-21
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ use crate::{
2525
FileType, ReadBackend,
2626
},
2727
blob::BlobType,
28-
error::{CommandErrorKind, RusticErrorKind, RusticResult},
28+
error::{CommandErrorKind, IgnoreErrorKind, RusticErrorKind, RusticResult},
2929
id::Id,
3030
progress::{Progress, ProgressBars},
3131
repository::{IndexedFull, IndexedTree, Open, Repository},
@@ -313,7 +313,11 @@ impl RestoreOptions {
313313
)
314314
})?
315315
.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())
317321
|| node.is_special()
318322
{
319323
// if types do not match, first remove the existing file
@@ -369,20 +373,20 @@ impl RestoreOptions {
369373
if path.starts_with(stack_path) {
370374
break;
371375
}
372-
self.set_metadata(dest, stack_path, stack_node);
376+
self.set_metadata(dest, stack_path, stack_node)?;
373377
_ = dir_stack.pop();
374378
}
375379

376380
// push current path to the stack
377381
dir_stack.push((path, node));
378382
} else {
379-
self.set_metadata(dest, &path, &node);
383+
self.set_metadata(dest, &path, &node)?;
380384
}
381385
}
382386

383387
// empty dir stack and set metadata
384388
for (path, node) in dir_stack.into_iter().rev() {
385-
self.set_metadata(dest, &path, &node);
389+
self.set_metadata(dest, &path, &node)?;
386390
}
387391

388392
Ok(())
@@ -399,26 +403,57 @@ impl RestoreOptions {
399403
/// # Errors
400404
///
401405
/// 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<()> {
404412
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+
407421
match (self.no_ownership, self.numeric_id) {
408422
(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+
}
415435
}
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(())
422457
}
423458
}
424459

crates/core/src/error.rs

+6
Original file line numberDiff line numberDiff line change
@@ -234,6 +234,10 @@ pub enum CommandErrorKind {
234234
#[source]
235235
source: OutOfRangeError,
236236
},
237+
/// There are too many packs to delete: `{0}`
238+
TooManyPacksToDelete(usize),
239+
/// error setting metadata for {0:?}: {1:?}
240+
ErrorSettingMetadata(PathBuf, Vec<RusticError>),
237241
}
238242

239243
/// [`CryptoErrorKind`] describes the errors that can happen while dealing with Cryptographic functions
@@ -508,6 +512,8 @@ pub enum PackerErrorKind {
508512
FileWriterHandleNotPresent,
509513
/// failed to receive message for PackerStats: `{0:?}`
510514
ReceivingCrossbeamMessageFailedForPackerStats(crossbeam_channel::RecvError),
515+
/// failed to receive message: `{0:?}`
516+
ReceivingCrossbeamMessageFailedForActorFinalizing(crossbeam_channel::RecvError),
511517
}
512518

513519
/// [`TreeErrorKind`] describes the errors that can come up dealing with Trees

0 commit comments

Comments
 (0)