summaryrefslogtreecommitdiff
path: root/src/copy.c
diff options
context:
space:
mode:
authorJim Meyering <jim@meyering.net>2000-09-09 07:29:38 +0000
committerJim Meyering <jim@meyering.net>2000-09-09 07:29:38 +0000
commit84d9e6f35b7912277d7c56df2dcc443d6dee07fb (patch)
tree660e8c94597d52fce440f95757ce52c761e2a498 /src/copy.c
parent5e333bb8b83cb8aaa8a7583b164055f5fa55da9c (diff)
downloadcoreutils-84d9e6f35b7912277d7c56df2dcc443d6dee07fb.tar.xz
(SAME_OWNER, SAME_GROUP, SAME_OWNER_AND_GROUP): Define.
(copy_internal): Avoid calling chown if we know it's not necessary.
Diffstat (limited to 'src/copy.c')
-rw-r--r--src/copy.c8
1 files changed, 7 insertions, 1 deletions
diff --git a/src/copy.c b/src/copy.c
index 742ff4a24..2be91a223 100644
--- a/src/copy.c
+++ b/src/copy.c
@@ -44,6 +44,10 @@
or if the target system doesn't support file ownership. */ \
&& ((errno != EPERM && errno != EINVAL) || x->myeuid == 0))
+#define SAME_OWNER(A, B) ((A).st_uid == (B).st_uid)
+#define SAME_GROUP(A, B) ((A).st_gid == (B).st_gid)
+#define SAME_OWNER_AND_GROUP(A, B) (SAME_OWNER (A, B) && SAME_GROUP (A, B))
+
struct dir_list
{
struct dir_list *parent;
@@ -1078,7 +1082,9 @@ copy_internal (const char *src_path, const char *dst_path,
}
}
- if (x->preserve_owner_and_group)
+ /* Avoid calling chown if we know it's not necessary. */
+ if (x->preserve_owner_and_group
+ && (new_dst || !SAME_OWNER_AND_GROUP (src_sb, dst_sb)))
{
if (DO_CHOWN (chown, dst_path, src_sb.st_uid, src_sb.st_gid))
{