Skip to content

Commit 5db575d

Browse files
committed
adapt check errors
1 parent 4a34307 commit 5db575d

File tree

6 files changed

+36
-4693
lines changed

6 files changed

+36
-4693
lines changed

crates/core/src/commands/check.rs

Lines changed: 22 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ use std::{
33
collections::{BTreeMap, BTreeSet, HashMap},
44
fmt::Debug,
55
num::ParseIntError,
6-
path::PathBuf,
76
str::FromStr,
87
sync::Mutex,
98
};
@@ -35,6 +34,7 @@ use crate::{
3534
IndexFile, IndexPack, PackHeader, PackHeaderLength, PackHeaderRef, packfile::PackId,
3635
},
3736
repository::{Open, Repository},
37+
util::SerializablePath,
3838
};
3939

4040
#[derive(Clone, Copy, Debug, Default)]
@@ -643,22 +643,22 @@ fn check_trees(
643643
NodeType::File => node.content.as_ref().map_or_else(
644644
|| {
645645
collector.add_error(CheckError::FileHasNoContent {
646-
file: path.join(node.name()),
646+
file: SerializablePath(path.join(node.name())),
647647
});
648648
},
649649
|content| {
650650
for (i, id) in content.iter().enumerate() {
651651
if id.is_null() {
652652
collector.add_error(CheckError::FileBlobHasNullId {
653-
file: path.join(node.name()),
653+
file: SerializablePath(path.join(node.name())),
654654
blob_num: i,
655655
});
656656
}
657657

658658
match index.get_data(id) {
659659
None => {
660660
collector.add_error(CheckError::FileBlobNotInIndex {
661-
file: path.join(node.name()),
661+
file: SerializablePath(path.join(node.name())),
662662
blob_id: *id,
663663
});
664664
}
@@ -673,17 +673,17 @@ fn check_trees(
673673
NodeType::Dir => {
674674
match node.subtree {
675675
None => collector.add_error(CheckError::NoSubTree {
676-
dir: path.join(node.name()),
676+
dir: SerializablePath(path.join(node.name())),
677677
}),
678678
Some(tree) if tree.is_null() => {
679679
collector.add_error(CheckError::NullSubTree {
680-
dir: path.join(node.name()),
680+
dir: SerializablePath(path.join(node.name())),
681681
});
682682
}
683683
Some(id) => match index.get_tree(&id) {
684684
None => {
685685
collector.add_error(CheckError::SubTreeMissingInIndex {
686-
dir: path.join(node.name()),
686+
dir: SerializablePath(path.join(node.name())),
687687
blob_id: id,
688688
});
689689
}
@@ -887,17 +887,26 @@ pub enum CheckError {
887887
/// pack {id} is referenced by the index but not present! To repair: 'rustic repair index'.
888888
NoPack { id: PackId },
889889
/// file {file:?} doesn't have a content
890-
FileHasNoContent { file: PathBuf },
890+
FileHasNoContent { file: SerializablePath },
891891
/// file {file:?} blob {blob_num} has null ID
892-
FileBlobHasNullId { file: PathBuf, blob_num: usize },
892+
FileBlobHasNullId {
893+
file: SerializablePath,
894+
blob_num: usize,
895+
},
893896
/// file {file:?} blob {blob_id} is missing in index
894-
FileBlobNotInIndex { file: PathBuf, blob_id: DataId },
897+
FileBlobNotInIndex {
898+
file: SerializablePath,
899+
blob_id: DataId,
900+
},
895901
/// dir {dir:?} doesn't have a subtree
896-
NoSubTree { dir: PathBuf },
902+
NoSubTree { dir: SerializablePath },
897903
/// "dir {dir:?} subtree has null ID
898-
NullSubTree { dir: PathBuf },
904+
NullSubTree { dir: SerializablePath },
899905
/// "dir {dir:?} subtree blob {blob_id} is missing in index",
900-
SubTreeMissingInIndex { dir: PathBuf, blob_id: TreeId },
906+
SubTreeMissingInIndex {
907+
dir: SerializablePath,
908+
blob_id: TreeId,
909+
},
901910
/// pack {id}: data size does not match expected size. Read: {size} bytes, expected: {expected} bytes
902911
PackSizeMismatch {
903912
id: PackId,

crates/core/src/util.rs

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
///
33
use std::{
44
borrow::Cow,
5+
fmt::Debug,
56
path::{Path, PathBuf},
67
str::Utf8Error,
78
};
@@ -12,9 +13,9 @@ use typed_path::{
1213
WindowsPrefix,
1314
};
1415

15-
#[derive(Debug, PartialEq, Eq, PartialOrd, Ord, Serialize)]
16+
#[derive(PartialEq, Eq, PartialOrd, Ord, Serialize)]
1617
#[serde(transparent)]
17-
/// Like `UnixPathBuf`, but implements `Serialize`
18+
/// Like `UnixPathBuf`, but implements `Serialize` and a nicer `Debug`
1819
pub struct SerializablePath(#[serde(serialize_with = "serialize_unix_path")] pub UnixPathBuf);
1920

2021
fn serialize_unix_path<S>(path: &UnixPath, serializer: S) -> Result<S::Ok, S::Error>
@@ -25,6 +26,12 @@ where
2526
serializer.serialize_str(&s)
2627
}
2728

29+
impl Debug for SerializablePath {
30+
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
31+
write!(f, "{}", self.0.display())
32+
}
33+
}
34+
2835
/// Converts a [`Path`] to a [`WindowsPath`].
2936
///
3037
/// # Arguments

crates/core/tests/integration/check.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ use rustic_core::{CheckOptions, Repository, RepositoryBackends, RepositoryOption
1313
#[rstest]
1414
#[case("repo-data-missing.tar.gz")]
1515
#[case("repo-duplicates.tar.gz")]
16-
// #[case("repo-index-missing-blob.tar.gz")] TODO: Activate when paths are identical for unix/windows
16+
#[case("repo-index-missing-blob.tar.gz")]
1717
#[case("repo-index-missing.tar.gz")]
1818
#[case("repo-mixed.tar.gz")]
1919
#[case("repo-obsolete-index.tar.gz")]

crates/core/tests/integration/snapshots/integration__integration__check__repo-index-missing-blob.tar.gz.snap

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22
source: crates/core/tests/integration/check.rs
33
expression: check_results
44
---
5-
CheckResults {
6-
errors: [
5+
CheckResults(
6+
[
77
(
88
Warn,
99
PackNotReferenced {
@@ -19,11 +19,11 @@ CheckResults {
1919
(
2020
Error,
2121
FileBlobNotInIndex {
22-
file: "home/thinkpad/data/test",
22+
file: home/thinkpad/data/test,
2323
blob_id: DataId(
2424
f2ca1bb6c7e907d06dafe4687e579fce76b37e4e93b7605022da52e6ccc26fd2,
2525
),
2626
},
2727
),
2828
],
29-
}
29+
)
Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
---
22
source: crates/core/tests/integration/find.rs
3-
assertion_line: 45
43
expression: not_found
54
---
65
FindMatches {

0 commit comments

Comments
 (0)