dav/config.c

changeset 319
2433b5969d44
parent 317
7eea57f6d847
child 321
eb8885a87866
--- a/dav/config.c	Sun Oct 01 17:37:59 2017 +0200
+++ b/dav/config.c	Tue Oct 03 14:59:35 2017 +0200
@@ -99,9 +99,6 @@
     // TODO: free the config somewhere
     repos = ucx_map_new(16);
     keys = ucx_map_new(16);
-    if(check_config_dir()) {
-        return 1;
-    }
     
     char *file = util_concat_path(ENV_HOME, ".dav/config.xml");
     
@@ -109,7 +106,6 @@
     if(stat(file, &s)) {
         switch(errno) {
             case ENOENT: {
-                create_default_config(file);
                 return 0;
             }
             default: {
@@ -589,7 +585,27 @@
 }
 
 int add_repository(Repository *repo) {
+    if(check_config_dir()) {
+        fprintf(stderr, "Cannot create .dav directory\n");
+        return 1;
+    }
+    
     char *file = util_concat_path(ENV_HOME, ".dav/config.xml");
+    struct stat s;
+    if(stat(file, &s)) {
+        switch(errno) {
+            case ENOENT: {
+                create_default_config(file);
+                break;
+            }
+            default: {
+                perror("Cannot load config.xml");
+                free(file);
+                return 1;
+            }
+        }
+    }
+    
     xmlDoc *doc = xmlReadFile(file, NULL, 0);
     if(!doc) {
         free(file);

mercurial