diff options
author | Paul Eggert <eggert@cs.ucla.edu> | 2005-05-31 06:15:48 +0000 |
---|---|---|
committer | Paul Eggert <eggert@cs.ucla.edu> | 2005-05-31 06:15:48 +0000 |
commit | 1b3bf65c5173c1e7a34e3ea323a67254fb95e3f8 (patch) | |
tree | cf7d2979099e81faffb9bb13ba9236c4a11a0069 /src | |
parent | d8ce6bf1434748af09cdf17620d7585eae23fd6f (diff) | |
download | coreutils-1b3bf65c5173c1e7a34e3ea323a67254fb95e3f8.tar.xz |
(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.
Diffstat (limited to 'src')
-rw-r--r-- | src/cp.c | 10 |
1 files changed, 3 insertions, 7 deletions
@@ -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; |