Sun, 07 Apr 2019 10:44:29 +0200
add copy/move operation
dav/sync.c | file | annotate | diff | comparison | revisions |
--- a/dav/sync.c Sun Apr 07 09:07:33 2019 +0200 +++ b/dav/sync.c Sun Apr 07 10:44:29 2019 +0200 @@ -1584,8 +1584,14 @@ LocalResource *local = elm->data; UcxList *prev = elm->prev; UcxList *next = elm->next; + if(local->isdirectory) { + elm = elm->next; + continue; + } + char *local_path = util_concat_path(dir->path, local->path); char *hash = util_file_hash(local_path); + local->hash = hash; // check if a file with this hash already exists LocalResource *origin = ucx_map_cstr_get(db_hashes, hash); if(origin) { @@ -1611,7 +1617,6 @@ } } - free(hash); free(local_path); elm = next; @@ -1724,6 +1729,44 @@ //if(dbres) local_resource_free(dbres); } + DavBool copy = TRUE; + for(UcxList *elm=ls_copy;elm && !sync_shutdown;elm=elm->next) { + LocalResource *local = elm->data; + DavResource *res = dav_resource_new(sn, local->origin); + int err = 0; + if(copy) { + printf("copy: %s -> %s\n", local->origin, local->path); + err = dav_copy_o(res, local->path, FALSE); + + if(!elm->next) { + // finished copy, begin move + elm->next = ls_move; + copy = FALSE; + } + } else { + printf("move: %s -> %s\n", local->origin, local->path); + err = dav_move_o(res, local->path, FALSE); + } + + if(err) { + if(sn->error == DAV_PRECONDITION_FAILED) { + printf("conflict: %s\n", local->path); + local->last_modified = 0; + local->skipped = TRUE; + sync_skipped++; + } else { + sync_error++; + print_resource_error(sn, res->path); + ret = -1; + error = 1; + } + } + + dav_resource_free(res); + LocalResource *dbres = ucx_map_cstr_remove(db->resources, local->path); + ucx_map_cstr_put(db->resources, local->path, local); + } + // metadata updates for(UcxList *elm=ls_update;elm && !sync_shutdown;elm=elm->next) { LocalResource *local_res = elm->data;