@@ -65,6 +65,8 @@ typedef struct {
65
65
uint64_t downloadedsize ;
66
66
uint64_t localsize ;
67
67
uint64_t hash ;
68
+ time_t crtime ;
69
+ time_t mtime ;
68
70
psync_folderid_t localfolderid ;
69
71
unsigned char checksum [PSYNC_HASH_DIGEST_HEXLEN ];
70
72
char indwllist ;
@@ -481,17 +483,22 @@ static int stat_and_create_local(psync_syncid_t syncid, psync_fileid_t fileid, p
481
483
return psync_sql_commit_transaction ();
482
484
}
483
485
484
- static int rename_and_create_local (const char * src , const char * dst , psync_syncid_t syncid , psync_fileid_t fileid , psync_folderid_t localfolderid ,
485
- const char * filename , unsigned char * checksum , uint64_t serversize , uint64_t hash ){
486
+ // rename_and_create_local(dt->tmpname, dt->localname, dt->dwllist.syncid, dt->dwllist.fileid, dt->localfolderid, dt->filename, serverhashhex, serversize, hash))
487
+ //static int rename_and_create_local(const char *src, const char *dst, psync_syncid_t syncid, psync_fileid_t fileid, psync_folderid_t localfolderid,
488
+ // const char *filename, unsigned char *checksum, uint64_t serversize, uint64_t hash){
489
+
490
+
491
+ static int rename_and_create_local (download_task_t * dt , unsigned char * checksum , uint64_t serversize , uint64_t hash ){
486
492
psync_stop_localscan ();
487
- if (rename_if_notex (src , dst , fileid , localfolderid , syncid , filename )){
493
+ psync_set_crtime_mtime (dt -> tmpname , dt -> crtime , dt -> mtime );
494
+ if (rename_if_notex (dt -> tmpname , dt -> localname , dt -> dwllist .fileid , dt -> localfolderid , dt -> dwllist .syncid , dt -> filename )){
488
495
psync_resume_localscan ();
489
- debug (D_WARNING , "failed to rename %s to %s" , src , dst );
496
+ debug (D_WARNING , "failed to rename %s to %s" , dt -> tmpname , dt -> localname );
490
497
psync_milisleep (1000 );
491
498
return -1 ;
492
499
}
493
- if (stat_and_create_local (syncid , fileid , localfolderid , filename , dst , checksum , serversize , hash )){
494
- debug (D_WARNING , "stat_and_create_local failed for file %s" , dst );
500
+ if (stat_and_create_local (dt -> dwllist . syncid , dt -> dwllist . fileid , dt -> localfolderid , dt -> filename , dt -> localname , checksum , serversize , hash )){
501
+ debug (D_WARNING , "stat_and_create_local failed for file %s" , dt -> localname );
495
502
psync_resume_localscan ();
496
503
return -1 ;
497
504
}
@@ -587,7 +594,7 @@ static int task_download_file(download_task_t *dt){
587
594
sql = NULL ;
588
595
rt = psync_copy_local_file_if_checksum_matches (tmpold , dt -> tmpname , serverhashhex , serversize );
589
596
if (likely (rt == PSYNC_NET_OK )){
590
- if (rename_and_create_local (dt -> tmpname , dt -> localname , dt -> dwllist . syncid , dt -> dwllist . fileid , dt -> localfolderid , dt -> filename , serverhashhex , serversize , hash ))
597
+ if (rename_and_create_local (dt , serverhashhex , serversize , hash ))
591
598
rt = PSYNC_NET_TEMPFAIL ;
592
599
else
593
600
debug (D_NOTICE , "file %s copied from %s" , dt -> localname , tmpold );
@@ -611,7 +618,7 @@ static int task_download_file(download_task_t *dt){
611
618
if (serversize >=PSYNC_MIN_SIZE_FOR_P2P ){
612
619
rt = psync_p2p_check_download (dt -> dwllist .fileid , serverhashhex , serversize , dt -> tmpname );
613
620
if (rt == PSYNC_NET_OK ){
614
- if (rename_and_create_local (dt -> tmpname , dt -> localname , dt -> dwllist . syncid , dt -> dwllist . fileid , dt -> localfolderid , dt -> filename , serverhashhex , serversize , hash ))
621
+ if (rename_and_create_local (dt , serverhashhex , serversize , hash ))
615
622
return -1 ;
616
623
else
617
624
return 0 ;
@@ -761,7 +768,7 @@ static int task_download_file(download_task_t *dt){
761
768
psync_file_delete (dt -> tmpname );
762
769
goto err0 ;
763
770
}
764
- if (rename_and_create_local (dt -> tmpname , dt -> localname , dt -> dwllist . syncid , dt -> dwllist . fileid , dt -> localfolderid , dt -> filename , serverhashhex , serversize , hash ))
771
+ if (rename_and_create_local (dt , serverhashhex , serversize , hash ))
765
772
goto err0 ;
766
773
// psync_send_event_by_id(PEVENT_FILE_DOWNLOAD_FINISHED, syncid, name, fileid);
767
774
debug (D_NOTICE , "file downloaded %s" , dt -> localname );
@@ -981,8 +988,7 @@ typedef struct {
981
988
static void rename_create_thread (void * ptr ){
982
989
async_res_dt_t * ard ;
983
990
ard = (async_res_dt_t * )ptr ;
984
- if (rename_and_create_local (ard -> dt -> tmpname , ard -> dt -> localname , ard -> dt -> dwllist .syncid , ard -> dt -> dwllist .fileid , ard -> dt -> localfolderid , ard -> dt -> filename ,
985
- ard -> res .file .sha1hex , ard -> res .file .size , ard -> res .file .hash )){
991
+ if (rename_and_create_local (ard -> dt , ard -> res .file .sha1hex , ard -> res .file .size , ard -> res .file .hash )){
986
992
set_task_inprogress (ard -> dt -> taskid , 0 );
987
993
free_download_task (ard -> dt );
988
994
psync_free (ard );
@@ -1022,8 +1028,7 @@ static void finish_async_download(void *ptr, psync_async_result_t *res){
1022
1028
ard -> dt = dt ;
1023
1029
psync_timer_register (rename_create_timer , 2 , ard );
1024
1030
#else
1025
- if (rename_and_create_local (dt -> tmpname , dt -> localname , dt -> dwllist .syncid , dt -> dwllist .fileid , dt -> localfolderid , dt -> filename ,
1026
- res -> file .sha1hex , res -> file .size , res -> file .hash ))
1031
+ if (rename_and_create_local (dt , res -> file .sha1hex , res -> file .size , res -> file .hash ))
1027
1032
psync_timer_register (free_task_timer , 1 , dt );
1028
1033
else {
1029
1034
delete_task (dt -> taskid );
@@ -1081,21 +1086,26 @@ static int task_run_download_file(uint64_t taskid, psync_syncid_t syncid, psync_
1081
1086
char * localpath , * localname , * tmpname ;
1082
1087
psync_file_lock_t * lock ;
1083
1088
uint64_t size , minfree , hash , csize ;
1089
+ time_t crtime , mtime ;
1084
1090
int64_t freespace ;
1085
1091
size_t len ;
1086
1092
unsigned char targetchecksum [PSYNC_HASH_DIGEST_HEXLEN ];
1087
1093
int hastargetchecksum , ret ;
1088
- res = psync_sql_query_rdlock ("SELECT size, hash FROM file WHERE id=?" );
1094
+ res = psync_sql_query_rdlock ("SELECT size, hash, ctime, mtime FROM file WHERE id=?" );
1089
1095
psync_sql_bind_uint (res , 1 , fileid );
1090
1096
row = psync_sql_fetch_rowint (res );
1091
1097
if (row ){
1092
1098
size = row [0 ];
1093
1099
hash = row [1 ];
1100
+ crtime = row [2 ];
1101
+ mtime = row [3 ];
1094
1102
}
1095
1103
else {
1096
1104
// make compiler happy :)
1097
1105
size = 0 ;
1098
1106
hash = 0 ;
1107
+ crtime = 0 ;
1108
+ mtime = 0 ;
1099
1109
}
1100
1110
psync_sql_free_result (res );
1101
1111
if (!row ){
@@ -1129,6 +1139,8 @@ static int task_run_download_file(uint64_t taskid, psync_syncid_t syncid, psync_
1129
1139
dt -> tmpname = tmpname ;
1130
1140
dt -> size = size ;
1131
1141
dt -> hash = hash ;
1142
+ dt -> crtime = crtime ;
1143
+ dt -> mtime = mtime ;
1132
1144
dt -> localfolderid = localfolderid ;
1133
1145
memcpy (dt -> filename , filename , len + 1 );
1134
1146
pthread_mutex_lock (& current_downloads_mutex );
@@ -1158,7 +1170,7 @@ static int task_run_download_file(uint64_t taskid, psync_syncid_t syncid, psync_
1158
1170
if (hastargetchecksum && psync_get_local_file_checksum (tmpname , dt -> checksum , & csize )== PSYNC_NET_OK && csize == size &&
1159
1171
!memcmp (dt -> checksum , targetchecksum , PSYNC_HASH_DIGEST_HEXLEN )){
1160
1172
debug (D_NOTICE , "found file %s, candidate for %s with the right size and checksum" , tmpname , localname );
1161
- ret = rename_and_create_local (tmpname , localname , syncid , fileid , localfolderid , filename , targetchecksum , size , hash );
1173
+ ret = rename_and_create_local (dt , targetchecksum , size , hash );
1162
1174
free_download_task (dt );
1163
1175
return ret ;
1164
1176
}
0 commit comments