mirror of
https://github.com/ouch-org/ouch.git
synced 2025-06-07 12:05:46 +00:00
Don't allow ouch
to compress the root folder
This commit is contained in:
parent
49e4c4afcd
commit
234e0406a1
@ -1,7 +1,4 @@
|
|||||||
use std::{
|
use std::{io::{Cursor, Write}, path::PathBuf};
|
||||||
io::{Cursor, Write},
|
|
||||||
path::PathBuf,
|
|
||||||
};
|
|
||||||
|
|
||||||
use walkdir::WalkDir;
|
use walkdir::WalkDir;
|
||||||
|
|
||||||
@ -57,7 +54,11 @@ impl ZipCompressor {
|
|||||||
for filename in input_filenames {
|
for filename in input_filenames {
|
||||||
|
|
||||||
let previous_location = utils::change_dir_and_return_parent(&filename)?;
|
let previous_location = utils::change_dir_and_return_parent(&filename)?;
|
||||||
let filename = filename.file_name()?;
|
let filename = filename
|
||||||
|
.file_name()
|
||||||
|
// Safe unwrap since the function call above would fail in scenarios
|
||||||
|
// where this unwrap would panic
|
||||||
|
.unwrap();
|
||||||
|
|
||||||
for entry in WalkDir::new(filename) {
|
for entry in WalkDir::new(filename) {
|
||||||
let entry = entry?;
|
let entry = entry?;
|
||||||
|
12
src/utils.rs
12
src/utils.rs
@ -63,7 +63,17 @@ pub(crate) fn get_destination_path(dest: &Option<File>) -> &Path {
|
|||||||
|
|
||||||
pub (crate) fn change_dir_and_return_parent(filename: &PathBuf) -> crate::Result<PathBuf> {
|
pub (crate) fn change_dir_and_return_parent(filename: &PathBuf) -> crate::Result<PathBuf> {
|
||||||
let previous_location = env::current_dir()?;
|
let previous_location = env::current_dir()?;
|
||||||
let parent = filename.parent().unwrap();
|
|
||||||
|
let parent = if let Some(parent) = filename.parent() {
|
||||||
|
parent
|
||||||
|
} else {
|
||||||
|
let spacing = " ";
|
||||||
|
println!("{} It seems you're trying to compress the root folder.", "[WARNING]".red());
|
||||||
|
println!("{}This is unadvisable since ouch does compressions in-memory.", spacing);
|
||||||
|
println!("{}Use a more appropriate tool for this, such as {}.", spacing, "rsync".green());
|
||||||
|
return Err(crate::Error::InvalidInput);
|
||||||
|
};
|
||||||
|
|
||||||
env::set_current_dir(parent)?;
|
env::set_current_dir(parent)?;
|
||||||
Ok(previous_location)
|
Ok(previous_location)
|
||||||
}
|
}
|
Loading…
x
Reference in New Issue
Block a user