dav/sync.c

changeset 569
cafdc13b6820
parent 568
a81cad6bb377
child 570
00b7b8e86c48
equal deleted inserted replaced
568:a81cad6bb377 569:cafdc13b6820
756 } 756 }
757 757
758 MovedFile *mf = malloc(sizeof(MovedFile)); 758 MovedFile *mf = malloc(sizeof(MovedFile));
759 mf->content = local; 759 mf->content = local;
760 mf->resource = res; 760 mf->resource = res;
761 if(ucx_map_cstr_get(lres_removed, local->path)) { 761 if(ucx_map_cstr_remove(lres_removed, local->path)) {
762 mf->copy = FALSE; 762 mf->copy = FALSE;
763 } else { 763 } else {
764 mf->copy = TRUE; 764 mf->copy = TRUE;
765 } 765 }
766 766
1211 (*counter)++; 1211 (*counter)++;
1212 1212
1213 char *etag = dav_get_string_property(res, "D:getetag"); 1213 char *etag = dav_get_string_property(res, "D:getetag");
1214 char *content_hash = sync_get_content_hash(res); 1214 char *content_hash = sync_get_content_hash(res);
1215 1215
1216 LocalResource *local = local_resource_copy(content, res->path); 1216 LocalResource *local = NULL;
1217 if(copy) {
1218 local = local_resource_copy(content, res->path);
1219 } else {
1220 // reuse previous LocalResource (content)
1221 // remove it from db->resources, change path and put it back
1222 local = ucx_map_cstr_remove(db->resources, content->path);
1223 if(!local) {
1224 // can't happen, but handle it nevertheless
1225 local = content;
1226 }
1227 free(content->path);
1228 local->path = strdup(res->path);
1229 }
1217 ucx_map_cstr_put(db->resources, local->path, local); 1230 ucx_map_cstr_put(db->resources, local->path, local);
1218 1231
1219 if(sync_store_metadata(dir, new_path, local, res)) { 1232 if(sync_store_metadata(dir, new_path, local, res)) {
1220 fprintf(stderr, "Cannot store metadata: %s\n", res->path); 1233 fprintf(stderr, "Cannot store metadata: %s\n", res->path);
1221 } 1234 }
1863 ls_modified = ucx_list_prepend(ls_modified, local); 1876 ls_modified = ucx_list_prepend(ls_modified, local);
1864 } else { 1877 } else {
1865 printf("%s: %s -> %s\n", copy ? "copy":"move", local->origin->path, local->path); 1878 printf("%s: %s -> %s\n", copy ? "copy":"move", local->origin->path, local->path);
1866 err = sync_move_remote_resource( 1879 err = sync_move_remote_resource(
1867 dir, 1880 dir,
1881 db,
1868 origin_res, 1882 origin_res,
1869 local, 1883 local,
1870 copy, 1884 copy,
1871 &sync_success); 1885 &sync_success);
1872 } 1886 }
3576 return ret; 3590 return ret;
3577 } 3591 }
3578 3592
3579 int sync_move_remote_resource( 3593 int sync_move_remote_resource(
3580 SyncDirectory *dir, 3594 SyncDirectory *dir,
3595 SyncDatabase *db,
3581 DavResource *origin, 3596 DavResource *origin,
3582 LocalResource *local, 3597 LocalResource *local,
3583 DavBool copy, 3598 DavBool copy,
3584 int *counter) 3599 int *counter)
3585 { 3600 {
3603 3618
3604 if(result != 0) { 3619 if(result != 0) {
3605 return result; 3620 return result;
3606 } 3621 }
3607 3622
3623 LocalResource *local_origin = local->origin;
3624 if(!copy) {
3625 ucx_map_cstr_remove(db->resources, local_origin->path);
3626 }
3608 // replace LocalResource with origin content 3627 // replace LocalResource with origin content
3609 LocalResource *local_origin = local->origin;
3610 local->origin = NULL; 3628 local->origin = NULL;
3611 char *path = strdup(local->path); 3629 char *path = strdup(local->path);
3612 // TODO: free stuff before replacing it 3630 // TODO: free stuff before replacing it
3613 memcpy(local, local_origin, sizeof(LocalResource)); 3631 memcpy(local, local_origin, sizeof(LocalResource));
3614 local->path = path; 3632 local->path = path;

mercurial