summaryrefslogtreecommitdiff
path: root/src/copy.c
diff options
context:
space:
mode:
authorJim Meyering <jim@meyering.net>1998-06-27 22:09:45 +0000
committerJim Meyering <jim@meyering.net>1998-06-27 22:09:45 +0000
commit6ae99a42905ef98d07ebf97c80805eaa3fb039ea (patch)
tree53332a9956ae6e36a1c8cac5ae7bc5b2cdd8cf66 /src/copy.c
parentc76172fbb06a10594f234ca0fe1440d5c6a75d86 (diff)
downloadcoreutils-6ae99a42905ef98d07ebf97c80805eaa3fb039ea.tar.xz
(copy_internal): Fix it so hard-link test is no longer hidden inside
big if-(backup_type == none) block.
Diffstat (limited to 'src/copy.c')
-rw-r--r--src/copy.c53
1 files changed, 29 insertions, 24 deletions
diff --git a/src/copy.c b/src/copy.c
index 356da5e04..6ffecbb2c 100644
--- a/src/copy.c
+++ b/src/copy.c
@@ -430,39 +430,44 @@ copy_internal (const char *src_path, const char *dst_path,
}
else
{
- /* The destination file exists already. */
+ int same;
- if (x->backup_type == none)
- {
- int same;
+ /* The destination file exists already. */
- same = (src_sb.st_ino == dst_sb.st_ino
- && src_sb.st_dev == dst_sb.st_dev);
+ same = (src_sb.st_ino == dst_sb.st_ino
+ && src_sb.st_dev == dst_sb.st_dev);
#ifdef S_ISLNK
- /* If we're preserving symlinks (--no-dereference) and either
- file is a symlink, use stat (not xstat) to see if they refer
- to the same file. */
- if (!same && !x->dereference
- && (S_ISLNK (dst_sb.st_mode) || S_ISLNK (src_sb.st_mode)))
+ /* If we're preserving symlinks (--no-dereference) and either
+ file is a symlink, use stat (not xstat) to see if they refer
+ to the same file. */
+ if (!same
+ /* If we're making a backup, we'll detect the problem case in
+ copy_reg because SRC_PATH will no longer exist. Allowing
+ the test to be deferred lets cp do some useful things. */
+ && x->backup_type == none
+ && !x->dereference
+ && (S_ISLNK (dst_sb.st_mode) || S_ISLNK (src_sb.st_mode)))
+ {
+ struct stat dst2_sb;
+ struct stat src2_sb;
+ if (stat (dst_path, &dst2_sb) == 0
+ && stat (src_path, &src2_sb) == 0
+ && src2_sb.st_ino == dst2_sb.st_ino
+ && src2_sb.st_dev == dst2_sb.st_dev)
{
- struct stat dst2_sb;
- struct stat src2_sb;
- if (stat (dst_path, &dst2_sb) == 0
- && stat (src_path, &src2_sb) == 0
- && src2_sb.st_ino == dst2_sb.st_ino
- && src2_sb.st_dev == dst2_sb.st_dev)
- {
- same = 1;
- }
+ same = 1;
}
+ }
#endif
- if (same)
- {
- if (x->hard_link)
- return 0;
+ if (same)
+ {
+ if (x->hard_link)
+ return 0;
+ if (x->backup_type == none)
+ {
error (0, 0, _("`%s' and `%s' are the same file"),
src_path, dst_path);
return 1;