Allow opening directories non-recursively

This commit is contained in:
Paride Legovini 2016-09-28 18:59:15 +02:00 committed by Bert Münnich
parent d69f39e3aa
commit 86dc6860f9
5 changed files with 8 additions and 10 deletions

View file

@ -1,4 +1,4 @@
VERSION := git-20160810
VERSION := git-20160928
PREFIX := /usr/local
MANPREFIX := $(PREFIX)/share/man

6
main.c
View file

@ -818,11 +818,7 @@ int main(int argc, char **argv)
if (!S_ISDIR(fstats.st_mode)) {
check_add_file(filename, true);
} else {
if (!options->recursive) {
error(0, 0, "%s: Is a directory", filename);
continue;
}
if (r_opendir(&dir, filename) < 0) {
if (r_opendir(&dir, filename, options->recursive) < 0) {
error(0, errno, "%s", filename);
continue;
}

View file

@ -123,7 +123,7 @@ void tns_clean_cache(tns_t *tns)
char *cfile, *filename, *tpos;
r_dir_t dir;
if (r_opendir(&dir, cache_dir) < 0) {
if (r_opendir(&dir, cache_dir, true) < 0) {
error(0, errno, "%s", cache_dir);
return;
}

5
util.c
View file

@ -89,7 +89,7 @@ void size_readable(float *size, const char **unit)
*unit = units[MIN(i, ARRLEN(units) - 1)];
}
int r_opendir(r_dir_t *rdir, const char *dirname)
int r_opendir(r_dir_t *rdir, const char *dirname, bool recursive)
{
if (*dirname == '\0')
return -1;
@ -106,6 +106,7 @@ int r_opendir(r_dir_t *rdir, const char *dirname)
rdir->name = (char*) dirname;
rdir->d = 0;
rdir->recursive = recursive;
return 0;
}
@ -167,7 +168,7 @@ char* r_readdir(r_dir_t *rdir)
return filename;
}
if (rdir->stlen > 0) {
if (rdir->recursive && rdir->stlen > 0) {
/* open next subdirectory */
closedir(rdir->dir);
if (rdir->d != 0)

3
util.h
View file

@ -55,6 +55,7 @@ typedef struct {
DIR *dir;
char *name;
int d;
bool recursive;
char **stack;
int stcap;
@ -71,7 +72,7 @@ void error(int, int, const char*, ...);
void size_readable(float*, const char**);
int r_opendir(r_dir_t*, const char*);
int r_opendir(r_dir_t*, const char*, bool);
int r_closedir(r_dir_t*);
char* r_readdir(r_dir_t*);
int r_mkdir(char*);