GNU bug report logs - #76452
3.11 critical bug: diff -Naur a b does not show a unified diff when one of the file is empty

Previous Next

Package: diffutils;

Reported by: Kate Deplaix <kit-ty-kate <at> outlook.com>

Date: Fri, 21 Feb 2025 04:48:04 UTC

Severity: normal

Merged with 76453, 76454

Found in version 3.11

Done: Paul Eggert <eggert <at> cs.ucla.edu>

Bug is archived. No further changes may be made.

Full log


View this message in rfc822 format

From: Collin Funk <collin.funk1 <at> gmail.com>
To: Kate Deplaix <kit-ty-kate <at> outlook.com>, Paul Eggert <eggert <at> cs.ucla.edu>
Cc: 76452 <at> debbugs.gnu.org
Subject: bug#76452: [bug-diffutils] bug#76452: 3.11 critical bug: diff -Naur a b does not show a unified diff when one of the file is empty
Date: Thu, 20 Feb 2025 22:10:44 -0800
[Message part 1 (text/plain, inline)]
Hi Katie,

Kate Deplaix <kit-ty-kate <at> outlook.com> writes:

> With diffutils 3.10, "diff -Naur a b" returns:
>
> diff -Naur a/test b/test
> --- a/test   2025-02-20 14:50:07.870258052 +0000
> +++ b/test   2025-02-20 14:50:18.957287641 +0000
> @@ -0,0 +1 @@
> +content
>
> but with diffutils 3.11, the same command returns:
>
> File a/test is a regular empty file while file b/test is a regular file

Good catch.

CC'ing Paul Eggert since I think that I found the cause and it appears
unintentional to me.

Commit e016d12581ac4ea6be1ded88279527ceface74e1 has the following
ChangeLog:

    diff: improve symlink handling, avoiding a race
    [...]
    (compare_prepped_files): Use filetype and stat macros, not detype.
    [...]

Where filetype refers to a constant string returned by Gnulib's
c_file_type function. The relevant lines are here:

  if (S_ISREG (st->st_mode))
    return st->st_size == 0 ? N_("regular empty file") : N_("regular file");

So empty files will be treated as different file types because of that
change.

I have attached a patch to check for this condition.

Collin

[0001-diff-don-t-treat-empty-files-as-a-different-file-typ.patch (text/x-patch, attachment)]

This bug report was last modified 60 days ago.

Previous Next


GNU bug tracking system
Copyright (C) 1999 Darren O. Benham, 1997,2003 nCipher Corporation Ltd, 1994-97 Ian Jackson.