Fri, 12 Apr 2019 14:22:18 +0200
fix push operation order (move before put)
dav/sync.c | file | annotate | diff | comparison | revisions |
--- a/dav/sync.c Fri Apr 12 12:42:41 2019 +0200 +++ b/dav/sync.c Fri Apr 12 14:22:18 2019 +0200 @@ -597,7 +597,6 @@ UcxList *res_modified = NULL; UcxList *res_new = NULL; UcxList *res_moved = NULL; // type: MovedFile - UcxList *res_copied = NULL; // type: MovedFile UcxList *res_conflict = NULL; UcxList *res_mkdir = NULL; UcxList *res_metadata = NULL; @@ -1824,17 +1823,75 @@ ucx_map_cstr_remove(db->resources, local->path); } - ls_delete = ucx_list_sort(ls_delete, (cmp_func)resource_pathlen_cmp, NULL); - // // BEGIN PUSH // + int ret = 0; + int error = 0; + + // copy/move files + DavBool copy = TRUE; + if(!ls_copy) { + copy = FALSE; + ls_copy = ls_move; + } + for(UcxList *elm=ls_copy;elm && !sync_shutdown;elm=elm->next) { + LocalResource *local = elm->data; + + int err = 0; + DavResource *res = dav_resource_new(sn, local->path); + if(dav_exists(res)) { + printf("conflict: %s\n", local->path); + local->last_modified = 0; + nullfree(local->etag); + local->etag = NULL; + nullfree(local->hash); + local->hash = NULL; + local->skipped = TRUE; + sync_conflict++; + } else { + DavResource *origin_res = dav_resource_new(sn, local->origin->path); + int origin_changed = remote_resource_is_changed( + sn, + dir, + db, + origin_res, + local->origin); + if(origin_changed) { + // upload with put + ls_modified = ucx_list_prepend(ls_modified, local); + } else { + printf("%s: %s -> %s\n", copy ? "copy":"move", local->origin->path, local->path); + err = sync_move_remote_resource( + dir, + origin_res, + local, + copy, + &sync_success); + } + } + + if(err) { + sync_error++; + print_resource_error(sn, res->path); + ret = -1; + error = 1; + } + + LocalResource *dbres = ucx_map_cstr_remove(db->resources, local->path); + ucx_map_cstr_put(db->resources, local->path, local); + + if(copy && !elm->next) { + // finished copy, begin move + elm->next = ls_move; + copy = FALSE; + } + } + // upload changed files ls_modified = ucx_list_concat(ls_new, ls_modified); - int ret = 0; - int error = 0; for(UcxList *elm=ls_modified;elm && !sync_shutdown;elm=elm->next) { LocalResource *local_res = elm->data; @@ -1900,67 +1957,6 @@ //if(dbres) local_resource_free(dbres); } - DavBool copy = TRUE; - if(!ls_copy) { - copy = FALSE; - ls_copy = ls_move; - } - for(UcxList *elm=ls_copy;elm && !sync_shutdown;elm=elm->next) { - LocalResource *local = elm->data; - - int err = 0; - DavResource *res = dav_resource_new(sn, local->path); - if(dav_exists(res)) { - printf("conflict: %s\n", local->path); - local->last_modified = 0; - nullfree(local->etag); - local->etag = NULL; - nullfree(local->hash); - local->hash = NULL; - local->skipped = TRUE; - sync_conflict++; - } else { - DavResource *origin_res = dav_resource_new(sn, local->origin->path); - int origin_changed = remote_resource_is_changed( - sn, - dir, - db, - origin_res, - local->origin); - if(origin_changed) { - // upload with put - printf("put: %s\n", local->path); - err = sync_put_resource(dir, res, local, &sync_success); - - // TODO: if move, delete old resource - } else { - printf("%s: %s -> %s\n", copy ? "copy":"move", local->origin->path, local->path); - err = sync_move_remote_resource( - dir, - origin_res, - local, - copy, - &sync_success); - } - } - - if(err) { - sync_error++; - print_resource_error(sn, res->path); - ret = -1; - error = 1; - } - - LocalResource *dbres = ucx_map_cstr_remove(db->resources, local->path); - ucx_map_cstr_put(db->resources, local->path, local); - - if(copy && !elm->next) { - // finished copy, begin move - elm->next = ls_move; - copy = FALSE; - } - } - // metadata updates for(UcxList *elm=ls_update;elm && !sync_shutdown;elm=elm->next) { LocalResource *local_res = elm->data; @@ -1975,6 +1971,8 @@ } // delete all removed files + ls_delete = ucx_list_sort(ls_delete, (cmp_func)resource_pathlen_cmp, NULL); + UcxList *cols = NULL; UcxList **col_list = &cols; UcxList *deletelist = ls_delete;