Simplify preserving permissions and ownership
This commit is contained in:
parent
2e96450547
commit
1dac58806d
14
src/cp.c
14
src/cp.c
|
@ -262,26 +262,20 @@ static int _cp_single_regular(char const * src, char const * dst, mode_t mode)
|
|||
static int _cp_single_p(char const * dst, struct stat * st)
|
||||
{
|
||||
struct timeval tv[2];
|
||||
int (*_chown)(const char * path, uid_t uid, gid_t git);
|
||||
int (*_chmod)(const char * path, mode_t mode);
|
||||
int (*_utimes)(const char * path, const struct timeval times[2]);
|
||||
|
||||
_chown = S_ISLNK(st->st_mode) ? lchown : chown;
|
||||
_chmod = S_ISLNK(st->st_mode) ? lchmod : chmod;
|
||||
_utimes = S_ISLNK(st->st_mode) ? lutimes : utimes;
|
||||
if(_chown(dst, st->st_uid, st->st_gid) != 0)
|
||||
if(lchown(dst, st->st_uid, st->st_gid) != 0)
|
||||
{
|
||||
_cp_error(dst, 0);
|
||||
if(_chmod(dst, st->st_mode & ~(S_ISUID | S_ISGID)) != 0)
|
||||
if(lchmod(dst, st->st_mode & ~(S_ISUID | S_ISGID)) != 0)
|
||||
_cp_error(dst, 0);
|
||||
}
|
||||
else if(_chmod(dst, st->st_mode) != 0)
|
||||
else if(lchmod(dst, st->st_mode) != 0)
|
||||
_cp_error(dst, 0);
|
||||
tv[0].tv_sec = st->st_atime;
|
||||
tv[0].tv_usec = 0;
|
||||
tv[1].tv_sec = st->st_mtime;
|
||||
tv[1].tv_usec = 0;
|
||||
if(_utimes(dst, tv) != 0)
|
||||
if(lutimes(dst, tv) != 0)
|
||||
_cp_error(dst, 0);
|
||||
return 0;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user