Thu, 30 May 2019 18:23:39 +0200
fix that db entries are updated on errors
dav/sync.c | file | annotate | diff | comparison | revisions |
--- a/dav/sync.c Thu May 30 12:47:28 2019 +0200 +++ b/dav/sync.c Thu May 30 18:23:39 2019 +0200 @@ -1907,7 +1907,7 @@ sync_error++; } - int abort = 0; + //int abort = 0; dav_exists(res); if(sn->error == DAV_NOT_FOUND) { @@ -1919,7 +1919,17 @@ ret = -1; sync_error++; error = 1; - abort = 1; + //abort = 1; + } else { + // success + if(local_res->metadata_updated) { + sync_update_metadata(dir, sn, res, local_res); + } + + // remove old db entry (if it exists) + // and add add new entry + LocalResource *dbres = ucx_map_cstr_remove(db->resources, local_res->path); + ucx_map_cstr_put(db->resources, local_res->path, local_res); } } else if(sn->error != DAV_OK) { // dav_exists() failed @@ -1927,17 +1937,10 @@ ret = -1; sync_error++; error = 1; - abort = 1; - } - - if(local_res->metadata_updated && !abort) { - sync_update_metadata(dir, sn, res, local_res); + //abort = 1; } dav_resource_free(res); - - LocalResource *dbres = ucx_map_cstr_remove(db->resources, local_res->path); - ucx_map_cstr_put(db->resources, local_res->path, local_res); } // copy/move files @@ -1988,11 +1991,11 @@ print_resource_error(sn, res->path); ret = -1; error = 1; + } else { + LocalResource *dbres = ucx_map_cstr_remove(db->resources, local->path); + ucx_map_cstr_put(db->resources, local->path, local); } - 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; @@ -2005,46 +2008,50 @@ for(UcxList *elm=ls_modified;elm && !sync_shutdown;elm=elm->next) { LocalResource *local_res = elm->data; + int err = 0; DavResource *res = dav_resource_new(sn, local_res->path); if(!res) { print_resource_error(sn, local_res->path); ret = -1; sync_error++; - } - - int changed = remote_resource_is_changed(sn, dir, db, res, local_res); - if(cdt && changed) { - printf("conflict: %s\n", local_res->path); - local_res->last_modified = 0; - nullfree(local_res->etag); - local_res->etag = NULL; - nullfree(local_res->hash); - local_res->hash = NULL; - local_res->skipped = TRUE; - sync_conflict++; } else { - if(local_res->link_target) { - printf( - "link: %s -> %s\n", - local_res->path, - local_res->link_target); + int changed = remote_resource_is_changed(sn, dir, db, res, local_res); + if(cdt && changed) { + printf("conflict: %s\n", local_res->path); + local_res->last_modified = 0; + nullfree(local_res->etag); + local_res->etag = NULL; + nullfree(local_res->hash); + local_res->hash = NULL; + local_res->skipped = TRUE; + sync_conflict++; } else { - printf("put: %s\n", local_res->path); + if(local_res->link_target) { + printf( + "link: %s -> %s\n", + local_res->path, + local_res->link_target); + } else { + printf("put: %s\n", local_res->path); + } + if(sync_put_resource(dir, res, local_res, &sync_success)) { + sync_error++; + print_resource_error(sn, res->path); + ret = -1; + error = 1; + + err = 1; + } } - if(sync_put_resource(dir, res, local_res, &sync_success)) { - sync_error++; - print_resource_error(sn, res->path); - ret = -1; - error = 1; + + if(!err) { + LocalResource *dbres = ucx_map_cstr_remove(db->resources, local_res->path); + ucx_map_cstr_put(db->resources, local_res->path, local_res); } } dav_resource_free(res); - - LocalResource *dbres = ucx_map_cstr_remove(db->resources, local_res->path); - ucx_map_cstr_put(db->resources, local_res->path, local_res); - //if(dbres) local_resource_free(dbres); } // metadata updates