Show error when archiving files outside working directory
This commit is contained in:
parent
ce39eada4c
commit
a7582ae765
1 changed files with 18 additions and 1 deletions
|
@ -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)
|
||||||
|
|
Loading…
Reference in a new issue