adds list-versions command

Tue, 19 Mar 2019 20:31:17 +0100

author
Olaf Wintermann <olaf.wintermann@gmail.com>
date
Tue, 19 Mar 2019 20:31:17 +0100
changeset 529
dc3f82b04733
parent 528
4c9c8c017d52
child 530
29e660161b73

adds list-versions command

dav/sync.c file | annotate | diff | comparison | revisions
dav/sync.h file | annotate | diff | comparison | revisions
--- a/dav/sync.c	Tue Mar 19 19:24:25 2019 +0100
+++ b/dav/sync.c	Tue Mar 19 20:31:17 2019 +0100
@@ -148,6 +148,8 @@
             ret = cmd_resolve_conflicts(args);
         } else if(!strcmp(cmd, "delete-conflicts")) {
             ret = cmd_delete_conflicts(args);
+        } else if(!strcmp(cmd, "list-versions")) {
+            ret = cmd_list_versions(args);
         } else if(!strcmp(cmd, "trash-info")) {
             ret = cmd_trash_info(args);
         } else if(!strcmp(cmd, "empty-trash")) {
@@ -194,7 +196,7 @@
     fprintf(stderr, "        pull [-cldr] [-t <tags>] <directory>\n");
     fprintf(stderr, "        push [-cldrVRM] [-t <tags>] <directory>\n");
     fprintf(stderr, "        archive [-cldVRM] [-t <tags>] <directory>\n");
-    fprintf(stderr, "        restore [-ld] [-s <directory>] [file...]\n");
+    fprintf(stderr, "        restore [-ldRM] [-s <directory>] [file...]\n");
     fprintf(stderr, "        resolve-conflicts <directory>\n");
     fprintf(stderr, "        delete-conflicts <directory>\n");
     fprintf(stderr, "        trash-info <directory>\n");
@@ -3031,6 +3033,98 @@
     return str;
 }
 
+int cmd_list_versions(CmdArgs *a) {
+    if(a->argc != 1) {
+        fprintf(stderr, "Too %s arguments\n", a->argc < 1 ? "few" : "many");
+        return -1;
+    }
+    
+    SyncFile file;
+    int ret = 0;
+    char *path = a->argv[0];
+    
+    int err = sync_get_file(a, path, &file, TRUE);
+    if(err) {
+        sync_print_get_file_err(path, err);
+        return 1;
+    }
+    SyncDirectory *dir = file.dir;
+    
+    if(!dir->versioning) {
+        fprintf(stderr, "No versioning configured for syncdir %s\n", dir->name);
+    }
+    
+    Repository *repo = get_repository(sstr(dir->repository));
+    if(!repo) {
+        fprintf(stderr, "Unknown repository %s\n", dir->repository);
+        return -1;
+    }
+    
+    SyncDatabase *db = load_db(dir->database);
+    if(!db) {
+        fprintf(stderr, "Cannot load database file: %s\n", dir->database);
+        return -1;
+    }
+    remove_deleted_conflicts(dir, db);
+    
+    DavSession *sn = create_session(ctx, repo, dir->collection);
+    ucx_mempool_reg_destr(sn->mp, db, (ucx_destructor)destroy_db);
+    if (cmd_getoption(a, "verbose")) {
+        curl_easy_setopt(sn->handle, CURLOPT_VERBOSE, 1L);
+        curl_easy_setopt(sn->handle, CURLOPT_STDERR, stderr);
+    }
+    
+    DavResource *res = dav_resource_new(sn, file.path);
+    if(dir->versioning->type == VERSIONING_SIMPLE) {
+        do {
+            DavPropName p;
+            p.ns = DAV_NS;
+            p.name = VERSION_PATH_PROPERTY;
+            if(dav_load_prop(res, &p, 1)) {
+                print_resource_error(sn, file.path);
+                ret = 1;
+                break;
+            }
+            char *vcol_href = dav_get_string_property_ns(res, DAV_NS, VERSION_PATH_PROPERTY); 
+            if(!vcol_href) {
+                ret = 1;
+                break;
+            }
+            
+            DavResource *vcol = dav_resource_new_href(sn, vcol_href);
+            if(!vcol) {
+                ret = 1;
+                break;
+            }
+            
+            if(dav_load_prop(vcol, NULL, 0)) {
+                print_resource_error(sn, vcol->path);
+                ret = 1;
+                break;
+            }
+            
+            DavResource *child = vcol->children;
+            while(child) {
+                time_t now = child->lastmodified;
+                struct tm *date = gmtime(&now);
+                char str[32];
+                putenv("LC_TIME=C");
+                size_t len = strftime(str, 32, "%a, %d %b %Y %H:%M:%S GMT", date);
+                
+                printf("%s%32s\n", str, child->name);
+                
+                child = child->next;
+            }
+        } while(0);
+    }
+    
+    free(file.path);
+    dav_session_destroy(sn);
+    
+    return ret;
+}
+
+
 int cmd_trash_info(CmdArgs *a) {
     if(a->argc != 1) {
         fprintf(stderr, "Too %s arguments\n", a->argc < 1 ? "few" : "many");
--- a/dav/sync.h	Tue Mar 19 19:24:25 2019 +0100
+++ b/dav/sync.h	Tue Mar 19 20:31:17 2019 +0100
@@ -163,6 +163,8 @@
 int cmd_resolve_conflicts(CmdArgs *args);
 int cmd_delete_conflicts(CmdArgs *args);
 
+int cmd_list_versions(CmdArgs *args);
+
 int cmd_trash_info(CmdArgs *args);
 int cmd_empty_trash(CmdArgs *args);
 

mercurial