[hackers] [sbase] Add SILENT flag to recurse() || FRIGN

From: <git_AT_suckless.org>
Date: Mon, 20 Apr 2015 12:12:46 +0200 (CEST)

commit f83d7bc647a99405e919ba27416a56d8b2d0617a
Author: FRIGN <dev_AT_frign.de>
Date: Sun Apr 19 14:00:47 2015 +0200

    Add SILENT flag to recurse()
    
    recurse() is getting smarter every day. I expect it to pass the Turing
    test in a few months.
    Along the way, it was reported that "rm -f" on nonexistant files reports
    their missing as an internal recurse()-error.
    So recurse() knows when to shut up, I added the SILENT flag to fix all
    these things.

diff --git a/fs.h b/fs.h
index 35b5cf8..15ae5f4 100644
--- a/fs.h
+++ b/fs.h
_AT_@ -20,6 +20,7 @@ struct recursor {
 enum {
         SAMEDEV = 1 << 0,
         DIRFIRST = 1 << 1,
+ SILENT = 1 << 2,
 };
 
 extern int cp_aflag;
diff --git a/libutil/recurse.c b/libutil/recurse.c
index de794f2..e2b8a6e 100644
--- a/libutil/recurse.c
+++ b/libutil/recurse.c
_AT_@ -33,8 +33,10 @@ recurse(const char *path, void *data, struct recursor *r)
         }
 
         if (statf(path, &st) < 0) {
- weprintf("%s %s:", statf_name, path);
- recurse_status = 1;
+ if (!(r->flags & SILENT)) {
+ weprintf("%s %s:", statf_name, path);
+ recurse_status = 1;
+ }
                 return;
         }
         if (!S_ISDIR(st.st_mode)) {
_AT_@ -53,8 +55,10 @@ recurse(const char *path, void *data, struct recursor *r)
                         return;
 
         if (!(dp = opendir(path))) {
- weprintf("opendir %s:", path);
- recurse_status = 1;
+ if (!(r->flags & SILENT)) {
+ weprintf("opendir %s:", path);
+ recurse_status = 1;
+ }
                 return;
         }
 
_AT_@ -74,8 +78,10 @@ recurse(const char *path, void *data, struct recursor *r)
                                 estrlcat(subpath, "/", sizeof(subpath));
                         estrlcat(subpath, d->d_name, sizeof(subpath));
                         if (statf(subpath, &dst) < 0) {
- weprintf("%s %s:", statf_name, subpath);
- recurse_status = 1;
+ if (!(r->flags & SILENT)) {
+ weprintf("%s %s:", statf_name, subpath);
+ recurse_status = 1;
+ }
                         } else if ((r->flags & SAMEDEV) && dst.st_dev != st.st_dev) {
                                 continue;
                         } else {
diff --git a/libutil/rm.c b/libutil/rm.c
index 03bbafe..f6a54b6 100644
--- a/libutil/rm.c
+++ b/libutil/rm.c
_AT_@ -8,7 +8,6 @@
 #include "../fs.h"
 #include "../util.h"
 
-int rm_fflag = 0;
 int rm_status = 0;
 
 void
_AT_@ -18,15 +17,15 @@ rm(const char *path, struct stat *st, void *data, struct recursor *r)
                 recurse(path, NULL, r);
 
                 if (rmdir(path) < 0) {
- if (!rm_fflag)
+ if (!(r->flags & SILENT))
                                 weprintf("rmdir %s:", path);
- if (!(rm_fflag && errno == ENOENT))
+ if (!((r->flags & SILENT) && errno == ENOENT))
                                 rm_status = 1;
                 }
         } else if (unlink(path) < 0) {
- if (!rm_fflag)
+ if (!(r->flags & SILENT))
                         weprintf("unlink %s:", path);
- if (!(rm_fflag && errno == ENOENT))
+ if (!((r->flags & SILENT) && errno == ENOENT))
                         rm_status = 1;
         }
 }
diff --git a/rm.c b/rm.c
index 139c020..9a63f8a 100644
--- a/rm.c
+++ b/rm.c
_AT_@ -16,7 +16,7 @@ main(int argc, char *argv[])
 
         ARGBEGIN {
         case 'f':
- rm_fflag = 1;
+ r.flags |= SILENT;
                 break;
         case 'R':
         case 'r':
_AT_@ -27,7 +27,7 @@ main(int argc, char *argv[])
         } ARGEND;
 
         if (!argc) {
- if (!rm_fflag)
+ if (!(r.flags & SILENT))
                         usage();
                 else
                         return 0;
Received on Mon Apr 20 2015 - 12:12:46 CEST

This archive was generated by hypermail 2.3.0 : Mon Apr 20 2015 - 12:24:12 CEST