# HG changeset patch # User Olaf Wintermann # Date 1565513845 -7200 # Node ID 06f9fddc82a1a4126add37523fcb9ef778e66396 # Parent a93374f1849aaec286a8ea216b382fdb02b5cf55 don't store weak etag in LocalResource diff -r a93374f1849a -r 06f9fddc82a1 dav/sync.c --- a/dav/sync.c Sun Aug 11 08:58:58 2019 +0200 +++ b/dav/sync.c Sun Aug 11 10:57:25 2019 +0200 @@ -1274,9 +1274,8 @@ fprintf(stderr, "Cannot store metadata: %s\n", res->path); } - if(local->etag) { - free(local->etag); - } + // dont free local->etag, because local_resource_set_etag will do that + if(local->hash) { free(local->hash); } @@ -1288,7 +1287,7 @@ } // set metadata from stat - local->etag = nullstrdup(etag); + local_resource_set_etag(local, etag); local->hash = nullstrdup(content_hash); sync_set_metadata_from_stat(local, &s); @@ -1464,7 +1463,7 @@ } // set metadata from stat - local->etag = strdup(etag); + local_resource_set_etag(local, etag); if(content_hash) { local->hash = content_hash; } @@ -2844,6 +2843,24 @@ return 0; } +void local_resource_set_etag(LocalResource *local, const char *etag) { + // free old etag + if(local->etag) { + free(local->etag); + } + + if(!etag) { + local->etag = NULL; + return; + } + + scstr_t e = scstr(etag); + if(sstrprefix(e, S("W/"))) { + e = scstrsubs(e, 2); + } + local->etag = sstrdup(e).ptr; +} + char* resource_local_path(DavResource *res) { #ifdef SYS_LINK_EXT // on Windows, add .lnk extension to links @@ -3816,21 +3833,7 @@ } else { // everything seems fine, we can update the local resource char *etag = dav_get_string_property(up_res, "D:getetag"); - if(etag) { - if(strlen(etag) > 2 && etag[0] == 'W' && etag[1] == '/') { - etag = etag + 2; - } - } - - if(local->etag) { - free(local->etag); - } - - if(etag) { - local->etag = strdup(etag); - } else { - local->etag = NULL; - } + local_resource_set_etag(local, etag); if(!issplit && dir->hashing) { if(local->hash) { @@ -3928,21 +3931,7 @@ // everything seems fine, we can update the local resource char *etag = dav_get_string_property(up_res, "D:getetag"); - if(etag) { - if(strlen(etag) > 2 && etag[0] == 'W' && etag[1] == '/') { - etag = etag + 2; - } - } - - if(local->etag) { - free(local->etag); - } - - if(etag) { - local->etag = strdup(etag); - } else { - local->etag = NULL; - } + local_resource_set_etag(local, etag); local->last_modified = s.st_mtime; diff -r a93374f1849a -r 06f9fddc82a1 dav/sync.h --- a/dav/sync.h Sun Aug 11 08:58:58 2019 +0200 +++ b/dav/sync.h Sun Aug 11 10:57:25 2019 +0200 @@ -152,6 +152,9 @@ DavResource *remote, LocalResource *res); int local_resource_load_metadata(SyncDirectory *dir, LocalResource *res); + +void local_resource_set_etag(LocalResource *local, const char *etag); + char* resource_local_path(DavResource *res); size_t resource_get_blocksize(SyncDirectory *dir, LocalResource *local, DavResource *res, off_t filesize);