mirror of
https://github.com/RGBCube/uutils-coreutils
synced 2025-07-28 11:37:44 +00:00
install: remove / from end of path if it exists so as not to mess with .exists() (#5730)
* remove / from end of path if it exists so as not to mess with .exists() * install: fix / removal from path * Fix clippy warnings * Add test for install target ends with /
This commit is contained in:
parent
413638c789
commit
bf26eda786
2 changed files with 31 additions and 0 deletions
|
@ -569,6 +569,13 @@ fn standard(mut paths: Vec<String>, b: &Behavior) -> UResult<()> {
|
|||
};
|
||||
|
||||
if let Some(to_create) = to_create {
|
||||
// if the path ends in /, remove it
|
||||
let to_create = if to_create.to_string_lossy().ends_with('/') {
|
||||
Path::new(to_create.to_str().unwrap().trim_end_matches('/'))
|
||||
} else {
|
||||
to_create
|
||||
};
|
||||
|
||||
if !to_create.exists() {
|
||||
if b.verbose {
|
||||
let mut result = PathBuf::new();
|
||||
|
|
|
@ -1589,3 +1589,27 @@ fn test_t_exist_dir() {
|
|||
.fails()
|
||||
.stderr_contains("failed to access 'sub4/file_exists': Not a directory");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_target_file_ends_with_slash() {
|
||||
let scene = TestScenario::new(util_name!());
|
||||
let at = &scene.fixtures;
|
||||
|
||||
let source = "source_file";
|
||||
let target_dir = "dir";
|
||||
let target_file = "dir/target_file";
|
||||
let target_file_slash = format!("{}/", target_file);
|
||||
|
||||
at.touch(source);
|
||||
at.mkdir(target_dir);
|
||||
at.touch(target_file);
|
||||
|
||||
scene
|
||||
.ucmd()
|
||||
.arg("-t")
|
||||
.arg(target_file_slash)
|
||||
.arg("-D")
|
||||
.arg(source)
|
||||
.fails()
|
||||
.stderr_contains("failed to access 'dir/target_file/': Not a directory");
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue