Skip to content

Commit 32a5737

Browse files
authored
fix(errors): Show filenames in error message coming from ignore source (#215)
see rustic-rs/rustic#1122
1 parent f3ad6e9 commit 32a5737

File tree

2 files changed

+36
-14
lines changed

2 files changed

+36
-14
lines changed

crates/core/src/backend/ignore.rs

+28-7
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,10 @@ impl LocalSource {
165165

166166
for file in &filter_opts.glob_file {
167167
for line in std::fs::read_to_string(file)
168-
.map_err(IgnoreErrorKind::FromIoError)?
168+
.map_err(|err| IgnoreErrorKind::ErrorGlob {
169+
file: file.into(),
170+
err,
171+
})?
169172
.lines()
170173
{
171174
_ = override_builder
@@ -185,7 +188,10 @@ impl LocalSource {
185188

186189
for file in &filter_opts.iglob_file {
187190
for line in std::fs::read_to_string(file)
188-
.map_err(IgnoreErrorKind::FromIoError)?
191+
.map_err(|err| IgnoreErrorKind::ErrorGlob {
192+
file: file.into(),
193+
err,
194+
})?
189195
.lines()
190196
{
191197
_ = override_builder
@@ -254,7 +260,8 @@ impl ReadSourceOpen for OpenFile {
254260
/// [`IgnoreErrorKind::UnableToOpenFile`]: crate::error::IgnoreErrorKind::UnableToOpenFile
255261
fn open(self) -> RusticResult<Self::Reader> {
256262
let path = self.0;
257-
File::open(path).map_err(|err| IgnoreErrorKind::UnableToOpenFile(err).into())
263+
File::open(&path)
264+
.map_err(|err| IgnoreErrorKind::UnableToOpenFile { file: path, err }.into())
258265
}
259266
}
260267

@@ -400,7 +407,11 @@ fn map_entry(
400407
let node = if m.is_dir() {
401408
Node::new_node(name, NodeType::Dir, meta)
402409
} else if m.is_symlink() {
403-
let target = read_link(entry.path()).map_err(IgnoreErrorKind::FromIoError)?;
410+
let path = entry.path();
411+
let target = read_link(path).map_err(|err| IgnoreErrorKind::ErrorLink {
412+
path: path.to_path_buf(),
413+
err,
414+
})?;
404415
let node_type = NodeType::from_link(&target);
405416
Node::new_node(name, node_type, meta)
406417
} else {
@@ -522,12 +533,18 @@ fn map_entry(
522533
let extended_attributes = {
523534
let path = entry.path();
524535
xattr::list(path)
525-
.map_err(IgnoreErrorKind::FromIoError)?
536+
.map_err(|err| IgnoreErrorKind::ErrorXattr {
537+
path: path.to_path_buf(),
538+
err,
539+
})?
526540
.map(|name| {
527541
Ok(ExtendedAttribute {
528542
name: name.to_string_lossy().to_string(),
529543
value: xattr::get(path, name)
530-
.map_err(IgnoreErrorKind::FromIoError)?
544+
.map_err(|err| IgnoreErrorKind::ErrorXattr {
545+
path: path.to_path_buf(),
546+
err,
547+
})?
531548
.unwrap(),
532549
})
533550
})
@@ -554,7 +571,11 @@ fn map_entry(
554571
let node = if m.is_dir() {
555572
Node::new_node(name, NodeType::Dir, meta)
556573
} else if m.is_symlink() {
557-
let target = read_link(entry.path()).map_err(IgnoreErrorKind::FromIoError)?;
574+
let path = entry.path();
575+
let target = read_link(path).map_err(|err| IgnoreErrorKind::ErrorLink {
576+
path: path.to_path_buf(),
577+
err,
578+
})?;
558579
let node_type = NodeType::from_link(&target);
559580
Node::new_node(name, node_type, meta)
560581
} else if filetype.is_block_device() {

crates/core/src/error.rs

+8-7
Original file line numberDiff line numberDiff line change
@@ -578,16 +578,17 @@ pub enum CryptBackendErrorKind {
578578
pub enum IgnoreErrorKind {
579579
/// generic Ignore error: `{0:?}`
580580
GenericError(#[from] ignore::Error),
581-
/// Unable to open file: {0:?}
582-
UnableToOpenFile(std::io::Error),
583-
/// `{0:?}`
584-
#[error(transparent)]
585-
FromIoError(#[from] std::io::Error),
581+
/// Error reading glob file {file:?}: {err:?}
582+
ErrorGlob { file: PathBuf, err: std::io::Error },
583+
/// Unable to open file {file:?}: {err:?}
584+
UnableToOpenFile { file: PathBuf, err: std::io::Error },
585+
/// Error getting xattrs for {path:?}: {err:?}
586+
ErrorXattr { path: PathBuf, err: std::io::Error },
587+
/// Error reading link target for {path:?}: {err:?}
588+
ErrorLink { path: PathBuf, err: std::io::Error },
586589
/// `{0:?}`
587590
#[error(transparent)]
588591
FromTryFromIntError(#[from] TryFromIntError),
589-
/// no unicode link target. File: {file:?}, target: {target:?}
590-
TargetIsNotValidUnicode { file: PathBuf, target: PathBuf },
591592
}
592593

593594
/// [`LocalDestinationErrorKind`] describes the errors that can be returned by an action on the filesystem in Backends

0 commit comments

Comments
 (0)