mirror of
https://github.com/uutils/coreutils.git
synced 2025-12-23 08:47:37 +00:00
install: options support non-ut8 too
This commit is contained in:
parent
66a1fc8bbf
commit
83e5be8a52
2 changed files with 21 additions and 7 deletions
|
|
@ -569,13 +569,17 @@ fn standard(mut paths: Vec<OsString>, b: &Behavior) -> UResult<()> {
|
|||
if let Some(to_create) = to_create {
|
||||
// if the path ends in /, remove it
|
||||
let to_create_owned;
|
||||
let to_create = if to_create.to_string_lossy().ends_with('/') {
|
||||
let path_str = to_create.to_string_lossy();
|
||||
let trimmed = path_str.trim_end_matches('/');
|
||||
to_create_owned = PathBuf::from(trimmed);
|
||||
to_create_owned.as_path()
|
||||
} else {
|
||||
to_create
|
||||
let to_create = match uucore::os_str_as_bytes(to_create.as_os_str()) {
|
||||
Ok(path_bytes) if path_bytes.ends_with(b"/") => {
|
||||
let mut trimmed_bytes = path_bytes;
|
||||
while trimmed_bytes.ends_with(b"/") {
|
||||
trimmed_bytes = &trimmed_bytes[..trimmed_bytes.len() - 1];
|
||||
}
|
||||
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() {
|
||||
|
|
|
|||
|
|
@ -2380,4 +2380,14 @@ fn test_install_non_utf8_paths() {
|
|||
at.mkdir(dest_dir);
|
||||
|
||||
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();
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue