diff options
author | Jim Meyering <jim@meyering.net> | 2001-01-09 16:07:40 +0000 |
---|---|---|
committer | Jim Meyering <jim@meyering.net> | 2001-01-09 16:07:40 +0000 |
commit | e92e87181b06d4de6a978a8f8fdea70639c05348 (patch) | |
tree | 69a40ca329c3a1244b00c0bb66bcdbd00b70d6ce | |
parent | 902dacb46a959f2e81327bcd42683a8752a1b9b4 (diff) | |
download | coreutils-e92e87181b06d4de6a978a8f8fdea70639c05348.tar.xz |
(top_level_src_path, top_level_dst_path): New globals.
(copy_internal): Use them.
(copy): Set them.
-rw-r--r-- | src/copy.c | 24 |
1 files changed, 21 insertions, 3 deletions
diff --git a/src/copy.c b/src/copy.c index f1d527cb1..5fd5699f5 100644 --- a/src/copy.c +++ b/src/copy.c @@ -1,5 +1,5 @@ /* copy.c -- core functions for copying files and directories - Copyright (C) 89, 90, 91, 1995-2000 Free Software Foundation. + Copyright (C) 89, 90, 91, 1995-2001 Free Software Foundation. This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -67,6 +67,11 @@ static int copy_internal PARAMS ((const char *src_path, const char *dst_path, int *copy_into_self, int *rename_succeeded)); +/* Pointers to the file names: they're used in the diagnostic that is issued + when we detect the user is trying to copy a directory into itself. */ +static char const *top_level_src_path; +static char const *top_level_dst_path; + /* The invocation name of this program. */ extern char *program_name; @@ -756,8 +761,15 @@ copy_internal (const char *src_path, const char *dst_path, directories). */ if (S_ISDIR (src_type)) { - error (0, 0, _("won't create hard link %s to directory %s"), - quote_n (0, dst_path), quote_n (1, earlier_file)); + /* If src_path and earlier_file refer to the same directory entry, + then warn about copying a directory into itself. */ + if (same_name (src_path, earlier_file)) + error (0, 0, _("can't copy a directory %s into itself %s"), + quote_n (0, top_level_src_path), + quote_n (1, top_level_dst_path)); + else + error (0, 0, _("won't create hard link %s to directory %s"), + quote_n (0, dst_path), quote_n (1, earlier_file)); goto un_backup; } @@ -1167,6 +1179,12 @@ copy (const char *src_path, const char *dst_path, int move_mode = options->move_mode; assert (valid_options (options)); + + /* Record the file names: they're used in case of error, + when copying a directory into itself. */ + top_level_src_path = src_path; + top_level_dst_path = dst_path; + return copy_internal (src_path, dst_path, nonexistent_dst, 0, NULL, options, move_mode, copy_into_self, rename_succeeded); } |