mirror of
https://github.com/ouch-org/ouch.git
synced 2025-06-07 20:15:27 +00:00
Report errors for non-UTF-8 entries in Zip and 7z
This commit is contained in:
parent
d07c65508a
commit
a7a65d2510
@ -10,6 +10,7 @@ use fs_err as fs;
|
|||||||
use same_file::Handle;
|
use same_file::Handle;
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
|
error::FinalError,
|
||||||
info,
|
info,
|
||||||
utils::{self, cd_into_same_dir_as, Bytes, EscapedPathDisplay, FileVisibilityPolicy},
|
utils::{self, cd_into_same_dir_as, Bytes, EscapedPathDisplay, FileVisibilityPolicy},
|
||||||
warning,
|
warning,
|
||||||
@ -70,8 +71,12 @@ where
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
let entry_name = path.to_str().unwrap().to_owned();
|
let entry_name = path.to_str().ok_or_else(|| {
|
||||||
let entry = sevenz_rust::SevenZArchiveEntry::from_path(path, entry_name);
|
FinalError::with_title("7z requires that all entry names are valid UTF-8")
|
||||||
|
.detail(format!("File at '{path:?}' has a non-UTF-8 name"))
|
||||||
|
})?;
|
||||||
|
|
||||||
|
let entry = sevenz_rust::SevenZArchiveEntry::from_path(path, entry_name.to_owned());
|
||||||
let entry_data = if metadata.is_dir() {
|
let entry_data = if metadata.is_dir() {
|
||||||
None
|
None
|
||||||
} else {
|
} else {
|
||||||
|
@ -209,8 +209,13 @@ where
|
|||||||
#[cfg(unix)]
|
#[cfg(unix)]
|
||||||
let options = options.unix_permissions(metadata.permissions().mode());
|
let options = options.unix_permissions(metadata.permissions().mode());
|
||||||
|
|
||||||
|
let entry_name = path.to_str().ok_or_else(|| {
|
||||||
|
FinalError::with_title("Zip requires that all directories names are valid UTF-8")
|
||||||
|
.detail(format!("File at '{path:?}' has a non-UTF-8 name"))
|
||||||
|
})?;
|
||||||
|
|
||||||
if metadata.is_dir() {
|
if metadata.is_dir() {
|
||||||
writer.add_directory(path.to_str().unwrap().to_owned(), options)?;
|
writer.add_directory(entry_name, options)?;
|
||||||
} else {
|
} else {
|
||||||
#[cfg(not(unix))]
|
#[cfg(not(unix))]
|
||||||
let options = if is_executable::is_executable(path) {
|
let options = if is_executable::is_executable(path) {
|
||||||
@ -220,10 +225,11 @@ where
|
|||||||
};
|
};
|
||||||
|
|
||||||
let mut file = fs::File::open(path)?;
|
let mut file = fs::File::open(path)?;
|
||||||
writer.start_file(
|
|
||||||
path.to_str().unwrap(),
|
// Updated last modified time
|
||||||
options.last_modified_time(get_last_modified_time(&file)),
|
let last_modified_time = options.last_modified_time(get_last_modified_time(&file));
|
||||||
)?;
|
|
||||||
|
writer.start_file(entry_name, last_modified_time)?;
|
||||||
io::copy(&mut file, &mut writer)?;
|
io::copy(&mut file, &mut writer)?;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user