On Wed, Jul 26, 2017 at 11:06:02PM -0400, Ted Unangst wrote:
> Ibrahim Khalifa wrote:
> > Hi,
> >
> > If you run diff against two directories where you have file(s) and the
> > only difference is that you have file(s) that only exists in one of the
> > directories, diff will exit with 0. If you use -N och -P it will however
> > exit with 1.
> >
> > Reading through the man-page, I can???t find any reference that this would
> > be intentionally. Rather I expected it to exit with 1, since there is a
> > difference found. The only other diff I have access to is GNU diff, which
> > seems to exit with 1 in the same scenario.
> >
> > If the behavior is intentionally, I think the man-page should also reflect
> > this. Otherwise diff should be changed to exit with 1 even if -N or -P
> > isn't used.
> >
> > Both changes are trivial and I can provide a patch if there is some
> > consensus on which behavior is the best.
>
> it's probably an oversight. the exit code should be 1.
Great. The attached patch changes the exit code to 1.
//Ibo
? diff-direxit.patch
Index: diffdir.c
===================================================================
RCS file: /cvs/src/usr.bin/diff/diffdir.c,v
retrieving revision 1.45
diff -u -p -r1.45 diffdir.c
--- diffdir.c 5 Oct 2015 20:15:00 -0000 1.45
+++ diffdir.c 27 Jul 2017 09:00:48 -0000
@@ -132,16 +132,20 @@ diffdir(char *p1, char *p2, int flags)
if (Nflag)
diffit(dent1, path1, dirlen1, path2, dirlen2,
flags);
- else
+ else {
print_only(path1, dirlen1, dent1->d_name);
+ status |= 1;
+ }
dp1++;
} else {
/* file only in second dir, only diff if -N or -P */
if (Nflag || Pflag)
diffit(dent2, path1, dirlen1, path2, dirlen2,
flags);
- else
+ else {
print_only(path2, dirlen2, dent2->d_name);
+ status |= 1;
+ }
dp2++;
}
}