# HG changeset patch # User Olaf Wintermann # Date 1541782997 -3600 # Node ID 7bde663719dc59f2ca6b1650c2c21f053cfcdf88 # Parent fdc2fb090cc76f34f05f6796b3000dfcfbba4b6c Adds dav-sync option for enabling versioning diff -r fdc2fb090cc7 -r 7bde663719dc dav/sopt.c --- a/dav/sopt.c Sun Nov 04 16:35:44 2018 +0100 +++ b/dav/sopt.c Fri Nov 09 18:03:17 2018 +0100 @@ -99,6 +99,9 @@ ucx_map_cstr_put(a->options, "restore-modified", NOARG); break; } + case 'V': { + ucx_map_cstr_put(a->options, "versioning", NOARG); + } } } } else if(option) { diff -r fdc2fb090cc7 -r 7bde663719dc dav/sync.c --- a/dav/sync.c Sun Nov 04 16:35:44 2018 +0100 +++ b/dav/sync.c Fri Nov 09 18:03:17 2018 +0100 @@ -175,8 +175,8 @@ fprintf(stderr, "Commands:\n"); fprintf(stderr, " pull [-cldr] [-t ] \n"); - fprintf(stderr, " push [-cldrRM] [-t ] \n"); - fprintf(stderr, " archive [-cldRM] [-t ] \n"); + fprintf(stderr, " push [-cldrVRM] [-t ] \n"); + fprintf(stderr, " archive [-cldVRM] [-t ] \n"); fprintf(stderr, " restore [-ld] \n"); fprintf(stderr, " resolve-conflicts \n"); fprintf(stderr, " delete-conflicts \n"); @@ -195,6 +195,7 @@ "Only sync files which have the specified tags\n"); fprintf(stderr, " -r " "Remove resources not matching the tag filter\n"); + fprintf(stderr, " -V Enable versioning\n"); fprintf(stderr, " -R Restore removed files\n"); fprintf(stderr, " -M Restore modified files\n"); fprintf(stderr, " -v Verbose output (all commands)\n\n"); @@ -989,6 +990,14 @@ if(scfg_check_dir(dir)) { return -1; } + if(cmd_getoption(a, "versioning")) { + if(dir->versioning) { + dir->versioning->always = TRUE; + } else { + fprintf(stderr, "Error: versioning not configured for the sync directory\nAbort.\n"); + return -1; + } + } int cmd = archive ? SYNC_CMD_ARCHIVE : SYNC_CMD_PUSH; if((dir->allow_cmd & cmd) != cmd) { @@ -1213,7 +1222,7 @@ if (!local->keep && !res_matches_filter(dir, local->path+1)) { if(sync_shutdown) { ucx_map_cstr_put(lclres, local->path, local_resource_copy(local)); - } else if(sync_delete_remote_resource(sn, local, &sync_delete, &cols)) { + } else if(sync_delete_remote_resource(dir, sn, local, &sync_delete, &cols)) { ucx_map_cstr_put(lclres, local->path, local_resource_copy(local)); if(sn->error != DAV_NOT_FOUND) { print_resource_error(sn, local->path); @@ -1231,7 +1240,7 @@ if (!local->keep && !res_matches_filter(dir, local->path+1)) { if(sync_shutdown) { ucx_map_cstr_put(lclres, local->path, local_resource_copy(local)); - } else if(sync_delete_remote_resource(sn, local, &sync_delete, NULL)) { + } else if(sync_delete_remote_resource(dir, sn, local, &sync_delete, NULL)) { ucx_map_cstr_put(lclres, local->path, local_resource_copy(local)); if(sn->error != DAV_NOT_FOUND) { print_resource_error(sn, local->path); @@ -2095,7 +2104,7 @@ dav_resource_free(history_collection); } else { - // Delta V is so much easier :) + // DeltaV is so much easier :) if(dav_checkout(res)) { ret = VBEGIN_ERROR_CHECKOUT; } @@ -2110,6 +2119,12 @@ } } +int versioning_delete(SyncDirectory *dir, DavResource *res) { + if(dir->versioning->type == VERSIONING_SIMPLE) { + // TODO + } +} + int sync_put_resource( SyncDirectory *dir, DavResource *res, @@ -2240,6 +2255,7 @@ } int sync_delete_remote_resource( + SyncDirectory *dir, DavSession *sn, LocalResource *local_res, int *counter, @@ -2276,7 +2292,17 @@ // local resource metadata == remote resource metadata // resource can be deleted printf("delete: %s\n", res->path); - if(dav_delete(res)) { + + if(dir->versioning && dir->versioning->always) { + if(versioning_delete(dir, res)) { + fprintf( + stderr, + "Cannot save resource version before deletion\n"); + ret = 1; + } + } + + if(!ret && dav_delete(res)) { if(sn->error != DAV_NOT_FOUND) { fprintf(stderr, "Cannot delete resource %s\n", res->path); ret = 1; diff -r fdc2fb090cc7 -r 7bde663719dc dav/sync.h --- a/dav/sync.h Sun Nov 04 16:35:44 2018 +0100 +++ b/dav/sync.h Fri Nov 09 18:03:17 2018 +0100 @@ -116,7 +116,7 @@ LocalResource *local, int *counter); int sync_mkdir(SyncDirectory *dir, DavResource *res, LocalResource *local); -int sync_delete_remote_resource(DavSession *sn, LocalResource *res, int *counter, UcxList **cols); +int sync_delete_remote_resource(SyncDirectory *dir, DavSession *sn, LocalResource *res, int *counter, UcxList **cols); int sync_update_tags(SyncDirectory *dir, DavSession *sn, DavResource *res, LocalResource *local); void remove_deleted_conflicts(SyncDirectory *dir, SyncDatabase *db);