From 1b3bf65c5173c1e7a34e3ea323a67254fb95e3f8 Mon Sep 17 00:00:00 2001 From: Paul Eggert Date: Tue, 31 May 2005 06:15:48 +0000 Subject: [PATCH] (re_protect): Remove unnecessary call to geteuid. Use chown_failure_ok rather than our own code. (cp_options_init): Use chown_privileges rather than getuid. --- src/cp.c | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/src/cp.c b/src/cp.c index 04d73a02b9..e577242693 100644 --- a/src/cp.c +++ b/src/cp.c @@ -281,7 +281,6 @@ re_protect (const char *const_dst_path, size_t src_offset, struct dir_attr *p; char *dst_path; /* A copy of CONST_DST_PATH we can change. */ char *src_path; /* The source name in `dst_path'. */ - uid_t myeuid = geteuid (); ASSIGN_STRDUPA (dst_path, const_dst_path); src_path = dst_path + src_offset; @@ -322,11 +321,8 @@ re_protect (const char *const_dst_path, size_t src_offset, if (x->preserve_ownership) { - /* If non-root uses -p, it's ok if we can't preserve ownership. - But root probably wants to know, e.g. if NFS disallows it, - or if the target system doesn't support file ownership. */ - if (chown (dst_path, src_sb.st_uid, src_sb.st_gid) - && ((errno != EPERM && errno != EINVAL) || myeuid == 0)) + if (chown (dst_path, src_sb.st_uid, src_sb.st_gid) != 0 + && ! chown_failure_ok (x)) { error (0, errno, _("failed to preserve ownership for %s"), quote (dst_path)); @@ -683,7 +679,7 @@ cp_option_init (struct cp_options *x) x->unlink_dest_after_failed_open = false; x->hard_link = false; x->interactive = I_UNSPECIFIED; - x->myeuid = geteuid (); + x->chown_privileges = chown_privileges (); x->move_mode = false; x->one_file_system = false; -- 2.47.3