diff options
author | Jim Meyering <jim@meyering.net> | 2001-08-13 08:31:03 +0000 |
---|---|---|
committer | Jim Meyering <jim@meyering.net> | 2001-08-13 08:31:03 +0000 |
commit | 66c2f3a08a7b7ef336db50b04b17c4f3715cd753 (patch) | |
tree | df8679857dde1f950ee0d196112046f197a33f1b /src | |
parent | c1c73683720e45d541f3cfe0cf056d04c8715bb7 (diff) | |
download | coreutils-66c2f3a08a7b7ef336db50b04b17c4f3715cd753.tar.xz |
(overwrite_prompt): New function.
(copy_internal): Separate the mv-specific and non-move_mode code
that determines whether to prompt the user.
[move_mode]: Don't make mv fail (i.e. don't return 1) just because
the user declined to remove one or more of the files.
Diffstat (limited to 'src')
-rw-r--r-- | src/copy.c | 54 |
1 files changed, 44 insertions, 10 deletions
diff --git a/src/copy.c b/src/copy.c index 1096fba23..f644b7610 100644 --- a/src/copy.c +++ b/src/copy.c @@ -543,6 +543,23 @@ same_file_ok (const char *src_path, const struct stat *src_sb, return 0; } +static void +overwrite_prompt (char const *dst_path, struct stat const *dst_sb) +{ + if (euidaccess (dst_path, W_OK) != 0) + { + fprintf (stderr, + _("%s: overwrite %s, overriding mode %04lo? "), + program_name, quote (dst_path), + (unsigned long) (dst_sb->st_mode & CHMOD_MODE_BITS)); + } + else + { + fprintf (stderr, _("%s: overwrite %s? "), + program_name, quote (dst_path)); + } +} + /* Copy the file SRC_PATH to the file DST_PATH. The files may be of any type. NEW_DST should be nonzero if the file DST_PATH cannot exist because its parent directory was just created; NEW_DST should @@ -654,6 +671,9 @@ copy_internal (const char *src_path, const char *dst_path, if (x->update && MTIME_CMP (src_sb, dst_sb) <= 0) { + /* We're using --update and the source file is older + than the destination file, so there is no need to + copy or move. */ /* Pretend the rename succeeded, so the caller (mv) doesn't end up removing the source file. */ if (rename_succeeded) @@ -662,22 +682,36 @@ copy_internal (const char *src_path, const char *dst_path, } } - if (!S_ISDIR (src_type) && x->interactive) + if (!S_ISDIR (src_type)) { - if (euidaccess (dst_path, W_OK) != 0) + /* cp and mv treat -i and -f differently. */ + if (x->move_mode) { - fprintf (stderr, - _("%s: overwrite %s, overriding mode %04lo? "), - program_name, quote (dst_path), - (unsigned long) (dst_sb.st_mode & CHMOD_MODE_BITS)); + if (x->interactive != I_OFF + && (x->interactive == I_ON + || (x->stdin_tty + /* euidaccess is not meaningful for symlinks */ + && ! S_ISLNK (dst_sb.st_mode) + && euidaccess (dst_path, W_OK) != 0))) + { + overwrite_prompt (dst_path, &dst_sb); + if (!yesno ()) + /* Pretend the rename succeeded, so the caller (mv) + doesn't end up removing the source file. */ + if (rename_succeeded) + *rename_succeeded = 1; + return 0; + } } else { - fprintf (stderr, _("%s: overwrite %s? "), - program_name, quote (dst_path)); + if (x->interactive == I_ON) + { + overwrite_prompt (dst_path, &dst_sb); + if (!yesno ()) + return 0; + } } - if (!yesno ()) - return (move_mode ? 1 : 0); } if (move_mode) |