From: Jim Meyering Date: Mon, 4 Sep 2000 14:49:30 +0000 (+0000) Subject: (same_file_ok): Hoist a test. X-Git-Tag: FILEUTILS-4_0z~48 X-Git-Url: http://git.ipfire.org/gitweb/index.cgi?a=commitdiff_plain;h=b5545e03db4846ec4aee9867c8251dfa9455f158;p=thirdparty%2Fcoreutils.git (same_file_ok): Hoist a test. --- diff --git a/src/copy.c b/src/copy.c index 8b238680a6..cd9b7ec1a6 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; }