[hackers] [sxiv] Allow opening directories non-recursively || Paride Legovini

From: <git_AT_suckless.org>
Date: Wed, 28 Sep 2016 19:28:42 +0200 (CEST)

commit 86dc6860f9def64ad554a7c69eeae28203661e2c
Author: Paride Legovini <pl_AT_ninthfloor.org>
AuthorDate: Wed Sep 28 18:59:15 2016 +0200
Commit: Bert M√ľnnich <ber.t_AT_posteo.de>
CommitDate: Wed Sep 28 19:27:48 2016 +0200

    Allow opening directories non-recursively

diff --git a/Makefile b/Makefile
index 576d32e..2339272 100644
--- a/Makefile
+++ b/Makefile
_AT_@ -1,4 +1,4 @@
-VERSION := git-20160810
+VERSION := git-20160928
 
 PREFIX := /usr/local
 MANPREFIX := $(PREFIX)/share/man
diff --git a/main.c b/main.c
index 5b41170..d1813a5 100644
--- a/main.c
+++ b/main.c
_AT_@ -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;
                         }
diff --git a/thumbs.c b/thumbs.c
index f51f85f..3988bd2 100644
--- a/thumbs.c
+++ b/thumbs.c
_AT_@ -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;
         }
diff --git a/util.c b/util.c
index 070101e..395a345 100644
--- a/util.c
+++ b/util.c
_AT_@ -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;
_AT_@ -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;
 }
_AT_@ -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)
diff --git a/util.h b/util.h
index 91b76d1..8918f75 100644
--- a/util.h
+++ b/util.h
_AT_@ -55,6 +55,7 @@ typedef struct {
         DIR *dir;
         char *name;
         int d;
+ bool recursive;
 
         char **stack;
         int stcap;
_AT_@ -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*);
Received on Wed Sep 28 2016 - 19:28:42 CEST

This archive was generated by hypermail 2.3.0 : Wed Sep 28 2016 - 19:36:14 CEST