summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPaul Eggert <eggert@cs.ucla.edu>2014-03-24 23:17:02 -0700
committerPaul Eggert <eggert@cs.ucla.edu>2014-03-24 23:18:41 -0700
commit7f669b40c91bda7d6d4827d20cc637dcda08c68a (patch)
treec46a108f7782c31652227cf6e1b32e100bc12047
parent4b25fdbdabce1b758e55880d0aa3947614d94c3d (diff)
downloadcoreutils-7f669b40c91bda7d6d4827d20cc637dcda08c68a.tar.xz
cp: simplify overwrite logic
* src/copy.c (overwrite_ok): Rename from overwrite_prompt. Invoke yesno instead of having the caller do it; that's cleaner. Return bool, not void. All callers changed.
-rw-r--r--src/copy.c14
1 files changed, 7 insertions, 7 deletions
diff --git a/src/copy.c b/src/copy.c
index bd4df05fb..71813dc40 100644
--- a/src/copy.c
+++ b/src/copy.c
@@ -1565,9 +1565,9 @@ writable_destination (char const *file, mode_t mode)
|| euidaccess (file, W_OK) == 0);
}
-static void
-overwrite_prompt (struct cp_options const *x, char const *dst_name,
- struct stat const *dst_sb)
+static bool
+overwrite_ok (struct cp_options const *x, char const *dst_name,
+ struct stat const *dst_sb)
{
if (! writable_destination (dst_name, dst_sb->st_mode))
{
@@ -1588,6 +1588,8 @@ overwrite_prompt (struct cp_options const *x, char const *dst_name,
fprintf (stderr, _("%s: overwrite %s? "),
program_name, quote (dst_name));
}
+
+ return yesno ();
}
/* Initialize the hash table implementing a set of F_triple entries
@@ -1642,8 +1644,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 (x, dst_name, dst_sb), 1)
- && ! yesno ()));
+ && ! overwrite_ok (x, dst_name, dst_sb)));
}
/* Print --verbose output on standard output, e.g. 'new' -> 'old'.
@@ -1917,8 +1918,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 (x, dst_name, &dst_sb), 1)
- && ! yesno ())))
+ && ! overwrite_ok (x, dst_name, &dst_sb))))
return true;
}