diff -r c5759ac76c1b -r 9c486ea25161 dav/sync.c --- a/dav/sync.c Thu Jul 03 15:50:13 2014 +0200 +++ b/dav/sync.c Thu Jul 03 16:16:02 2014 +0200 @@ -134,17 +134,24 @@ // TODO: free return 0; // empty repository } - + + UcxMap *svrres = ucx_map_new(db->resources->count); + UcxList *stack = ucx_list_prepend(NULL, ls->children); while(stack) { DavResource *res = stack->data; stack = ucx_list_remove(stack, stack); - while(res) { + while(res) { + // download the resource if(sync_get_resource(dir, res, db)) { fprintf(stderr, "sync_get_resource failed for resource: %s\n", res->path); } + LocalResource *local = ucx_map_cstr_get(db->resources, res->path); + ucx_map_cstr_put(svrres, res->path, local); + ucx_map_cstr_remove(db->resources, res->path); + if(res->children) { stack = ucx_list_prepend(stack, res->children); } @@ -152,6 +159,14 @@ } } + UcxMapIterator i = ucx_map_iterator(db->resources); + LocalResource *local; + UCX_MAP_FOREACH(key, local, i) { + sync_remove_resource(dir, local); + } + ucx_map_free(db->resources); + db->resources = svrres; + // TODO: cleanup // store db @@ -239,6 +254,26 @@ return ret; } +void sync_remove_resource(SyncDirectory *dir, LocalResource *res) { + char *local_path = util_concat_path(dir->path, res->path); + struct stat s; + if(stat(local_path, &s)) { + free(local_path); + return; + } + + if(s.st_mtim.tv_sec != res->last_modified) { + free(local_path); + return; + } + + printf("delete: %s\n", res->path); + if(unlink(local_path)) { + fprintf(stderr, "Cannot remove file %s\n", local_path); + } + free(local_path); +} + int cmd_push(CmdArgs *a) { if(a->argc != 1) { fprintf(stderr, "Too %s arguments\n", a->argc < 1 ? "few" : "many");