[hackers] [sbase][PATCH] cp: don't abort when src and dest file are the same

From: Arthur Williams <taaparthur_AT_disroot.org>
Date: Sun, 6 Mar 2022 04:14:01 -0800

The POSIX spec gives many options on how to handle this case, but it
also states that cp (and mv) should continue with remaining operands
regardless. We used to exit immediately, which violates the spec.

This change makes cp/mv not exit immediately in this case and
also won't cause the return value to be non-zero.

From `man 1p cp`:
   If source_file references the same file as dest_file, cp may write
   a diagnostic message to standard error; it shall do nothing more
   with source_file and shall go on to any remaining files.
---
 libutil/fnck.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/libutil/fnck.c b/libutil/fnck.c
index 92da1f4..4f8875b 100644
--- a/libutil/fnck.c
+++ b/libutil/fnck.c
_AT_@ -13,7 +13,8 @@ fnck(const char *a, const char *b,
 	    && !stat(b, &stb)
 	    && sta.st_dev == stb.st_dev
 	    && sta.st_ino == stb.st_ino) {
-		eprintf("%s -> %s: same file\n", a, b);
+		weprintf("%s -> %s: same file\n", a, b);
+		return;
 	}
 
 	if (fn(a, b, depth) < 0)
-- 
2.34.1
Received on Sun Mar 06 2022 - 13:14:01 CET

This archive was generated by hypermail 2.3.0 : Sun Mar 06 2022 - 13:24:36 CET