From cb6b76be475c2c7764b7a059175254af734c61af Mon Sep 17 00:00:00 2001 From: Michael Mikonos <127171689+mknos@users.noreply.github.com> Date: Sat, 2 Dec 2023 22:25:01 +0800 Subject: [PATCH] diff: comparing stdin with directory * "perl diff . -" and "perl diff - ." are not valid usages because comparing stdin with a directory is no allowed * Instead of failing in open() with a confusing error, output an error consistent with GNU diff --- bin/diff | 2 ++ 1 file changed, 2 insertions(+) diff --git a/bin/diff b/bin/diff index d1c7704e..87b913cd 100755 --- a/bin/diff +++ b/bin/diff @@ -129,8 +129,10 @@ my ($fh1, $fh2); if ($file1 eq '-') { exit 0 if ($file2 eq '-'); + bag("cannot compare '-' to a directory") if (-d $file2); $fh1 = *STDIN; } elsif (-d $file1) { + bag("cannot compare '-' to a directory") if ($file2 eq '-'); bag("'$file2': is a directory") if (-d $file2); my $path = join('/', $file1, basename($file2)); open($fh1, '<', $path) or bag("Couldn't open '$path': $!");