From b5545e03db4846ec4aee9867c8251dfa9455f158 Mon Sep 17 00:00:00 2001 From: Jim Meyering Date: Mon, 4 Sep 2000 14:49:30 +0000 Subject: (same_file_ok): Hoist a test. --- src/copy.c | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) diff --git a/src/copy.c b/src/copy.c index 8b238680a..cd9b7ec1a 100644 --- a/src/copy.c +++ b/src/copy.c @@ -462,7 +462,8 @@ same_file_ok (const char *src_path, const struct stat *src_sb, } #if 0 - /* FIXME: remove or use */ + /* FIXME: use or remove */ + /* 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. @@ -473,7 +474,6 @@ same_file_ok (const char *src_path, const struct stat *src_sb, || S_ISLNK (dst_sb_link->st_mode)) return 1; - /* FIXME: explain */ if (x->dereference != DEREF_NEVER) return 1; #endif @@ -503,6 +503,13 @@ same_file_ok (const char *src_path, const struct stat *src_sb, } } + /* It's ok to remove a destination symlink. But that works only when we + unlink before opening the destination and when they're on the same + partition. */ + if (x->unlink_dest_before_opening + && S_ISLNK (dst_sb_link->st_mode)) + return src_sb_link->st_dev == src_sb_link->st_dev; + if (x->xstat == lstat) { static struct stat tmp_dst_sb; @@ -527,14 +534,6 @@ same_file_ok (const char *src_path, const struct stat *src_sb, dst_sb_no_link = dst_sb; } - /* FIXME: hoist this to precede if/else? */ - /* It's ok to remove a destination symlink. But that works only when we - unlink before opening the destination and when they're on the same - partition. */ - if (x->unlink_dest_before_opening - && S_ISLNK (dst_sb_link->st_mode)) - return src_sb_link->st_dev == src_sb_link->st_dev; - return 0; } -- cgit v1.2.3-70-g09d2