Show error when archiving files outside working directory

This commit is contained in:
timvisee 2019-06-20 21:22:03 +02:00
parent ce39eada4c
commit a7582ae765
No known key found for this signature in database
GPG key ID: B8DB720BC383E172

View file

@ -147,10 +147,27 @@ impl<'a> Upload<'a> {
let mut archiver = Archiver::new(archive_file); let mut archiver = Archiver::new(archive_file);
for path in &paths { for path in &paths {
// Find the relative path, get path name of file to add // Find the relative path, get path name of file to add
let path = diff_paths(Path::new(path), &working_dir) let mut path = Path::new(path).to_path_buf();
if let Ok(p) = path.canonicalize() {
path = p;
}
let path = diff_paths(&path, &working_dir)
.expect("failed to determine relative path of file to archive"); .expect("failed to determine relative path of file to archive");
let name = path.to_str().expect("failed to get file path"); let name = path.to_str().expect("failed to get file path");
// Files must all be in this directory
// TODO: find shared parent, and archive from there instead
if !matcher_main.force() && name.contains("..") {
quit_error_msg(
"when archiving, all files must be within the current working directory",
ErrorHintsBuilder::default()
.force(true)
.verbose(false)
.build()
.unwrap(),
);
}
// Add file to archiver // Add file to archiver
archiver archiver
.append_path(name, &path) .append_path(name, &path)