dav-sync add-directory shows list of repositories

Thu, 17 Mar 2016 15:06:26 +0100

author
Olaf Wintermann <olaf.wintermann@gmail.com>
date
Thu, 17 Mar 2016 15:06:26 +0100
changeset 215
781aee172901
parent 214
7961460e0d9e
child 216
16d6b97fbf33

dav-sync add-directory shows list of repositories

dav/config.c file | annotate | diff | comparison | revisions
dav/config.h file | annotate | diff | comparison | revisions
dav/db.c file | annotate | diff | comparison | revisions
dav/sync.c file | annotate | diff | comparison | revisions
--- a/dav/config.c	Wed Mar 16 14:39:59 2016 +0100
+++ b/dav/config.c	Thu Mar 17 15:06:26 2016 +0100
@@ -51,7 +51,7 @@
 static Proxy  *http_proxy;
 static Proxy  *https_proxy;
 
-int check_config_dir() {
+int check_config_dir(void) {
     char *file = util_concat_path(ENV_HOME, ".dav");
     int ret = 0;
     if(util_mkdir(file, S_IRWXU)) {
@@ -127,7 +127,7 @@
     xmlFreeDoc(doc);
 }
 
-void free_config() {
+void free_config(void) {
     UcxMapIterator i = ucx_map_iterator(repos);
     UcxKey k;
     Repository *repo;
@@ -154,7 +154,7 @@
     ucx_map_free(keys);
 }
 
-Repository* repository_new() {
+Repository* repository_new(void) {
     Repository *repo = calloc(1, sizeof(Repository));
     repo->encrypt_name = false;
     repo->encrypt_content = false;
@@ -477,11 +477,11 @@
     return ucx_map_cstr_get(keys, name);
 }
 
-Proxy* get_http_proxy() {
+Proxy* get_http_proxy(void) {
     return http_proxy;
 }
 
-Proxy* get_https_proxy() {
+Proxy* get_https_proxy(void) {
     return https_proxy;
 }
 
@@ -541,3 +541,13 @@
     }
     return 0;
 }
+
+UcxList* get_repositories(void) {
+    UcxList *list = NULL;
+    UcxMapIterator i = ucx_map_iterator(repos);
+    Repository *repo;
+    UCX_MAP_FOREACH(key, repo, i) {
+        list = ucx_list_append(list, repo);
+    }
+    return list;
+}
--- a/dav/config.h	Wed Mar 16 14:39:59 2016 +0100
+++ b/dav/config.h	Thu Mar 17 15:06:26 2016 +0100
@@ -76,24 +76,25 @@
 };
     
 void load_config(DavContext *ctx);
-void free_config();
+void free_config(void);
 void load_repository(xmlNode *reponode);
 void load_key(xmlNode *keynode);
 void load_proxy(xmlNode *proxynode, int type);
 sstr_t load_key_file(char *filename);
 
-Repository* repository_new();
+Repository* repository_new(void);
 
 Repository* get_repository(sstr_t name);
 int repo_add_config(Repository *repo, char *key, char *value);
 int get_repository_flags(Repository *repo);
 DavSession *repository_session(Repository *repo);
 Key* get_key(char *name);
-Proxy* get_http_proxy();
-Proxy* get_https_proxy();
+Proxy* get_http_proxy(void);
+Proxy* get_https_proxy(void);
 
 int add_repository(Repository *repo);
-int list_repositories();
+int list_repositories(void);
+UcxList* get_repositories(void);
 
 #ifdef	__cplusplus
 }
--- a/dav/db.c	Wed Mar 16 14:39:59 2016 +0100
+++ b/dav/db.c	Thu Mar 17 15:06:26 2016 +0100
@@ -145,7 +145,7 @@
                     if(endptr == (char*)value) {
                         fprintf(
                             stderr,
-                            "lastmodified contains not a number: %s\n", value);
+                            "lastmodified does not contain a number: %s\n", value);
                     } else {
                         res->last_modified = t;
                     }
--- a/dav/sync.c	Wed Mar 16 14:39:59 2016 +0100
+++ b/dav/sync.c	Thu Mar 17 15:06:26 2016 +0100
@@ -257,7 +257,7 @@
             }
             
             // add every resource from the server to svrres
-            // then db-resources only contains resources which are not on the
+            // then db-resources contains only resources which are not on the
             // server
             LocalResource *local = ucx_map_cstr_get(db->resources, res->path);
             ucx_map_cstr_put(svrres, res->path, local);
@@ -1233,15 +1233,41 @@
         return -1;
     }
     
-    printf("Enter webdav repository name.\n");
+    printf("Specify webdav repository.\n");
+    UcxList *repos = get_repositories();
+    int i = 0;
+    UCX_FOREACH(elm, repos) {
+        Repository *r = elm->data;
+        printf("%d) %s\n", i, r->name);
+        i++;
+    }
     char *repository = assistant_getcfg("repository");
+    char *reponame = NULL;
     if(!repository) {
         fprintf(stderr, "Abort\n");
         return -1;
     }
-    if(!get_repository(sstr(repository))) {
-        fprintf(stderr, "Repository %s doesn't exist.\nAbort\n", repository);
-        return -1;
+    int64_t reponum = 0;
+    if(util_strtoint(repository, &reponum)) {
+        if(reponum < 0) {
+            fprintf(stderr, "Wrong input.\nAbort\n");
+            return -1;
+        }
+        UcxList *elm = ucx_list_get(repos, reponum);
+        if(elm) {
+            Repository *r = elm->data;
+            reponame = r->name;
+        } else {
+            fprintf(stderr, "Wrong input.\nAbort\n");
+            return -1;
+        }
+    } else {
+        if(get_repository(sstr(repository))) {
+            reponame = repository;
+        } else {
+            fprintf(stderr, "Repository %s doesn't exist.\nAbort\n", repository);
+            return -1;
+        }
     }
     
     printf("Enter collection relative to the repository base url.\n");
@@ -1253,7 +1279,7 @@
     memset(&dir, 0, sizeof(SyncDirectory));
     dir.name = name;
     dir.path = path;
-    dir.repository = repository;
+    dir.repository = reponame;
     dir.collection = collection;
     dir.trash = ".trash";
     dir.database = db;

mercurial