Bug 2203

Summary: diff -r on a dir with trailing / goes bad
Product: Busybox Reporter: Natanael Copa <ncopa>
Component: OtherAssignee: unassigned
Status: RESOLVED FIXED    
Severity: normal CC: busybox-cvs
Priority: P5    
Version: unspecified   
Target Milestone: ---   
Hardware: PC   
OS: Linux   
Host: Target:
Build:

Description Natanael Copa 2010-07-09 07:10:07 UTC
doing a 'diff -r dir1 dir2/' goes bad when there is a trailing / on dir.

To reproduce:

t:~/work# mkdir test
t:~/work# touch test/test1
t:~/work# touch test/test2
t:~/work# touch test/test3
t:~/work# cp -r test/ test2
t:~/work# diff -r test test2/
Only in test2/: est1
Only in test2/: est2
Only in test2/: est3
Only in test: test1
Only in test: test2
Only in test: test3

Expected reslult would be to print nothing since dirs are equal.

Originally reported on: http://redmine.alpinelinux.org/issues/381
Comment 1 Natanael Copa 2010-07-09 09:27:35 UTC
Possible fix. Might not solve the issue when one of the dirs is / (root).

diff --git a/editors/diff.c b/editors/diff.c
index 07594e8..e2da626 100644
--- a/editors/diff.c
+++ b/editors/diff.c
@@ -788,9 +788,15 @@ static void diffdir(char *p[2], const char *s_start)
 
 	memset(&list, 0, sizeof(list));
 	for (i = 0; i < 2; i++) {
+		char *lc;
 		/*list[i].s = list[i].e = 0; - memset did it */
 		/*list[i].dl = NULL; */
 
+		/* trim trailing / in dirs. */
+		lc = last_char_is(p[i], '/');
+		if (lc && lc != p[i])
+			*lc = '\0';
+
 		/* We need to trim root directory prefix.
 		 * Using list.len to specify its length,
 		 * add_to_dirlist will remove it. */
Comment 2 Denys Vlasenko 2010-07-09 17:46:42 UTC
Fixed in git, thanks!

http://git.busybox.net/busybox/commit/?id=61f5f7823c4f217dd9bad2f1df547f81b9338c76