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 } |
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; |