Fri, 12 Apr 2019 15:00:50 +0200
remove dead db entry when files are moved
dav/sync.c | file | annotate | diff | comparison | revisions | |
dav/sync.h | file | annotate | diff | comparison | revisions |
--- a/dav/sync.c Fri Apr 12 14:22:18 2019 +0200 +++ b/dav/sync.c Fri Apr 12 15:00:50 2019 +0200 @@ -758,7 +758,7 @@ MovedFile *mf = malloc(sizeof(MovedFile)); mf->content = local; mf->resource = res; - if(ucx_map_cstr_get(lres_removed, local->path)) { + if(ucx_map_cstr_remove(lres_removed, local->path)) { mf->copy = FALSE; } else { mf->copy = TRUE; @@ -1213,7 +1213,20 @@ char *etag = dav_get_string_property(res, "D:getetag"); char *content_hash = sync_get_content_hash(res); - LocalResource *local = local_resource_copy(content, res->path); + LocalResource *local = NULL; + if(copy) { + local = local_resource_copy(content, res->path); + } else { + // reuse previous LocalResource (content) + // remove it from db->resources, change path and put it back + local = ucx_map_cstr_remove(db->resources, content->path); + if(!local) { + // can't happen, but handle it nevertheless + local = content; + } + free(content->path); + local->path = strdup(res->path); + } ucx_map_cstr_put(db->resources, local->path, local); if(sync_store_metadata(dir, new_path, local, res)) { @@ -1865,6 +1878,7 @@ printf("%s: %s -> %s\n", copy ? "copy":"move", local->origin->path, local->path); err = sync_move_remote_resource( dir, + db, origin_res, local, copy, @@ -3578,6 +3592,7 @@ int sync_move_remote_resource( SyncDirectory *dir, + SyncDatabase *db, DavResource *origin, LocalResource *local, DavBool copy, @@ -3605,8 +3620,11 @@ return result; } + LocalResource *local_origin = local->origin; + if(!copy) { + ucx_map_cstr_remove(db->resources, local_origin->path); + } // replace LocalResource with origin content - LocalResource *local_origin = local->origin; local->origin = NULL; char *path = strdup(local->path); // TODO: free stuff before replacing it
--- a/dav/sync.h Fri Apr 12 14:22:18 2019 +0200 +++ b/dav/sync.h Fri Apr 12 15:00:50 2019 +0200 @@ -168,6 +168,7 @@ int sync_mkdir(SyncDirectory *dir, DavResource *res, LocalResource *local); int sync_move_remote_resource( SyncDirectory *dir, + SyncDatabase *db, DavResource *origin, LocalResource *local, DavBool copy,