# HG changeset patch # User Olaf Wintermann # Date 1467799218 -7200 # Node ID da7ace67deab61fdf964e18bf2c03c77172da6eb # Parent 220ea6247077c89a71be8259b4d6434083f55734 improved dav put output diff -r 220ea6247077 -r da7ace67deab README --- a/README Tue Jul 05 18:23:20 2016 +0200 +++ b/README Wed Jul 06 12:00:18 2016 +0200 @@ -58,6 +58,12 @@ Olaf Wintermann +Authors +------- + +Olaf Wintermann +Mike Becker + License ------- diff -r 220ea6247077 -r da7ace67deab dav/main.c --- 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 - diff -r 220ea6247077 -r da7ace67deab dav/main.h --- a/dav/main.h Tue Jul 05 18:23:20 2016 +0200 +++ b/dav/main.h Wed Jul 06 12:00:18 2016 +0200 @@ -51,7 +51,7 @@ int get_resource(Repository *repo, DavResource *res, CmdArgs *a, char *out); int cmd_put(CmdArgs *args); -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 put_file(Repository *repo, CmdArgs *a, DavSession *sn, char *path, char *name, FILE *in, off_t len); int cmd_remove(CmdArgs *args);