Wed, 06 Jul 2016 12:00:18 +0200
improved dav put output
README | file | annotate | diff | comparison | revisions | |
dav/main.c | file | annotate | diff | comparison | revisions | |
dav/main.h | file | annotate | diff | comparison | revisions |
--- 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 <olaf.wintermann@gmail.com> +Authors +------- + +Olaf Wintermann +Mike Becker + License -------
--- 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 -
--- 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);