Skip to content

Commit

Permalink
minor changes
Browse files Browse the repository at this point in the history
  • Loading branch information
matrixhead committed Aug 23, 2024
1 parent 62944a2 commit ca0c4e3
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 7 deletions.
9 changes: 6 additions & 3 deletions src/uu/cp/src/cp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1406,8 +1406,11 @@ impl OverwriteMode {
}
Err(Error::Skipped(false))
}
// allow `unused_variables` because windows doesn't use `clobber_mode`
#[allow(unused_variables)]
Self::Interactive(clobber_mode) => {
let prompt = if cfg!(unix) {
#[cfg(unix)]
let prompt = {
let path_md = path.metadata()?;
if path_md.permissions().readonly() {
match clobber_mode {
Expand All @@ -1427,9 +1430,9 @@ impl OverwriteMode {
} else {
format!("overwrite {}?", path.quote())
}
} else {
format!("overwrite {}?", path.quote())
};
#[cfg(not(unix))]
let prompt = { format!("overwrite {}?", path.quote()) };
if prompt_yes!("{prompt}") {
Ok(())
} else {
Expand Down
23 changes: 19 additions & 4 deletions tests/by-util/test_cp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5748,6 +5748,11 @@ fn test_cp_interactive_with_read_only_dest() {
.permissions();
permissions.set_readonly(true);
set_permissions(at.plus(dest), permissions).expect("couldn't set permissions");
let perms_prompt = if cfg!(target_os = "android") {
" (mode 0400, r--------); try anyway?"
} else {
"(mode 0444, r--r--r--); try anyway?"
};
scene
.ucmd()
.args(&[
Expand All @@ -5758,7 +5763,7 @@ fn test_cp_interactive_with_read_only_dest() {
.pipe_in("y\n")
.fails()
.stderr_contains("unwritable")
.stderr_contains("(mode 0444, r--r--r--); try anyway?")
.stderr_contains(perms_prompt)
.stderr_contains("Permission denied");
assert_eq!(at.read(&at.plus(dest).to_string_lossy()), "dest contents");
}
Expand All @@ -5781,6 +5786,11 @@ fn test_cp_interactive_with_read_only_dest_and_force() {
.permissions();
permissions.set_readonly(true);
set_permissions(at.plus(dest), permissions).expect("couldn't set permissions");
let perms_prompt = if cfg!(target_os = "android") {
" overriding mode 0400 (r--------)?"
} else {
" overriding mode 0444 (r--r--r--)?"
};
scene
.ucmd()
.args(&[
Expand All @@ -5791,10 +5801,11 @@ fn test_cp_interactive_with_read_only_dest_and_force() {
.pipe_in("y\n")
.succeeds()
.stderr_contains("replace")
.stderr_contains(" overriding mode 0444 (r--r--r--)?");
.stderr_contains(perms_prompt);
assert_eq!(at.read(&at.plus(dest).to_string_lossy()), "src contents");
}

#[cfg(unix)]
#[test]
fn test_cp_interactive_with_read_only_dest_and_rem() {
let src = "src";
Expand All @@ -5812,7 +5823,11 @@ fn test_cp_interactive_with_read_only_dest_and_rem() {
.permissions();
permissions.set_readonly(true);
set_permissions(at.plus(dest), permissions).expect("couldn't set permissions");

let perms_prompt = if cfg!(target_os = "android") {
" overriding mode 0400 (r--------)?"
} else {
" overriding mode 0444 (r--r--r--)?"
};
scene
.ucmd()
.args(&[
Expand All @@ -5824,7 +5839,7 @@ fn test_cp_interactive_with_read_only_dest_and_rem() {
.pipe_in("y\n")
.succeeds()
.stderr_contains("replace")
.stderr_contains(" overriding mode 0444 (r--r--r--)?");
.stderr_contains(perms_prompt);
assert_eq!(at.read(&at.plus(dest).to_string_lossy()), "src contents");
}

Expand Down

0 comments on commit ca0c4e3

Please sign in to comment.