[dev] [sbase] [PATCH v2] rm: Fix exit status with -f for nonexistent paths

From: Michael Forney <mforney_AT_mforney.org>
Date: Sun, 1 Mar 2015 21:59:02 +0000

Under the description for the -f option, POSIX says, "Do not modify the
exit status in the case of nonexistent operands".
---
Whoops, just realized that simply using the errno from the remove call is way
simpler.
 libutil/rm.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
diff --git a/libutil/rm.c b/libutil/rm.c
index 53ae3f2..54987e5 100644
--- a/libutil/rm.c
+++ b/libutil/rm.c
_AT_@ -1,4 +1,5 @@
 /* See LICENSE file for copyright and license details. */
+#include <errno.h>
 #include <stdio.h>
 
 #include "../fs.h"
_AT_@ -14,8 +15,9 @@ rm(const char *path, int unused)
 	if (rm_rflag)
 		recurse(path, rm, 'P');
 	if (remove(path) < 0) {
+		if (!rm_fflag || errno != ENOENT)
+			rm_status = 1;
 		if (!rm_fflag)
 			weprintf("remove %s:", path);
-		rm_status = 1;
 	}
 }
-- 
2.1.3.1.g339ec9c
Received on Sun Mar 01 2015 - 22:59:02 CET

This archive was generated by hypermail 2.3.0 : Sun Mar 01 2015 - 23:12:07 CET