Skip to content

Commit 000bb62

Browse files
author
virco
committed
reuse openfile file descriptor for setting time (obviosly Win does not like writing from one handle and setting time by another)
1 parent cd1b259 commit 000bb62

File tree

5 files changed

+100
-8
lines changed

5 files changed

+100
-8
lines changed

gitcommit.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
#ifndef _GITCOMMIT_H
22
#define _GITCOMMIT_H
33

4-
#define GIT_PREV_COMMIT_ID "02ea1b5c3daeec50572b1de6cc7ed0b8ad402d2c"
5-
#define GIT_PREV_COMMIT_DATE "2016-12-12 15:16:21 +0200"
6-
#define GIT_COMMIT_DATE "2016-12-12 20:33:12 +0200"
4+
#define GIT_PREV_COMMIT_ID "cd1b259fc6415d7ba9078da20941d4da65a02bf6"
5+
#define GIT_PREV_COMMIT_DATE "2016-12-12 20:33:28 +0200"
6+
#define GIT_COMMIT_DATE "2016-12-19 16:02:18 +0200"
77

88
#endif

pcompat.c

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2827,6 +2827,71 @@ int psync_set_crtime_mtime(const char *path, time_t crtime, time_t mtime){
28272827
#endif
28282828
}
28292829

2830+
int psync_set_crtime_mtime_by_fd(psync_file_t fd, const char *path, time_t crtime, time_t mtime){
2831+
#if defined(P_OS_WINDOWS)
2832+
FILETIME fctime, fmtime, *pfctime, *pfmtime;
2833+
uint64_t tm64;
2834+
int ret;
2835+
if (crtime){
2836+
tm64=Int32x32To64(crtime, 10000000)+116444736000000000;
2837+
fctime.dwLowDateTime=(DWORD)tm64;
2838+
fctime.dwHighDateTime=tm64>>32;
2839+
pfctime=&fctime;
2840+
}
2841+
else
2842+
pfctime=NULL;
2843+
if (mtime){
2844+
tm64=Int32x32To64(mtime, 10000000)+116444736000000000;
2845+
fmtime.dwLowDateTime=(DWORD)tm64;
2846+
fmtime.dwHighDateTime=tm64>>32;
2847+
pfmtime=&fmtime;
2848+
}
2849+
else
2850+
pfmtime=NULL;
2851+
ret=psync_bool_to_zero(SetFileTime(fd, pfctime, NULL, pfmtime));
2852+
return ret;
2853+
#elif defined(P_OS_MACOSX)
2854+
if (crtime){
2855+
struct attrlist attr;
2856+
struct timespec crtime;
2857+
memset(&attr, 0, sizeof(attr));
2858+
attr.bitmapcount=ATTR_BIT_MAP_COUNT;
2859+
attr.commonattr=ATTR_CMN_CRTIME;
2860+
crtime.tv_sec=ctime;
2861+
crtime.tv_nsec=0;
2862+
if (fsetattrlist(fd, &attr, &crtime, sizeof(struct timespec), FSOPT_NOFOLLOW))
2863+
return -1;
2864+
}
2865+
if (mtime){
2866+
struct timeval tm[2];
2867+
tm[0].tv_sec=mtime;
2868+
tm[0].tv_usec=0;
2869+
tm[1].tv_sec=mtime;
2870+
tm[1].tv_usec=0;
2871+
return futimes(fd, tm);
2872+
}
2873+
return 0;
2874+
#elif defined(_BSD_SOURCE) || defined(P_OS_BSD)
2875+
if (mtime){
2876+
struct timeval tm[2];
2877+
tm[0].tv_sec=mtime;
2878+
tm[0].tv_usec=0;
2879+
tm[1].tv_sec=mtime;
2880+
tm[1].tv_usec=0;
2881+
if (unlikely(futimes(fd, tm))){
2882+
debug(D_NOTICE, "got errno %d while setting modification time of %s to %lu: %s", errno, path, (unsigned long)mtime, strerror(errno));
2883+
return -1;
2884+
}
2885+
else
2886+
return 0;
2887+
}
2888+
else
2889+
return 0;
2890+
#else
2891+
return psync_set_crtime_mtime(path, crtime, mtime);
2892+
#endif
2893+
}
2894+
28302895
typedef struct {
28312896
uint64_t offset;
28322897
size_t count;

pcompat.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -492,6 +492,7 @@ int psync_folder_sync(const char *path);
492492
psync_file_t psync_file_dup(psync_file_t fd);
493493
int psync_file_set_creation(psync_file_t fd, time_t ctime);
494494
int psync_set_crtime_mtime(const char *path, time_t crtime, time_t mtime);
495+
int psync_set_crtime_mtime_by_fd(psync_file_t fd, const char *path, time_t crtime, time_t mtime);
495496
int psync_file_preread(psync_file_t fd, uint64_t offset, size_t count);
496497
int psync_file_readahead(psync_file_t fd, uint64_t offset, size_t count);
497498
ssize_t psync_file_read(psync_file_t fd, void *buf, size_t count);

pfs.c

Lines changed: 29 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2758,17 +2758,42 @@ static int psync_fs_set_filetime_locked(psync_fsfileid_t fileid, const struct ti
27582758
else{
27592759
char fileidhex[sizeof(psync_fsfileid_t)*2+2], *filename;
27602760
const char *cachepath;
2761+
psync_tree *tr;
2762+
psync_openfile_t *fl;
2763+
int64_t d;
27612764
int ret;
2765+
tr=openfiles;
2766+
fl=NULL;
2767+
while (tr){
2768+
d=fileid-psync_tree_element(tr, psync_openfile_t, tree)->fileid;
2769+
if (d<0)
2770+
tr=tr->left;
2771+
else if (d>0)
2772+
tr=tr->right;
2773+
else{
2774+
fl=psync_tree_element(tr, psync_openfile_t, tree);
2775+
break;
2776+
}
2777+
}
27622778
fileid=-fileid;
27632779
psync_binhex(fileidhex, &fileid, sizeof(psync_fsfileid_t));
27642780
fileidhex[sizeof(psync_fsfileid_t)]='d';
27652781
fileidhex[sizeof(psync_fsfileid_t)+1]=0;
27662782
cachepath=psync_setting_get_string(_PS(fscachepath));
27672783
filename=psync_strcat(cachepath, PSYNC_DIRECTORY_SEPARATOR, fileidhex, NULL);
2768-
if (crtime)
2769-
ret=psync_set_crtime_mtime(filename, tv->tv_sec, 0);
2770-
else
2771-
ret=psync_set_crtime_mtime(filename, 0, tv->tv_sec);
2784+
if (fl && fl->datafile!=INVALID_HANDLE_VALUE){
2785+
debug(D_NOTICE, "found open file for file id %ld", (long)fl->fileid);
2786+
if (crtime)
2787+
ret=psync_set_crtime_mtime_by_fd(fl->datafile, filename, tv->tv_sec, 0);
2788+
else
2789+
ret=psync_set_crtime_mtime_by_fd(fl->datafile, filename, 0, tv->tv_sec);
2790+
}
2791+
else{
2792+
if (crtime)
2793+
ret=psync_set_crtime_mtime(filename, tv->tv_sec, 0);
2794+
else
2795+
ret=psync_set_crtime_mtime(filename, 0, tv->tv_sec);
2796+
}
27722797
debug(D_NOTICE, "setting %s time of %s to %lu=%d", crtime?"creation":"modification", filename, (unsigned long)tv->tv_sec, ret);
27732798
psync_free(filename);
27742799
return ret?-EACCES:0;

pupload.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -225,8 +225,9 @@ static int task_createfolder(psync_syncid_t syncid, psync_folderid_t localfolder
225225
psync_sql_run_free(res);
226226
ret=psync_sql_commit_transaction();
227227
psync_diff_unlock();
228+
if (psync_find_result(bres, "created", PARAM_BOOL)->num)
229+
psync_diff_wake();
228230
psync_free(bres);
229-
psync_diff_wake();
230231
return ret;
231232
}
232233
}

0 commit comments

Comments
 (0)