[hackers] [sbase] Fix return values in rm(1) and mv(1) || FRIGN

From: <git_AT_suckless.org>
Date: Fri, 30 Jan 2015 12:50:58 +0100 (CET)

commit cec1a57f3e4fa1054fdf9e0ee325b68db431b5c4
Author: FRIGN <dev_AT_frign.de>
Date: Fri Jan 30 12:45:54 2015 +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).

diff --git a/fs.h b/fs.h
index 4d65766..c6535d7 100644
--- a/fs.h
+++ b/fs.h
_AT_@ -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
index 7261b6f..9aaedab 100644
--- a/libutil/rm.c
+++ b/libutil/rm.c
_AT_@ -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
index afec3b8..e021ab0 100644
--- a/mv.c
+++ b/mv.c
_AT_@ -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)
_AT_@ -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
index d6e3504..ae2f591 100644
--- a/rm.c
+++ b/rm.c
_AT_@ -41,5 +41,5 @@ main(int argc, char *argv[])
         for (; argc > 0; argc--, argv++)
                 rm(argv[0]);
 
- return 0;
+ return rm_status;
 }
Received on Fri Jan 30 2015 - 12:50:58 CET

This archive was generated by hypermail 2.3.0 : Fri Jan 30 2015 - 13:00:14 CET