Thu, 17 Mar 2016 22:02:15 +0100
automatically remove deleted conflict files from the db
dav/sync.c | file | annotate | diff | comparison | revisions | |
dav/sync.h | file | annotate | diff | comparison | revisions |
--- a/dav/sync.c Thu Mar 17 21:11:19 2016 +0100 +++ b/dav/sync.c Thu Mar 17 22:02:15 2016 +0100 @@ -207,6 +207,7 @@ fprintf(stderr, "Cannot load database file: %s\n", dir->database); return -1; } + remove_deleted_conflicts(dir, db); char *new_url = NULL; if(dir->collection) { @@ -649,6 +650,7 @@ fprintf(stderr, "Cannot load database file: %s\n", dir->database); return -1; } + remove_deleted_conflicts(dir, db); char *new_url = NULL; if(dir->collection) { @@ -1075,6 +1077,32 @@ } +void remove_deleted_conflicts(SyncDirectory *dir, SyncDatabase *db) { + char **dc = calloc(sizeof(void*), db->conflict->count); + int numdc = 0; + + UcxMapIterator i = ucx_map_iterator(db->conflict); + LocalResource *res; + UCX_MAP_FOREACH(key, res, i) { + char *path = util_concat_path(dir->path, res->path); + struct stat s; + if(stat(path, &s)) { + if(errno == ENOENT) { + dc[numdc] = res->path; + numdc++; + } else { + fprintf(stderr, "Cannot stat file: %s\n", path); + perror(""); + } + } + free(path); + } + + for(int i=0;i<numdc;i++) { + ucx_map_cstr_remove(db->conflict, dc[i]); + } +} + int cmd_resolve_conflicts(CmdArgs *a) { if(a->argc != 1) { fprintf(stderr, "Too %s arguments\n", a->argc < 1 ? "few" : "many");
--- a/dav/sync.h Thu Mar 17 21:11:19 2016 +0100 +++ b/dav/sync.h Thu Mar 17 22:02:15 2016 +0100 @@ -74,6 +74,7 @@ int sync_mkdir(SyncDirectory *dir, DavResource *res, LocalResource *local); int sync_delete_remote_resource(DavSession *sn, LocalResource *res, int *counter); +void remove_deleted_conflicts(SyncDirectory *dir, SyncDatabase *db); int cmd_resolve_conflicts(CmdArgs *args); int cmd_delete_conflicts(CmdArgs *args);