nsxiv86dc686
Allow opening directories non-recursively
+8 −10
5 files changed
| @@ -1,4 +1,4 @@ | |||
| 1 | − | VERSION := git-20160810 | |
| 1 | + | VERSION := git-20160928 | |
| 2 | 2 | ||
| 3 | 3 | PREFIX := /usr/local | |
| 4 | 4 | MANPREFIX := $(PREFIX)/share/man | |
| @@ -818,11 +818,7 @@ int main(int argc, char **argv) | |||
| 818 | 818 | if (!S_ISDIR(fstats.st_mode)) { | |
| 819 | 819 | check_add_file(filename, true); | |
| 820 | 820 | } else { | |
| 821 | − | if (!options->recursive) { | |
| 822 | − | error(0, 0, "%s: Is a directory", filename); | |
| 823 | − | continue; | |
| 824 | − | } | |
| 825 | − | if (r_opendir(&dir, filename) < 0) { | |
| 821 | + | if (r_opendir(&dir, filename, options->recursive) < 0) { | |
| 826 | 822 | error(0, errno, "%s", filename); | |
| 827 | 823 | continue; | |
| 828 | 824 | } | |
| @@ -123,7 +123,7 @@ void tns_clean_cache(tns_t *tns) | |||
| 123 | 123 | char *cfile, *filename, *tpos; | |
| 124 | 124 | r_dir_t dir; | |
| 125 | 125 | ||
| 126 | − | if (r_opendir(&dir, cache_dir) < 0) { | |
| 126 | + | if (r_opendir(&dir, cache_dir, true) < 0) { | |
| 127 | 127 | error(0, errno, "%s", cache_dir); | |
| 128 | 128 | return; | |
| 129 | 129 | } | |
| @@ -89,7 +89,7 @@ void size_readable(float *size, const char **unit) | |||
| 89 | 89 | *unit = units[MIN(i, ARRLEN(units) - 1)]; | |
| 90 | 90 | } | |
| 91 | 91 | ||
| 92 | − | int r_opendir(r_dir_t *rdir, const char *dirname) | |
| 92 | + | int r_opendir(r_dir_t *rdir, const char *dirname, bool recursive) | |
| 93 | 93 | { | |
| 94 | 94 | if (*dirname == '\0') | |
| 95 | 95 | return -1; | |
| @@ -106,6 +106,7 @@ int r_opendir(r_dir_t *rdir, const char *dirname) | |||
| 106 | 106 | ||
| 107 | 107 | rdir->name = (char*) dirname; | |
| 108 | 108 | rdir->d = 0; | |
| 109 | + | rdir->recursive = recursive; | |
| 109 | 110 | ||
| 110 | 111 | return 0; | |
| 111 | 112 | } | |
| @@ -167,7 +168,7 @@ char* r_readdir(r_dir_t *rdir) | |||
| 167 | 168 | return filename; | |
| 168 | 169 | } | |
| 169 | 170 | ||
| 170 | − | if (rdir->stlen > 0) { | |
| 171 | + | if (rdir->recursive && rdir->stlen > 0) { | |
| 171 | 172 | /* open next subdirectory */ | |
| 172 | 173 | closedir(rdir->dir); | |
| 173 | 174 | if (rdir->d != 0) | |
| @@ -55,6 +55,7 @@ typedef struct { | |||
| 55 | 55 | DIR *dir; | |
| 56 | 56 | char *name; | |
| 57 | 57 | int d; | |
| 58 | + | bool recursive; | |
| 58 | 59 | ||
| 59 | 60 | char **stack; | |
| 60 | 61 | int stcap; | |
| @@ -71,7 +72,7 @@ void error(int, int, const char*, ...); | |||
| 71 | 72 | ||
| 72 | 73 | void size_readable(float*, const char**); | |
| 73 | 74 | ||
| 74 | − | int r_opendir(r_dir_t*, const char*); | |
| 75 | + | int r_opendir(r_dir_t*, const char*, bool); | |
| 75 | 76 | int r_closedir(r_dir_t*); | |
| 76 | 77 | char* r_readdir(r_dir_t*); | |
| 77 | 78 | int r_mkdir(char*); | |