dav/scfg.c

changeset 65
d4077e8175f3
parent 58
1708cba82ca3
child 66
f8c1f685e08e
--- a/dav/scfg.c	Sat Nov 08 20:27:10 2014 +0100
+++ b/dav/scfg.c	Sun Nov 09 11:30:24 2014 +0100
@@ -29,6 +29,7 @@
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
+#include <errno.h>
 #include <libidav/utils.h>
 #include <ucx/map.h>
 
@@ -88,6 +89,7 @@
 int scfg_load_directory(xmlNode *node) {
     char *name = NULL;
     char *path = NULL;
+    char *trash = NULL;
     char *collection = NULL;
     char *repository = NULL;
     char *database = NULL;
@@ -104,6 +106,8 @@
                 name = value;
             } else if(xstreq(node->name, "path")) {
                 path = value;
+            } else if(xstreq(node->name, "trash")) {
+                trash = value;
             } else if(xstreq(node->name, "collection")) {
                 collection = value;
             } else if(xstreq(node->name, "repository")) {
@@ -156,6 +160,23 @@
         regcomp(matchnothing, "///", REG_NOSUB);
         dir->exclude = ucx_list_append(NULL, matchnothing);
     }
+    if (trash) {
+        if (trash[0] == '/') {
+            dir->trash = strdup(trash);
+        } else {
+            char *t = util_concat_path(path, trash);
+            dir->trash = util_concat_path(t, "/");
+            free(t);
+        }
+        
+        // create trash directory
+        mode_t mode = S_IRWXU | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH;
+        if (util_mkdir(dir->trash, mode)) {
+            if (errno != EEXIST) {
+                fprintf(stderr, "Cannot create trash directory.\n");
+            }
+        }
+    }
     
     ucx_map_cstr_put(directories, name, dir);
     
@@ -172,6 +193,8 @@
         "    <name>documents</name>\n\n"
         "    <!-- local path to the directory -->\n"
         "    <path>/home/user/Documents</path>\n\n"
+        "    <!-- optional trash path -->\n"
+        "    <trash>.trash</trash>"
         "    <!-- repository name specified in config.xml -->\n"
         "    <repository>server</repository>\n\n"
         "    <!-- collection to synchronize (optional) -->\n"

mercurial