cp: Also preserve atime/mtime for symlinks
Laslo: Fixed style a bit and added comment
This commit is contained in:
parent
e03a57df92
commit
2481042651
16
libutil/cp.c
16
libutil/cp.c
|
@ -152,14 +152,16 @@ cp(const char *s1, const char *s2, int depth)
|
||||||
}
|
}
|
||||||
|
|
||||||
if (cp_aflag || cp_pflag) {
|
if (cp_aflag || cp_pflag) {
|
||||||
/* timestamp and owner */
|
/* atime and mtime */
|
||||||
|
times[0] = st.st_atim;
|
||||||
|
times[1] = st.st_mtim;
|
||||||
|
if (utimensat(AT_FDCWD, s2, times, AT_SYMLINK_NOFOLLOW) < 0) {
|
||||||
|
weprintf("utimensat %s:", s2);
|
||||||
|
cp_status = 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* owner */
|
||||||
if (!S_ISLNK(st.st_mode)) {
|
if (!S_ISLNK(st.st_mode)) {
|
||||||
times[0] = st.st_atim;
|
|
||||||
times[1] = st.st_mtim;
|
|
||||||
if (utimensat(AT_FDCWD, s2, times, 0) < 0) {
|
|
||||||
weprintf("utimensat %s:", s2);
|
|
||||||
cp_status = 1;
|
|
||||||
}
|
|
||||||
if (chown(s2, st.st_uid, st.st_gid) < 0) {
|
if (chown(s2, st.st_uid, st.st_gid) < 0) {
|
||||||
weprintf("chown %s:", s2);
|
weprintf("chown %s:", s2);
|
||||||
cp_status = 1;
|
cp_status = 1;
|
||||||
|
|
Loading…
Reference in New Issue
Block a user