mirror of
https://github.com/uutils/coreutils.git
synced 2026-06-10 15:48:22 -07:00
install: options support non-ut8 too
This commit is contained in:
@@ -569,13 +569,17 @@ fn standard(mut paths: Vec<OsString>, b: &Behavior) -> UResult<()> {
|
|||||||
if let Some(to_create) = to_create {
|
if let Some(to_create) = to_create {
|
||||||
// if the path ends in /, remove it
|
// if the path ends in /, remove it
|
||||||
let to_create_owned;
|
let to_create_owned;
|
||||||
let to_create = if to_create.to_string_lossy().ends_with('/') {
|
let to_create = match uucore::os_str_as_bytes(to_create.as_os_str()) {
|
||||||
let path_str = to_create.to_string_lossy();
|
Ok(path_bytes) if path_bytes.ends_with(b"/") => {
|
||||||
let trimmed = path_str.trim_end_matches('/');
|
let mut trimmed_bytes = path_bytes;
|
||||||
to_create_owned = PathBuf::from(trimmed);
|
while trimmed_bytes.ends_with(b"/") {
|
||||||
to_create_owned.as_path()
|
trimmed_bytes = &trimmed_bytes[..trimmed_bytes.len() - 1];
|
||||||
} else {
|
}
|
||||||
to_create
|
let trimmed_os_str = std::ffi::OsStr::from_bytes(trimmed_bytes);
|
||||||
|
to_create_owned = PathBuf::from(trimmed_os_str);
|
||||||
|
to_create_owned.as_path()
|
||||||
|
}
|
||||||
|
_ => to_create,
|
||||||
};
|
};
|
||||||
|
|
||||||
if !to_create.exists() {
|
if !to_create.exists() {
|
||||||
|
|||||||
@@ -2380,4 +2380,14 @@ fn test_install_non_utf8_paths() {
|
|||||||
at.mkdir(dest_dir);
|
at.mkdir(dest_dir);
|
||||||
|
|
||||||
ucmd.arg(&source_filename).arg(dest_dir).succeeds();
|
ucmd.arg(&source_filename).arg(dest_dir).succeeds();
|
||||||
|
|
||||||
|
// Test with trailing slash and directory creation (-D flag)
|
||||||
|
let (at, mut ucmd) = at_and_ucmd!();
|
||||||
|
let source_file = "source.txt";
|
||||||
|
let mut target_path = std::ffi::OsString::from_vec(vec![0xFF, 0xFE, b'd', b'i', b'r']);
|
||||||
|
target_path.push("/target.txt");
|
||||||
|
|
||||||
|
at.touch(source_file);
|
||||||
|
|
||||||
|
ucmd.arg("-D").arg(source_file).arg(&target_path).succeeds();
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user