mirror of
https://github.com/ouch-org/ouch.git
synced 2025-06-07 12:05:46 +00:00
Ignore broken symlinks when compressing
This commit is contained in:
parent
0976970e8c
commit
34c09d5d69
@ -90,7 +90,17 @@ where
|
||||
if path.is_dir() {
|
||||
builder.append_dir(path, path)?;
|
||||
} else {
|
||||
let mut file = fs::File::open(path)?;
|
||||
let mut file = match fs::File::open(path) {
|
||||
Ok(f) => f,
|
||||
Err(e) => {
|
||||
if e.kind() == std::io::ErrorKind::NotFound && path.is_symlink() {
|
||||
// This path is for a broken symlink
|
||||
// We just ignore it
|
||||
continue;
|
||||
}
|
||||
return Err(e.into());
|
||||
}
|
||||
};
|
||||
builder.append_file(path, file.file_mut()).map_err(|err| {
|
||||
FinalError::with_title("Could not create archive")
|
||||
.detail("Unexpected error while trying to read file")
|
||||
|
@ -142,7 +142,17 @@ where
|
||||
// If a dir has files, the files are responsible for creating them.
|
||||
} else {
|
||||
writer.start_file(path.to_str().unwrap().to_owned(), options)?;
|
||||
let file_bytes = fs::read(entry.path())?;
|
||||
let file_bytes = match fs::read(entry.path()) {
|
||||
Ok(b) => b,
|
||||
Err(e) => {
|
||||
if e.kind() == std::io::ErrorKind::NotFound && path.is_symlink() {
|
||||
// This path is for a broken symlink
|
||||
// We just ignore it
|
||||
continue;
|
||||
}
|
||||
return Err(e.into());
|
||||
}
|
||||
};
|
||||
writer.write_all(&*file_bytes)?;
|
||||
}
|
||||
}
|
||||
|
@ -5,6 +5,8 @@
|
||||
// used as a binary. Since `clap` doesn't remove URL markup in it's help output,
|
||||
// we don't mark them as URLs. This suppresses the relevant rustdoc warning:
|
||||
#![allow(rustdoc::bare_urls)]
|
||||
// Useful to detect broken symlinks when compressing. (So we can safely ignore them)
|
||||
#![feature(is_symlink)]
|
||||
|
||||
// Macros should be declared before
|
||||
pub mod macros;
|
||||
|
Loading…
x
Reference in New Issue
Block a user