From owner-freebsd-bugs@FreeBSD.ORG Wed Jun 20 19:40:15 2012 Return-Path: Delivered-To: freebsd-bugs@hub.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 7CCBB106564A for ; Wed, 20 Jun 2012 19:40:15 +0000 (UTC) (envelope-from gnats@FreeBSD.org) Received: from freefall.freebsd.org (freefall.freebsd.org [IPv6:2001:4f8:fff6::28]) by mx1.freebsd.org (Postfix) with ESMTP id 67EA88FC08 for ; Wed, 20 Jun 2012 19:40:15 +0000 (UTC) Received: from freefall.freebsd.org (localhost [127.0.0.1]) by freefall.freebsd.org (8.14.5/8.14.5) with ESMTP id q5KJeFjq010501 for ; Wed, 20 Jun 2012 19:40:15 GMT (envelope-from gnats@freefall.freebsd.org) Received: (from gnats@localhost) by freefall.freebsd.org (8.14.5/8.14.5/Submit) id q5KJeFDD010500; Wed, 20 Jun 2012 19:40:15 GMT (envelope-from gnats) Date: Wed, 20 Jun 2012 19:40:15 GMT Message-Id: <201206201940.q5KJeFDD010500@freefall.freebsd.org> To: freebsd-bugs@FreeBSD.org From: Garrett Cooper Cc: Subject: Re: bin/169274: [patch] diff exit code always reports "trouble" when there are differences between 2 files X-BeenThere: freebsd-bugs@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list Reply-To: Garrett Cooper List-Id: Bug reports List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 20 Jun 2012 19:40:15 -0000 The following reply was made to PR bin/169274; it has been noted by GNATS. From: Garrett Cooper To: Xin LI Cc: freebsd-gnats-submit@freebsd.org Subject: Re: bin/169274: [patch] diff exit code always reports "trouble" when there are differences between 2 files Date: Wed, 20 Jun 2012 12:34:27 -0700 On Wed, Jun 20, 2012 at 12:13 PM, Xin LI wrote: >> $ diff valid.output unittest.dip >/dev/null >> $ echo $? >> 2 > > I tried a few possible permutations and got expected result (when file > is not accessible I got 2, and otherwise 1), except the case that one > file is binary. =A0It's not clear to me whether this is a bug or a > feature, as our diff(1) does not have a RETURN VALUE section. This is what I was referring to: FILES are `FILE1 FILE2' or `DIR1 DIR2' or `DIR FILE...' or `FILE= ... DIR'. If --from-file or --to-file is given, there are no restricti= ons on FILES. If a FILE is `-', read standard input. Exit status is 0= if inputs are the same, 1 if different, 2 if trouble. The definition of "trouble" here is unnecessarily ambiguous. I interpret trouble to be: 1. open failure. 2. stat failure. 3. read failure. etc. Comparing a binary file and text file does not constitute "trouble" -- they're just different. It concerns me because there's a fine line -- in some cases -- between binary and text files, depending on the content in the file (I'm thinking of .shar files for instance or uuencoded scripts). > With your proposed change, diff no longer distinguishes "trouble outputti= ng > the diff because at least one file is binary and you don't know it" > and "I know it's binary (--brief) or I know what I am doing (--text), > just let me know if there is difference", which sounds like a > regression IMHO. Ok. That was the difference (binary vs text): $ file valid.output unittest.dip valid.output: ASCII text unittest.dip: data Where is that requirement mentioned in the manpage though? I can't find it in the GNU diffutils manpage. If this is a BSD diff requirement, then it's doing something clearly different from GNU diff implementation. Whether or not the BSD implementation has to conform is another thing entirely, but it would be nice to keep the inconsistencies down to a minimum if at all possible. >> The patch attached fixes this logic error and another inconsistency with= "magic numbers": > > As a rule, cosmetic changes like change in the second one should never > be applied on contributed code unless they are really broken. Ok. > If for a BSD licensed diff maintained by ourselves this would be a > desirable change. ... > This is expected. =A0What's wrong here? Nothing was wrong with that case; just trying to prove that my change worked as expected (sorry for the accidental ambiguity). >>>How-To-Repeat: >> diff /usr/src/contrib/diff/src/diff.c =A0/usr/src/contrib/diff/src/diff.= h >/dev/null >> ec=3D$? >> if [ $ec -eq 1 ] >> then >> =A0 =A0echo PASS >> else >> =A0 =A0echo FAIL >> fi > > I got "PASS" here... Yeah, I see where I got confused given the info above. Still -- I don't see why comparing a binary stream and a text stream should be considered "trouble" (esp. when "trouble" isn't well defined) as they're both just streams of 0s and 1s and all I care about is whether or not they were the same. Thanks! -Garrett