dav/main.c

changeset 241
da7ace67deab
parent 236
6b4ce32d0c4e
child 252
6b8e287269fc
--- a/dav/main.c	Tue Jul 05 18:23:20 2016 +0200
+++ b/dav/main.c	Wed Jul 06 12:00:18 2016 +0200
@@ -746,16 +746,16 @@
         FILE *in = stdin;
         ret = put_file(repo, a, sn, path, "stdin", in, 0);
     } else {
-        ret = put_entry(repo, a, sn, path, file); 
+        ret = put_entry(repo, a, sn, path, file, TRUE); 
     }
     
     free(path);
     return ret;
 }
 
-int put_entry(Repository *repo, CmdArgs *a, DavSession *sn, char *path, char *file) {
+int put_entry(Repository *repo, CmdArgs *a, DavSession *sn, char *path, char *file,  DavBool root) {
     int recursive = cmd_getoption(a, "recursive") ? 1 : 0;
-    if(recursive) {
+    if(recursive && !root) {
         printf("put: %s\n", file);
     }
     struct stat s;
@@ -768,6 +768,10 @@
     int ret = 0;
     if(S_ISDIR(s.st_mode)) {
         if(!recursive) {
+            fprintf(
+                    stderr,
+                    "%s is a directory.\nUse the -R option to upload directories.",
+                    file);
             return 1;
         }
         DIR *dir = opendir(file);
@@ -775,13 +779,15 @@
             // error
         }
         struct dirent *entry;
+        int nument = 0;
         while((entry = readdir(dir)) != NULL) {
             if(!strcmp(entry->d_name, ".") || !strcmp(entry->d_name, "..")) {
                 continue;
             }
+            nument++;
             char *entry_file = util_concat_path(file, entry->d_name);
             char *entry_path = util_concat_path(path, entry->d_name);
-            int r = put_entry(repo, a, sn, entry_path, entry_file);
+            int r = put_entry(repo, a, sn, entry_path, entry_file, FALSE);
             free(entry_path);
             free(entry_file);
             if(r) {
@@ -790,6 +796,20 @@
             }
         }
         closedir(dir);
+        
+        if(nument == 0) {
+            // create empty directory
+            DavResource *res = dav_resource_new(sn, path);
+            res->iscollection = TRUE;
+            if(!dav_exists(res)) {
+                if(dav_create(res)) {
+                    fprintf(stderr, "Cannot create collection %s\n", path);
+                    print_resource_error(sn, res->path);
+                    ret = 1;
+                }
+            }
+            dav_resource_free(res);
+        }
     } else if(S_ISREG(s.st_mode)) {
         /*
          * use stdin if the input file is -

mercurial