From 4b25fdbdabce1b758e55880d0aa3947614d94c3d Mon Sep 17 00:00:00 2001 From: Paul Eggert Date: Mon, 24 Mar 2014 23:14:43 -0700 Subject: cp: improve quality of overwrite prompt * src/copy.c (overwrite_prompt): New arg X. All callers changed. Use X to improve the quality of the prompt (Bug#17087). * tests/mv/i-2.sh, tests/mv/i-3.sh: Change test to match new prompt. --- src/copy.c | 12 ++++++++---- tests/mv/i-2.sh | 2 +- tests/mv/i-3.sh | 2 +- 3 files changed, 10 insertions(+), 6 deletions(-) diff --git a/src/copy.c b/src/copy.c index 49983869f..bd4df05fb 100644 --- a/src/copy.c +++ b/src/copy.c @@ -1566,7 +1566,8 @@ writable_destination (char const *file, mode_t mode) } static void -overwrite_prompt (char const *dst_name, struct stat const *dst_sb) +overwrite_prompt (struct cp_options const *x, char const *dst_name, + struct stat const *dst_sb) { if (! writable_destination (dst_name, dst_sb->st_mode)) { @@ -1574,7 +1575,10 @@ overwrite_prompt (char const *dst_name, struct stat const *dst_sb) strmode (dst_sb->st_mode, perms); perms[10] = '\0'; fprintf (stderr, - _("%s: try to overwrite %s, overriding mode %04lo (%s)? "), + _((x->unlink_dest_before_opening + || x->unlink_dest_after_failed_open) + ? "%s: replace %s, overriding mode %04lo (%s)? " + : "%s: unwritable %s (mode %04lo, %s); try anyway? "), program_name, quote (dst_name), (unsigned long int) (dst_sb->st_mode & CHMOD_MODE_BITS), &perms[1]); @@ -1638,7 +1642,7 @@ abandon_move (const struct cp_options *x, || (x->interactive == I_UNSPECIFIED && x->stdin_tty && ! writable_destination (dst_name, dst_sb->st_mode))) - && (overwrite_prompt (dst_name, dst_sb), 1) + && (overwrite_prompt (x, dst_name, dst_sb), 1) && ! yesno ())); } @@ -1913,7 +1917,7 @@ copy_internal (char const *src_name, char const *dst_name, if (! S_ISDIR (src_mode) && (x->interactive == I_ALWAYS_NO || (x->interactive == I_ASK_USER - && (overwrite_prompt (dst_name, &dst_sb), 1) + && (overwrite_prompt (x, dst_name, &dst_sb), 1) && ! yesno ()))) return true; } diff --git a/tests/mv/i-2.sh b/tests/mv/i-2.sh index 62d63af77..4202b5c5b 100755 --- a/tests/mv/i-2.sh +++ b/tests/mv/i-2.sh @@ -36,7 +36,7 @@ cp -if e f < y > out 2>&1 || fail=1 # Make sure out contains the prompt. case "$(cat out)" in - "cp: try to overwrite 'f', overriding mode 0000 (---------)?"*) ;; + "cp: replace 'f', overriding mode 0000 (---------)?"*) ;; *) fail=1 ;; esac diff --git a/tests/mv/i-3.sh b/tests/mv/i-3.sh index e03dc9999..690af7385 100755 --- a/tests/mv/i-3.sh +++ b/tests/mv/i-3.sh @@ -46,7 +46,7 @@ check_overwrite_prompt() { local delay="$1" case "$(cat out)" in - "mv: try to overwrite 'g', overriding mode 0000"*) ;; + "mv: replace 'g', overriding mode 0000"*) ;; *) sleep $delay; return 1;; esac } -- cgit v1.2.3-70-g09d2