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

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

Under the description for the -f option, POSIX says, "Do not modify the
exit status in the case of nonexistent operands".
---
 libutil/rm.c | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)
diff --git a/libutil/rm.c b/libutil/rm.c
index 53ae3f2..30a1b41 100644
--- a/libutil/rm.c
+++ b/libutil/rm.c
_AT_@ -1,5 +1,7 @@
 /* See LICENSE file for copyright and license details. */
+#include <errno.h>
 #include <stdio.h>
+#include <sys/stat.h>
 
 #include "../fs.h"
 #include "../util.h"
_AT_@ -11,11 +13,14 @@ int rm_status = 0;
 void
 rm(const char *path, int unused)
 {
+	struct stat st;
+
 	if (rm_rflag)
 		recurse(path, rm, 'P');
 	if (remove(path) < 0) {
 		if (!rm_fflag)
 			weprintf("remove %s:", path);
-		rm_status = 1;
+		if (!rm_fflag || stat(path, &st) < 0 && errno != ENOENT)
+			rm_status = 1;
 	}
 }
-- 
2.1.3.1.g339ec9c
Received on Sun Mar 01 2015 - 22:48:36 CET

This archive was generated by hypermail 2.3.0 : Sun Mar 01 2015 - 23:00:08 CET