dav/sync.c

changeset 621
06f9fddc82a1
parent 619
1d20a6cab2e5
child 626
2f735b0e87fa
equal deleted inserted replaced
620:a93374f1849a 621:06f9fddc82a1
1272 1272
1273 if(sync_store_metadata(dir, new_path, local, res)) { 1273 if(sync_store_metadata(dir, new_path, local, res)) {
1274 fprintf(stderr, "Cannot store metadata: %s\n", res->path); 1274 fprintf(stderr, "Cannot store metadata: %s\n", res->path);
1275 } 1275 }
1276 1276
1277 if(local->etag) { 1277 // dont free local->etag, because local_resource_set_etag will do that
1278 free(local->etag); 1278
1279 }
1280 if(local->hash) { 1279 if(local->hash) {
1281 free(local->hash); 1280 free(local->hash);
1282 } 1281 }
1283 1282
1284 SYS_STAT s; 1283 SYS_STAT s;
1286 fprintf(stderr, 1285 fprintf(stderr,
1287 "Cannot stat file %s: %s\n", new_path, strerror(errno)); 1286 "Cannot stat file %s: %s\n", new_path, strerror(errno));
1288 } 1287 }
1289 1288
1290 // set metadata from stat 1289 // set metadata from stat
1291 local->etag = nullstrdup(etag); 1290 local_resource_set_etag(local, etag);
1292 local->hash = nullstrdup(content_hash); 1291 local->hash = nullstrdup(content_hash);
1293 1292
1294 sync_set_metadata_from_stat(local, &s); 1293 sync_set_metadata_from_stat(local, &s);
1295 local->skipped = FALSE; 1294 local->skipped = FALSE;
1296 1295
1462 fprintf(stderr, 1461 fprintf(stderr,
1463 "Cannot stat file %s: %s\n", local_path, strerror(errno)); 1462 "Cannot stat file %s: %s\n", local_path, strerror(errno));
1464 } 1463 }
1465 1464
1466 // set metadata from stat 1465 // set metadata from stat
1467 local->etag = strdup(etag); 1466 local_resource_set_etag(local, etag);
1468 if(content_hash) { 1467 if(content_hash) {
1469 local->hash = content_hash; 1468 local->hash = content_hash;
1470 } 1469 }
1471 sync_set_metadata_from_stat(local, &s); 1470 sync_set_metadata_from_stat(local, &s);
1472 local->skipped = FALSE; 1471 local->skipped = FALSE;
2842 } 2841 }
2843 2842
2844 return 0; 2843 return 0;
2845 } 2844 }
2846 2845
2846 void local_resource_set_etag(LocalResource *local, const char *etag) {
2847 // free old etag
2848 if(local->etag) {
2849 free(local->etag);
2850 }
2851
2852 if(!etag) {
2853 local->etag = NULL;
2854 return;
2855 }
2856
2857 scstr_t e = scstr(etag);
2858 if(sstrprefix(e, S("W/"))) {
2859 e = scstrsubs(e, 2);
2860 }
2861 local->etag = sstrdup(e).ptr;
2862 }
2863
2847 char* resource_local_path(DavResource *res) { 2864 char* resource_local_path(DavResource *res) {
2848 #ifdef SYS_LINK_EXT 2865 #ifdef SYS_LINK_EXT
2849 // on Windows, add .lnk extension to links 2866 // on Windows, add .lnk extension to links
2850 if(dav_get_property_ns(res, DAV_PROPS_NS, "link")) { 2867 if(dav_get_property_ns(res, DAV_PROPS_NS, "link")) {
2851 return ucx_sprintf("%s%s", res->path, SYS_LINK_EXT).ptr; 2868 return ucx_sprintf("%s%s", res->path, SYS_LINK_EXT).ptr;
3814 // try to set the resource status to 'broken' 3831 // try to set the resource status to 'broken'
3815 sync_set_status(res, "broken"); 3832 sync_set_status(res, "broken");
3816 } else { 3833 } else {
3817 // everything seems fine, we can update the local resource 3834 // everything seems fine, we can update the local resource
3818 char *etag = dav_get_string_property(up_res, "D:getetag"); 3835 char *etag = dav_get_string_property(up_res, "D:getetag");
3819 if(etag) { 3836 local_resource_set_etag(local, etag);
3820 if(strlen(etag) > 2 && etag[0] == 'W' && etag[1] == '/') {
3821 etag = etag + 2;
3822 }
3823 }
3824
3825 if(local->etag) {
3826 free(local->etag);
3827 }
3828
3829 if(etag) {
3830 local->etag = strdup(etag);
3831 } else {
3832 local->etag = NULL;
3833 }
3834 3837
3835 if(!issplit && dir->hashing) { 3838 if(!issplit && dir->hashing) {
3836 if(local->hash) { 3839 if(local->hash) {
3837 free(local->hash); 3840 free(local->hash);
3838 } 3841 }
3926 fprintf(stderr, "Error: cannot store resource metadata\n"); 3929 fprintf(stderr, "Error: cannot store resource metadata\n");
3927 } 3930 }
3928 3931
3929 // everything seems fine, we can update the local resource 3932 // everything seems fine, we can update the local resource
3930 char *etag = dav_get_string_property(up_res, "D:getetag"); 3933 char *etag = dav_get_string_property(up_res, "D:getetag");
3931 if(etag) { 3934 local_resource_set_etag(local, etag);
3932 if(strlen(etag) > 2 && etag[0] == 'W' && etag[1] == '/') {
3933 etag = etag + 2;
3934 }
3935 }
3936
3937 if(local->etag) {
3938 free(local->etag);
3939 }
3940
3941 if(etag) {
3942 local->etag = strdup(etag);
3943 } else {
3944 local->etag = NULL;
3945 }
3946 3935
3947 local->last_modified = s.st_mtime; 3936 local->last_modified = s.st_mtime;
3948 3937
3949 dav_resource_free(up_res); 3938 dav_resource_free(up_res);
3950 } else { 3939 } else {

mercurial