Skip to content

Commit 7fd8d71

Browse files
author
virco
committed
upload modification date in sync
1 parent 02ea1b5 commit 7fd8d71

File tree

2 files changed

+28
-17
lines changed

2 files changed

+28
-17
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 "3a4e9905706f1bcab3e28372599b6ecf528dd585"
5-
#define GIT_PREV_COMMIT_DATE "2016-12-12 14:09:36 +0200"
6-
#define GIT_COMMIT_DATE "2016-12-12 15:16:21 +0200"
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"
77

88
#endif

pupload.c

Lines changed: 25 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -360,9 +360,12 @@ static void set_local_file_conflicted(psync_fileid_t localfileid, psync_fileid_t
360360
psync_free(newpath);
361361
}
362362

363-
static int copy_file(psync_fileid_t fileid, uint64_t hash, psync_folderid_t folderid, const char *name, psync_fileid_t localfileid){
363+
static int copy_file(psync_fileid_t fileid, uint64_t hash, psync_folderid_t folderid, const char *name, psync_fileid_t localfileid, psync_stat_t *st){
364364
binparam params[]={P_STR("auth", psync_my_auth), P_NUM("fileid", fileid), P_NUM("hash", hash), P_NUM("tofolderid", folderid), P_STR("toname", name),
365-
P_STR("timeformat", "timestamp")};
365+
#if defined(PSYNC_HAS_BIRTHTIME)
366+
P_NUM("ctime", psync_stat_birthtime(st)),
367+
#endif
368+
P_NUM("mtime", psync_stat_mtime(st)), P_STR("timeformat", "timestamp")};
366369
binresult *res;
367370
const binresult *meta;
368371
uint64_t result;
@@ -421,7 +424,8 @@ static int check_file_if_exists(const unsigned char *hashhex, uint64_t fsize, ps
421424
return 0;
422425
}
423426

424-
static int copy_file_if_exists(const unsigned char *hashhex, uint64_t fsize, psync_folderid_t folderid, const char *name, psync_fileid_t localfileid){
427+
static int copy_file_if_exists(const unsigned char *hashhex, uint64_t fsize, psync_folderid_t folderid, const char *name, psync_fileid_t localfileid,
428+
psync_stat_t *st){
425429
binparam params[]={P_STR("auth", psync_my_auth), P_NUM("size", fsize), P_LSTR(PSYNC_CHECKSUM, hashhex, PSYNC_HASH_DIGEST_HEXLEN), P_STR("timeformat", "timestamp")};
426430
binresult *res;
427431
const binresult *metas, *meta;
@@ -443,7 +447,7 @@ static int copy_file_if_exists(const unsigned char *hashhex, uint64_t fsize, psy
443447
return 0;
444448
}
445449
meta=metas->array[0];
446-
ret=copy_file(psync_find_result(meta, "fileid", PARAM_NUM)->num, psync_find_result(meta, "hash", PARAM_NUM)->num, folderid, name, localfileid);
450+
ret=copy_file(psync_find_result(meta, "fileid", PARAM_NUM)->num, psync_find_result(meta, "hash", PARAM_NUM)->num, folderid, name, localfileid, st);
447451
if (ret==1)
448452
debug(D_NOTICE, "file %lu/%s copied to %lu/%s instead of uploading due to matching checksum",
449453
(long unsigned)psync_find_result(meta, "parentfolderid", PARAM_NUM)->num, psync_find_result(meta, "name", PARAM_STR)->str,
@@ -467,9 +471,12 @@ static void add_bytes_uploaded(uint64_t bytes){
467471
}
468472

469473
static int upload_file(const char *localpath, const unsigned char *hashhex, uint64_t fsize, psync_folderid_t folderid, const char *name,
470-
psync_fileid_t localfileid, psync_syncid_t syncid, upload_list_t *upload, binparam pr){
474+
psync_fileid_t localfileid, psync_syncid_t syncid, upload_list_t *upload, psync_stat_t *st, binparam pr){
471475
binparam params[]={P_STR("auth", psync_my_auth), P_NUM("folderid", folderid), P_STR("filename", name), P_BOOL("nopartial", 1), P_STR("timeformat", "timestamp"),
472-
{pr.paramtype, pr.paramnamelen, pr.opts, pr.paramname, {pr.num}} /* specially for Visual Studio compiler */};
476+
#if defined(PSYNC_HAS_BIRTHTIME)
477+
P_NUM("ctime", psync_stat_birthtime(st)),
478+
#endif
479+
P_NUM("mtime", psync_stat_mtime(st)), {pr.paramtype, pr.paramnamelen, pr.opts, pr.paramname, {pr.num}} /* specially for Visual Studio compiler */};
473480
psync_socket *api;
474481
void *buff;
475482
binresult *res;
@@ -651,9 +658,12 @@ static int upload_get_checksum(psync_socket *api, psync_uploadid_t uploadid, uin
651658
}
652659

653660
static int upload_save(psync_socket *api, psync_fileid_t localfileid, const char *localpath, const unsigned char *hashhex, uint64_t size,
654-
psync_uploadid_t uploadid, psync_folderid_t folderid, const char *name, uint64_t taskid, binparam pr){
661+
psync_uploadid_t uploadid, psync_folderid_t folderid, const char *name, uint64_t taskid, psync_stat_t *st, binparam pr){
655662
binparam params[]={P_STR("auth", psync_my_auth), P_NUM("folderid", folderid), P_STR("name", name), P_NUM("uploadid", uploadid), P_STR("timeformat", "timestamp"),
656-
{pr.paramtype, pr.paramnamelen, pr.opts, pr.paramname, {pr.num}} /* specially for Visual Studio compiler */};
663+
#if defined(PSYNC_HAS_BIRTHTIME)
664+
P_NUM("ctime", psync_stat_birthtime(st)),
665+
#endif
666+
P_NUM("mtime", psync_stat_mtime(st)), {pr.paramtype, pr.paramnamelen, pr.opts, pr.paramname, {pr.num}} /* specially for Visual Studio compiler */};
657667
psync_sql_res *sres;
658668
binresult *res;
659669
const binresult *meta;
@@ -699,7 +709,8 @@ static int upload_save(psync_socket *api, psync_fileid_t localfileid, const char
699709
}
700710

701711
static int upload_big_file(const char *localpath, const unsigned char *hashhex, uint64_t fsize, psync_folderid_t folderid, const char *name,
702-
psync_fileid_t localfileid, psync_syncid_t syncid, upload_list_t *upload, psync_uploadid_t uploadid, uint64_t uploadoffset, binparam pr){
712+
psync_fileid_t localfileid, psync_syncid_t syncid, upload_list_t *upload, psync_uploadid_t uploadid, uint64_t uploadoffset,
713+
psync_stat_t *st, binparam pr){
703714
psync_socket *api;
704715
binresult *res;
705716
psync_sql_res *sql;
@@ -905,7 +916,7 @@ static int upload_big_file(const char *localpath, const unsigned char *hashhex,
905916
ret=PSYNC_NET_OK;
906917
psync_file_close(fd);
907918
if (ret==PSYNC_NET_OK)
908-
ret=upload_save(api, localfileid, localpath, hashhex, fsize, uploadid, folderid, name, upload->taskid, pr);
919+
ret=upload_save(api, localfileid, localpath, hashhex, fsize, uploadid, folderid, name, upload->taskid, st, pr);
909920
if (ret==PSYNC_NET_TEMPFAIL){
910921
psync_apipool_release_bad(api);
911922
return -1;
@@ -1106,7 +1117,7 @@ static int task_uploadfile(psync_syncid_t syncid, psync_folderid_t localfileid,
11061117
* not to waste a roundtrip to the server. Few kilos should be fine
11071118
*/
11081119
if (ret==0 && fsize>=PSYNC_MIN_SIZE_FOR_EXISTS_CHECK)
1109-
ret=copy_file_if_exists(hashhex, fsize, folderid, name, localfileid);
1120+
ret=copy_file_if_exists(hashhex, fsize, folderid, name, localfileid, &st);
11101121
if (ret==1 || ret==-1){
11111122
psync_unlock_file(lock);
11121123
psync_free(nname);
@@ -1132,15 +1143,15 @@ static int task_uploadfile(psync_syncid_t syncid, psync_folderid_t localfileid,
11321143
psync_sql_free_result(res);
11331144
debug(D_NOTICE, "uploading file %s", localpath);
11341145
if (fsize<=PSYNC_MIN_SIZE_FOR_CHECKSUMS)
1135-
ret=upload_file(localpath, hashhex, fsize, folderid, name, localfileid, syncid, upload, pr);
1146+
ret=upload_file(localpath, hashhex, fsize, folderid, name, localfileid, syncid, upload, &st, pr);
11361147
else{
11371148
if (uploadid && !memcmp(phashhex, uhashhex, PSYNC_HASH_DIGEST_HEXLEN))
1138-
ret=upload_big_file(localpath, hashhex, fsize, folderid, name, localfileid, syncid, upload, uploadid, ufsize, pr);
1149+
ret=upload_big_file(localpath, hashhex, fsize, folderid, name, localfileid, syncid, upload, uploadid, ufsize, &st, pr);
11391150
else{
11401151
if (uploadid && memcmp(phashhex, uhashhex, PSYNC_HASH_DIGEST_HEXLEN))
11411152
debug(D_WARNING, "restarting upload due to checksum mismatch up to offset %lu, expected: %."NTO_STR(PSYNC_HASH_DIGEST_HEXLEN)
11421153
"s, got: %."NTO_STR(PSYNC_HASH_DIGEST_HEXLEN)"s", (unsigned long)ufsize, phashhex, uhashhex);
1143-
ret=upload_big_file(localpath, hashhex, fsize, folderid, name, localfileid, syncid, upload, 0, 0, pr);
1154+
ret=upload_big_file(localpath, hashhex, fsize, folderid, name, localfileid, syncid, upload, 0, 0, &st, pr);
11441155
}
11451156
}
11461157
psync_unlock_file(lock);

0 commit comments

Comments
 (0)