Ignore broken symlinks when compressing

This commit is contained in:
Nbiba Bedis 2021-12-08 11:45:38 +01:00
parent 0976970e8c
commit 34c09d5d69
3 changed files with 24 additions and 2 deletions

View File

@ -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")

View 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)?;
}
}

View File

@ -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;