Skip to content

Commit 02ea1b5

Browse files
author
virco
committed
sync download now sets creation/modification time to the one in the cloud
1 parent 3a4e990 commit 02ea1b5

File tree

2 files changed

+30
-18
lines changed

2 files changed

+30
-18
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 "e8fa7f4fd244091f9b56020a95c8f8e7a1ca35b9"
5-
#define GIT_PREV_COMMIT_DATE "2016-12-12 14:07:54 +0200"
6-
#define GIT_COMMIT_DATE "2016-12-12 14:09:36 +0200"
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"
77

88
#endif

pdownload.c

Lines changed: 27 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,8 @@ typedef struct {
6565
uint64_t downloadedsize;
6666
uint64_t localsize;
6767
uint64_t hash;
68+
time_t crtime;
69+
time_t mtime;
6870
psync_folderid_t localfolderid;
6971
unsigned char checksum[PSYNC_HASH_DIGEST_HEXLEN];
7072
char indwllist;
@@ -481,17 +483,22 @@ static int stat_and_create_local(psync_syncid_t syncid, psync_fileid_t fileid, p
481483
return psync_sql_commit_transaction();
482484
}
483485

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){
486492
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)){
488495
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);
490497
psync_milisleep(1000);
491498
return -1;
492499
}
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);
495502
psync_resume_localscan();
496503
return -1;
497504
}
@@ -587,7 +594,7 @@ static int task_download_file(download_task_t *dt){
587594
sql=NULL;
588595
rt=psync_copy_local_file_if_checksum_matches(tmpold, dt->tmpname, serverhashhex, serversize);
589596
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))
591598
rt=PSYNC_NET_TEMPFAIL;
592599
else
593600
debug(D_NOTICE, "file %s copied from %s", dt->localname, tmpold);
@@ -611,7 +618,7 @@ static int task_download_file(download_task_t *dt){
611618
if (serversize>=PSYNC_MIN_SIZE_FOR_P2P){
612619
rt=psync_p2p_check_download(dt->dwllist.fileid, serverhashhex, serversize, dt->tmpname);
613620
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))
615622
return -1;
616623
else
617624
return 0;
@@ -761,7 +768,7 @@ static int task_download_file(download_task_t *dt){
761768
psync_file_delete(dt->tmpname);
762769
goto err0;
763770
}
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))
765772
goto err0;
766773
// psync_send_event_by_id(PEVENT_FILE_DOWNLOAD_FINISHED, syncid, name, fileid);
767774
debug(D_NOTICE, "file downloaded %s", dt->localname);
@@ -981,8 +988,7 @@ typedef struct {
981988
static void rename_create_thread(void *ptr){
982989
async_res_dt_t *ard;
983990
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)){
986992
set_task_inprogress(ard->dt->taskid, 0);
987993
free_download_task(ard->dt);
988994
psync_free(ard);
@@ -1022,8 +1028,7 @@ static void finish_async_download(void *ptr, psync_async_result_t *res){
10221028
ard->dt=dt;
10231029
psync_timer_register(rename_create_timer, 2, ard);
10241030
#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))
10271032
psync_timer_register(free_task_timer, 1, dt);
10281033
else{
10291034
delete_task(dt->taskid);
@@ -1081,21 +1086,26 @@ static int task_run_download_file(uint64_t taskid, psync_syncid_t syncid, psync_
10811086
char *localpath, *localname, *tmpname;
10821087
psync_file_lock_t *lock;
10831088
uint64_t size, minfree, hash, csize;
1089+
time_t crtime, mtime;
10841090
int64_t freespace;
10851091
size_t len;
10861092
unsigned char targetchecksum[PSYNC_HASH_DIGEST_HEXLEN];
10871093
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=?");
10891095
psync_sql_bind_uint(res, 1, fileid);
10901096
row=psync_sql_fetch_rowint(res);
10911097
if (row){
10921098
size=row[0];
10931099
hash=row[1];
1100+
crtime=row[2];
1101+
mtime=row[3];
10941102
}
10951103
else{
10961104
// make compiler happy :)
10971105
size=0;
10981106
hash=0;
1107+
crtime=0;
1108+
mtime=0;
10991109
}
11001110
psync_sql_free_result(res);
11011111
if (!row){
@@ -1129,6 +1139,8 @@ static int task_run_download_file(uint64_t taskid, psync_syncid_t syncid, psync_
11291139
dt->tmpname=tmpname;
11301140
dt->size=size;
11311141
dt->hash=hash;
1142+
dt->crtime=crtime;
1143+
dt->mtime=mtime;
11321144
dt->localfolderid=localfolderid;
11331145
memcpy(dt->filename, filename, len+1);
11341146
pthread_mutex_lock(&current_downloads_mutex);
@@ -1158,7 +1170,7 @@ static int task_run_download_file(uint64_t taskid, psync_syncid_t syncid, psync_
11581170
if (hastargetchecksum && psync_get_local_file_checksum(tmpname, dt->checksum, &csize)==PSYNC_NET_OK && csize==size &&
11591171
!memcmp(dt->checksum, targetchecksum, PSYNC_HASH_DIGEST_HEXLEN)){
11601172
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);
11621174
free_download_task(dt);
11631175
return ret;
11641176
}

0 commit comments

Comments
 (0)