sbase

suckless unix tools
git clone git://git.2f30.org/sbase
Log | Files | Refs | README | LICENSE

commit e60885699c9d839455331196963b9238d0d962cb
parent a9c7d16cde03812aebecc990d50b3864f2ac787a
Author: FRIGN <dev@frign.de>
Date:   Fri, 30 Jan 2015 12:45:54 +0100

Fix return values in rm(1) and mv(1)

by setting rm_status to 1 if removing 1 file in the list fails.
Extend this to mv_status in mv(1).

Diffstat:
Mfs.h | 1+
Mlibutil/rm.c | 8++++++--
Mmv.c | 35++++++++++++++++++-----------------
Mrm.c | 2+-
4 files changed, 26 insertions(+), 20 deletions(-)

diff --git a/fs.h b/fs.h @@ -9,6 +9,7 @@ extern int cp_status; extern int rm_fflag; extern int rm_rflag; +extern int rm_status; int cp(const char *, const char *); void rm(const char *); diff --git a/libutil/rm.c b/libutil/rm.c @@ -6,12 +6,16 @@ int rm_fflag = 0; int rm_rflag = 0; +int rm_status = 0; void rm(const char *path) { if (rm_rflag) recurse(path, rm); - if (remove(path) < 0 && !rm_fflag) - eprintf("remove %s:", path); + if (remove(path) < 0) { + if (!rm_fflag) + weprintf("remove %s:", path); + rm_status = 1; + } } diff --git a/mv.c b/mv.c @@ -8,7 +8,23 @@ #include "fs.h" #include "util.h" -static int mv(const char *, const char *); +int mv_status = 0; + +static int +mv(const char *s1, const char *s2) +{ + if (rename(s1, s2) == 0) + return (mv_status = 0); + if (errno == EXDEV) { + cp_rflag = 1; + rm_rflag = 1; + cp(s1, s2); + rm(s1); + return (mv_status = cp_status || rm_status); + } + mv_status = 1; + return -1; +} static void usage(void) @@ -36,20 +52,5 @@ main(int argc, char *argv[]) eprintf("%s: not a directory\n", argv[argc-1]); enmasse(argc, &argv[0], mv); - return 0; -} - -static int -mv(const char *s1, const char *s2) -{ - if (rename(s1, s2) == 0) - return 0; - if (errno == EXDEV) { - cp_rflag = 1; - rm_rflag = 1; - cp(s1, s2); - rm(s1); - return 0; - } - return -1; + return mv_status; } diff --git a/rm.c b/rm.c @@ -41,5 +41,5 @@ main(int argc, char *argv[]) for (; argc > 0; argc--, argv++) rm(argv[0]); - return 0; + return rm_status; }