Skip to content

Commit

Permalink
Display path in the warning msg when file metadata can't be accessed
Browse files Browse the repository at this point in the history
Before:
    warn: Permission denied (os error 13)

After:
    warn: Failed to read metadata of /.../file.txt: Permission
    denied (os error 13)

Fixes #147
  • Loading branch information
pkolaczk committed Aug 26, 2022
1 parent c92b497 commit 2abb370
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion src/file.rs
Original file line number Diff line number Diff line change
Expand Up @@ -290,7 +290,12 @@ pub struct FileMetadata {
impl FileMetadata {
pub fn new(path: &Path) -> io::Result<FileMetadata> {
let path_buf = path.to_path_buf();
let metadata = fs::metadata(&path_buf)?;
let metadata = fs::metadata(&path_buf).map_err(|e| {
io::Error::new(
e.kind(),
format!("Failed to read metadata of {}: {}", path.display(), e),
)
})?;
#[cfg(unix)]
let id = FileId::from_metadata(&metadata);
#[cfg(windows)]
Expand Down

0 comments on commit 2abb370

Please sign in to comment.