@@ -360,9 +360,12 @@ static void set_local_file_conflicted(psync_fileid_t localfileid, psync_fileid_t
360
360
psync_free (newpath );
361
361
}
362
362
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 ){
364
364
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" )};
366
369
binresult * res ;
367
370
const binresult * meta ;
368
371
uint64_t result ;
@@ -421,7 +424,8 @@ static int check_file_if_exists(const unsigned char *hashhex, uint64_t fsize, ps
421
424
return 0 ;
422
425
}
423
426
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 ){
425
429
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" )};
426
430
binresult * res ;
427
431
const binresult * metas , * meta ;
@@ -443,7 +447,7 @@ static int copy_file_if_exists(const unsigned char *hashhex, uint64_t fsize, psy
443
447
return 0 ;
444
448
}
445
449
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 );
447
451
if (ret == 1 )
448
452
debug (D_NOTICE , "file %lu/%s copied to %lu/%s instead of uploading due to matching checksum" ,
449
453
(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){
467
471
}
468
472
469
473
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 ){
471
475
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 */ };
473
480
psync_socket * api ;
474
481
void * buff ;
475
482
binresult * res ;
@@ -651,9 +658,12 @@ static int upload_get_checksum(psync_socket *api, psync_uploadid_t uploadid, uin
651
658
}
652
659
653
660
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 ){
655
662
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 */ };
657
667
psync_sql_res * sres ;
658
668
binresult * res ;
659
669
const binresult * meta ;
@@ -699,7 +709,8 @@ static int upload_save(psync_socket *api, psync_fileid_t localfileid, const char
699
709
}
700
710
701
711
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 ){
703
714
psync_socket * api ;
704
715
binresult * res ;
705
716
psync_sql_res * sql ;
@@ -905,7 +916,7 @@ static int upload_big_file(const char *localpath, const unsigned char *hashhex,
905
916
ret = PSYNC_NET_OK ;
906
917
psync_file_close (fd );
907
918
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 );
909
920
if (ret == PSYNC_NET_TEMPFAIL ){
910
921
psync_apipool_release_bad (api );
911
922
return -1 ;
@@ -1106,7 +1117,7 @@ static int task_uploadfile(psync_syncid_t syncid, psync_folderid_t localfileid,
1106
1117
* not to waste a roundtrip to the server. Few kilos should be fine
1107
1118
*/
1108
1119
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 );
1110
1121
if (ret == 1 || ret == -1 ){
1111
1122
psync_unlock_file (lock );
1112
1123
psync_free (nname );
@@ -1132,15 +1143,15 @@ static int task_uploadfile(psync_syncid_t syncid, psync_folderid_t localfileid,
1132
1143
psync_sql_free_result (res );
1133
1144
debug (D_NOTICE , "uploading file %s" , localpath );
1134
1145
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 );
1136
1147
else {
1137
1148
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 );
1139
1150
else {
1140
1151
if (uploadid && memcmp (phashhex , uhashhex , PSYNC_HASH_DIGEST_HEXLEN ))
1141
1152
debug (D_WARNING , "restarting upload due to checksum mismatch up to offset %lu, expected: %." NTO_STR (PSYNC_HASH_DIGEST_HEXLEN )
1142
1153
"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 );
1144
1155
}
1145
1156
}
1146
1157
psync_unlock_file (lock );
0 commit comments