When comparing a directory to a regular file (or vice versa),
BusyBox diff incorrectly returns exit code 1 (files differ)
instead of 2 (error). This breaks scripts that rely on the
standard diff exit codes.

GNU diff returns 2 for this case, as it's an invalid comparison.

Signed-off-by: Giorgi Tchankvetadze <[email protected]>
---
 editors/diff.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/editors/diff.c b/editors/diff.c
index 6f4ed9712..d1798a65b 100644
--- a/editors/diff.c
+++ b/editors/diff.c
@@ -1040,6 +1040,7 @@ int diff_main(int argc UNUSED_PARAM, char **argv)
                bb_simple_error_msg_and_die("no support for directory 
comparison");
 #endif
        } else {
+               if (S_ISDIR(stb[0].st_mode) != S_ISDIR(stb[1].st_mode)) return 
2;
                bool dirfile = S_ISDIR(stb[0].st_mode) || 
S_ISDIR(stb[1].st_mode);
                bool dir = S_ISDIR(stb[1].st_mode);
                if (dirfile) {
-- 
2.47.3

_______________________________________________
busybox mailing list
[email protected]
https://lists.busybox.net/mailman/listinfo/busybox

Reply via email to