1
0
mirror of git://git.sv.gnu.org/coreutils.git synced 2026-08-04 07:43:58 +02:00

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.
This commit is contained in:
Paul Eggert
2014-03-24 23:14:43 -07:00
parent 5f9a5b3f03
commit 4b25fdbdab
3 changed files with 10 additions and 6 deletions
+8 -4
View File
@@ -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;
}
+1 -1
View File
@@ -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
+1 -1
View File
@@ -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
}