GNU bug report logs - #79676
[trollo@franken-online.de: Bug#1118586: diffutils: diff --to-file=directory no longer works as expected]

Previous Next

Package: diffutils;

Reported by: Santiago Vila <sanvila <at> debian.org>

Date: Wed, 22 Oct 2025 14:57:02 UTC

Severity: normal

To reply to this bug, email your comments to 79676 AT debbugs.gnu.org.

Toggle the display of automated, internal messages from the tracker.

View this report as an mbox folder, status mbox, maintainer mbox


Report forwarded to bug-diffutils <at> gnu.org:
bug#79676; Package diffutils. (Wed, 22 Oct 2025 14:57:02 GMT) Full text and rfc822 format available.

Acknowledgement sent to Santiago Vila <sanvila <at> debian.org>:
New bug report received and forwarded. Copy sent to bug-diffutils <at> gnu.org. (Wed, 22 Oct 2025 14:57:02 GMT) Full text and rfc822 format available.

Message #5 received at submit <at> debbugs.gnu.org (full text, mbox):

From: Santiago Vila <sanvila <at> debian.org>
To: bug-diffutils <at> gnu.org
Cc: Werner Frey <trollo <at> franken-online.de>, 1118586 <at> bugs.debian.org
Subject: [trollo <at> franken-online.de: Bug#1118586: diffutils: diff
 --to-file=directory no longer works as expected]
Date: Wed, 22 Oct 2025 16:56:38 +0200
Hello.

I received the following report from the Debian bug system.
Thanks.

----- Forwarded message from Werner Frey <trollo <at> franken-online.de> -----

Date: Wed, 22 Oct 2025 16:27:49 +0200
From: Werner Frey <trollo <at> franken-online.de>
To: Debian Bug Tracking System <submit <at> bugs.debian.org>
Subject: Bug#1118586: diffutils: diff --to-file=directory no longer works as expected

Package: diffutils
Version: 1:3.12-1
Severity: normal
Tags: upstream

Dear Maintainer,

since diffutils v3.12 the option "--to-file" no longer works as expected
if its argument is a directory.

diff --to-file=directory file1 file2 file3

should compare file1, file2, and file3 to directory/file1, directory/file2,
and directory/file3, respectively.
But it only compares file1 to directory/file1 and reports for the
remaining comparisons:

diff: directory: No such file or directory

[...]




Information forwarded to bug-diffutils <at> gnu.org:
bug#79676; Package diffutils. (Wed, 22 Oct 2025 23:53:02 GMT) Full text and rfc822 format available.

Message #8 received at 79676 <at> debbugs.gnu.org (full text, mbox):

From: Collin Funk <collin.funk1 <at> gmail.com>
To: Santiago Vila <sanvila <at> debian.org>
Cc: 79676 <at> debbugs.gnu.org, Werner Frey <trollo <at> franken-online.de>,
 1118586 <at> bugs.debian.org
Subject: Re: [bug-diffutils] bug#79676: [trollo <at> franken-online.de:
 Bug#1118586: diffutils: diff --to-file=directory no longer works as
 expected]
Date: Wed, 22 Oct 2025 16:52:36 -0700
Santiago Vila <sanvila <at> debian.org> writes:

> Hello.
>
> I received the following report from the Debian bug system.
> Thanks.
>
> ----- Forwarded message from Werner Frey <trollo <at> franken-online.de> -----
>
> Date: Wed, 22 Oct 2025 16:27:49 +0200
> From: Werner Frey <trollo <at> franken-online.de>
> To: Debian Bug Tracking System <submit <at> bugs.debian.org>
> Subject: Bug#1118586: diffutils: diff --to-file=directory no longer works as expected
>
> Package: diffutils
> Version: 1:3.12-1
> Severity: normal
> Tags: upstream
>
> Dear Maintainer,
>
> since diffutils v3.12 the option "--to-file" no longer works as expected
> if its argument is a directory.
>
> diff --to-file=directory file1 file2 file3
>
> should compare file1, file2, and file3 to directory/file1, directory/file2,
> and directory/file3, respectively.
> But it only compares file1 to directory/file1 and reports for the
> remaining comparisons:
>
> diff: directory: No such file or directory

Reminds me of bug 79407. I'll have a look at a fix and adding a test.

Here is how it behaved in some older versions vs. current:

    $ mkdir -p directory && touch file{1,2,3} directory/file{1,2,3}
    $ diff-3.5 --to-file=directory file1 file2 file3
    $ echo $?
    0
    $ diff-3.10 --to-file=directory file1 file2 file3
    $ echo $?
    0
    $ diff-current --to-file=directory file1 file2 file3
    diff-current: directory: No such file or directory
    diff-current: directory: No such file or directory
    2

Thanks,
Collin

[1] https://debbugs.gnu.org/cgi/bugreport.cgi?bug=79407




Information forwarded to bug-diffutils <at> gnu.org:
bug#79676; Package diffutils. (Thu, 23 Oct 2025 02:14:03 GMT) Full text and rfc822 format available.

Message #11 received at 79676 <at> debbugs.gnu.org (full text, mbox):

From: Collin Funk <collin.funk1 <at> gmail.com>
To: Santiago Vila <sanvila <at> debian.org>
Cc: 79676 <at> debbugs.gnu.org, Paul Eggert <eggert <at> cs.ucla.edu>,
 Werner Frey <trollo <at> franken-online.de>, 1118586 <at> bugs.debian.org
Subject: Re: [bug-diffutils] bug#79676: bug#79676:
 [trollo <at> franken-online.de: Bug#1118586: diffutils: diff
 --to-file=directory no longer works as expected]
Date: Wed, 22 Oct 2025 19:13:02 -0700
Collin Funk <collin.funk1 <at> gmail.com> writes:

> Reminds me of bug 79407. I'll have a look at a fix and adding a test.
>
> Here is how it behaved in some older versions vs. current:
>
>     $ mkdir -p directory && touch file{1,2,3} directory/file{1,2,3}
>     $ diff-3.5 --to-file=directory file1 file2 file3
>     $ echo $?
>     0
>     $ diff-3.10 --to-file=directory file1 file2 file3
>     $ echo $?
>     0
>     $ diff-current --to-file=directory file1 file2 file3
>     diff-current: directory: No such file or directory
>     diff-current: directory: No such file or directory
>     2
>
> Thanks,
> Collin
>
> [1] https://debbugs.gnu.org/cgi/bugreport.cgi?bug=79407

Hey Paul, can you take a look at this one?

I have bisected it to this commit:

commit ce65fcbeec251c952df2788a8b6c4131c46e7cea
Author:     Paul Eggert <eggert <at> cs.ucla.edu>
AuthorDate: Sun Jul 30 17:04:17 2023 -0700
Commit:     Paul Eggert <eggert <at> cs.ucla.edu>
CommitDate: Sat Aug 5 11:01:41 2023 -0700

    diff: avoid a race when opening files
    
    * src/diff.c (O_PATHSEARCH): New constant.
    (compare_files): Prefer openat+fstat to fstatat+openat,
    as it avoids a race and should be a bit faster.

Here is what I see from strace:

    $ strace diff --to-file=directory file1 file2 file3 2>&1 | grep ^openat
    [...]
    openat(AT_FDCWD, "file1", O_RDONLY|O_CLOEXEC) = 3
    openat(AT_FDCWD, "directory", O_RDONLY|O_CLOEXEC) = 4
    openat(4, "file1", O_RDONLY|O_CLOEXEC)  = 5
    openat(AT_FDCWD, "file2", O_RDONLY|O_CLOEXEC) = 3
    openat(4, "directory", O_RDONLY|O_CLOEXEC) = -1 ENOENT (No such file or directory)
    [...]
    openat(AT_FDCWD, "file3", O_RDONLY|O_CLOEXEC) = 3
    openat(4, "directory", O_RDONLY|O_CLOEXEC) = -1 ENOENT (No such file or directory)

So it looks like we set the file descriptor of NOPARENT to the file
descriptor of "directory". But we do not give openat the correct name.

The code is quite complex, so I feel like you will have an easier time
coming up with the correct fix.

Collin




Information forwarded to bug-diffutils <at> gnu.org:
bug#79676; Package diffutils. (Thu, 23 Oct 2025 02:52:02 GMT) Full text and rfc822 format available.

Message #14 received at 79676 <at> debbugs.gnu.org (full text, mbox):

From: Robert Webb <ro.webbdg <at> gmail.com>
To: Collin Funk <collin.funk1 <at> gmail.com>
Cc: Santiago Vila <sanvila <at> debian.org>, 79676 <at> debbugs.gnu.org,
 Werner Frey <trollo <at> franken-online.de>, 1118586 <at> bugs.debian.org
Subject: Re: [bug-diffutils] bug#79676: bug#79676: [trollo <at> franken-online.de:
 Bug#1118586: diffutils: diff --to-file=directory no longer works as
 expected]
Date: Wed, 22 Oct 2025 19:51:01 -0700
[Message part 1 (text/plain, inline)]
On Wed, Oct 22, 2025 at 4:53 PM Collin Funk <collin.funk1 <at> gmail.com> wrote:
> Santiago Vila <sanvila <at> debian.org> writes:
>
> > since diffutils v3.12 the option "--to-file" no longer works as expected
> > if its argument is a directory.
> >
> > diff --to-file=directory file1 file2 file3
> >
> > should compare file1, file2, and file3 to directory/file1, directory/file2,
> > and directory/file3, respectively.
> > But it only compares file1 to directory/file1 and reports for the
> > remaining comparisons:
> >
> > diff: directory: No such file or directory
>
> Reminds me of bug 79407. I'll have a look at a fix and adding a test.
>
> Here is how it behaved in some older versions vs. current:
>
>     $ mkdir -p directory && touch file{1,2,3} directory/file{1,2,3}
>     $ diff-3.5 --to-file=directory file1 file2 file3
>     $ echo $?
>     0
>     $ diff-3.10 --to-file=directory file1 file2 file3
>     $ echo $?
>     0
>     $ diff-current --to-file=directory file1 file2 file3
>     diff-current: directory: No such file or directory
>     diff-current: directory: No such file or directory
>     2

Here is a test script (attached, also):

  $ cat diff-to_file-test.sh
  #!/bin/sh

  rm -rf -- Dref Da Db Dc  || exit
  mkdir Dref
  echo uno > Dref/f1
  echo dos > Dref/f2
  echo tres > Dref/f3

  # replicate Dref
  for D in Da Db Dc  ;do
    cp -rT -- Dref "$D"
    done

  # add differences
  echo mas >> Db/f1
  echo todo >> Dc/f2

  set -- Da 'identical' Db 'first file different' Dc 'second file different'

  while [ 2 -le $# ]  ;do
    echo "=== $1: $2"
    diff --to-file=Dref -- "$1"/f1 "$1"/f2 "$1"/f3
    echo "($?)"
    shift  ;shift
    done

  echo '=== DONE'

A run with the current version:

  $ diff --version  |head -n 2
  diff (GNU diffutils) 3.12
  Packaged by openSUSE
  $ ./diff-to_file-test.sh
  === Da: identical
  diff: Dref: No such file or directory
  diff: Dref: No such file or directory
  (2)
  === Db: first file different
  2d1
  < mas
  diff: Dref: No such file or directory
  diff: Dref: No such file or directory
  (2)
  === Dc: second file different
  diff: Dref: No such file or directory
  diff: Dref: No such file or directory
  (2)
  === DONE

An older version with the expected output:

  $ diff --version  |head -n 2
  diff (GNU diffutils) 3.6
  Packaged by openSUSE
  $ ./diff-to_file-test.sh
  === Da: identical
  (0)
  === Db: first file different
  2d1
  < mas
  (1)
  === Dc: second file different
  2d1
  < todo
  (1)
  === DONE

-- 
Robert Webb
[diff-to_file-test.sh (application/x-shellscript, attachment)]

Information forwarded to bug-diffutils <at> gnu.org:
bug#79676; Package diffutils. (Fri, 24 Oct 2025 07:07:01 GMT) Full text and rfc822 format available.

Message #17 received at 79676 <at> debbugs.gnu.org (full text, mbox):

From: Paul Eggert <eggert <at> cs.ucla.edu>
To: Collin Funk <collin.funk1 <at> gmail.com>, Santiago Vila <sanvila <at> debian.org>
Cc: 79676 <at> debbugs.gnu.org, Werner Frey <trollo <at> franken-online.de>,
 1118586 <at> bugs.debian.org
Subject: Re: [bug-diffutils] bug#79676: bug#79676: [trollo <at> franken-online.de:
 Bug#1118586: diffutils: diff --to-file=directory no longer works as
 expected]
Date: Fri, 24 Oct 2025 00:06:41 -0700
On 2025-10-22 19:13, Collin Funk wrote:
> The code is quite complex, so I feel like you will have an easier time
> coming up with the correct fix.

I'll try to shake loose some time to look at this, though I'm a bit 
crunched with other stuff.




This bug report was last modified 12 days ago.

Previous Next


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