/* This returns 0 for success, 1 for a symlink if symlink time-setting * is not possible, or -1 for any other error. */ int set_modtime(const char *fname, time_t modtime, uint32 mod_nsec, mode_t mode) { static int switch_step = 0; if (DEBUG_GTE(TIME, 1)) { rprintf(FINFO, "set modtime of %s to (%ld) %s", fname, (long)modtime, asctime(localtime(&modtime))); } switch (switch_step) { #ifdef HAVE_UTIMENSAT #include "case_N.h" if (do_utimensat(fname, modtime, mod_nsec) == 0) break; if (errno != ENOSYS) return -1; switch_step++; /* FALLTHROUGH */ #endif #ifdef HAVE_LUTIMES #include "case_N.h" if (do_lutimes(fname, modtime, mod_nsec) == 0) break; if (errno != ENOSYS) return -1; switch_step++; /* FALLTHROUGH */ #endif #include "case_N.h" switch_step++; if (preserve_times & PRESERVE_LINK_TIMES) { preserve_times &= ~PRESERVE_LINK_TIMES; if (S_ISLNK(mode)) return 1; } /* FALLTHROUGH */ #include "case_N.h" #ifdef HAVE_UTIMES if (do_utimes(fname, modtime, mod_nsec) == 0) break; #else if (do_utime(fname, modtime, mod_nsec) == 0) break; #endif return -1; } return 0; }
int attribs_set(struct asfd *asfd, const char *path, struct stat *statp, uint64_t winattr, struct cntr *cntr) { struct utimbuf ut; ut.actime=statp->st_atime; ut.modtime=statp->st_mtime; #ifdef HAVE_WIN32 win32_chmod(path, statp->st_mode, winattr); set_file_times(asfd, path, &ut, statp, cntr); return 0; #endif if(lchown(path, statp->st_uid, statp->st_gid)<0) { berrno be; berrno_init(&be); logw(asfd, cntr, "Unable to set file owner %s: ERR=%s\n", path, berrno_bstrerror(&be, errno)); return -1; } /* Watch out, a metadata restore will have cmd set to CMD_METADATA or CMD_ENC_META, but that is OK at the moment because we are not doing meta stuff on links. */ if(S_ISLNK(statp->st_mode)) { #ifdef HAVE_LUTIMES if(do_lutimes(path, statp)) { berrno be; berrno_init(&be); logw(asfd, cntr, "Unable to set lutimes %s: ERR=%s\n", path, berrno_bstrerror(&be, errno)); return -1; } #endif } else { if(chmod(path, statp->st_mode) < 0) { berrno be; berrno_init(&be); logw(asfd, cntr, "Unable to set file modes %s: ERR=%s\n", path, berrno_bstrerror(&be, errno)); return -1; } if(set_file_times(asfd, path, &ut, statp, cntr)) return -1; #ifdef HAVE_CHFLAGS /* * FreeBSD user flags * * Note, this should really be done before the utime() above, * but if the immutable bit is set, it will make the utimes() * fail. */ if(chflags(path, statp->st_flags)<0) { berrno be; berrno_init(&be); logw(asfd, cntr, "Unable to set file flags %s: ERR=%s\n", path, berrno_bstrerror(&be, errno)); return -1; } #endif } return 0; }