refresh patch for 'cmp -s'

This commit is contained in:
Than Ngo 2024-07-30 10:39:36 +02:00
commit efeeb64f37
3 changed files with 66 additions and 37 deletions

View file

@ -1,27 +0,0 @@
From cb52fa88d5f2d9bc4894a7eccd90fdc2e03f5af4 Mon Sep 17 00:00:00 2001
From: Bruno Haible <bruno@clisp.org>
Date: Tue, 4 Jul 2023 18:45:33 +0200
Subject: [PATCH] diff: Fix output of "diff -l -y" for non-ASCII input files
* src/side.c (print_half_line): Output the multibyte character to out,
not stdout.
---
src/side.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/src/side.c b/src/side.c
index 2f566f8..46ef095 100644
--- a/src/side.c
+++ b/src/side.c
@@ -146,7 +146,7 @@ print_half_line (char const *const *line, intmax_t indent, intmax_t out_bound)
if (in_position <= out_bound)
{
out_position = in_position;
- fwrite (tp0, 1, bytes, stdout);
+ fwrite (tp0, 1, bytes, out);
}
text_pointer = tp0 + bytes;
break;
--
2.34.1

View file

@ -1,11 +1,42 @@
diff -up diffutils-3.10/src/cmp.c.orig diffutils-3.10/src/cmp.c
--- diffutils-3.10/src/cmp.c.orig 2024-07-23 12:27:16.243455513 +0200
+++ diffutils-3.10/src/cmp.c 2024-07-23 12:31:55.560196269 +0200
@@ -343,12 +343,13 @@ main (int argc, char **argv)
commit ff1096a0c24c3a302a58864392270e6622e21a03
Author: Paul Eggert <eggert@cs.ucla.edu>
Date: Wed Jun 21 11:19:13 2023 -0700
cmp: fix -s bug when comparing /proc files
* NEWS: Mention this.
* src/cmp.c (main, cmp): Do not trust st_size == 0, as it may
be a /proc file.
* tests/brief-vs-stat-zero-kernel-lies: Also test cmp -s.
diff --git a/NEWS b/NEWS
index 0b7cf48..00ee5b6 100644
--- a/NEWS
+++ b/NEWS
@@ -10,6 +10,12 @@ GNU diffutils NEWS -*- outline -*-
cmp/diff can again work with file dates past Y2K38
[bug introduced in 3.9]
+ cmp -s no longer mishandles /proc files, for which the Linux kernel
+ reports a zero size even when nonempty. For example, the following
+ shell command now outputs nothing, as it should:
+ cp /proc/cmdline t; cmp -s /proc/cmdline t || echo files differ
+ [bug present since "the beginning"]
+
diff -D no longer fails to output #ifndef lines.
[bug#61193 introduced in 3.9]
diff --git a/src/cmp.c b/src/cmp.c
index 4bf0a4c..936125c 100644
--- a/src/cmp.c
+++ b/src/cmp.c
@@ -338,13 +338,14 @@ main (int argc, char **argv)
}
/* If only a return code is needed,
and if both input descriptors are associated with plain files,
+ and if both files are larger than 0 bytes (procfs files are always 0),
- and if both input descriptors are associated with plain files,
+ and both input descriptors are associated with plain files,
+ and the file sizes are nonzero so they are not Linux /proc files,
conclude that the files differ if they have different sizes
and if more bytes will be compared than are in the smaller file. */
@ -17,3 +48,26 @@ diff -up diffutils-3.10/src/cmp.c.orig diffutils-3.10/src/cmp.c
{
off_t s0 = stat_buf[0].st_size - file_position (0);
off_t s1 = stat_buf[1].st_size - file_position (1);
@@ -401,7 +402,7 @@ cmp (void)
? bytes : TYPE_MAXIMUM (off_t));
for (f = 0; f < 2; f++)
- if (0 <= stat_buf[f].st_size && S_ISREG (stat_buf[f].st_mode))
+ if (0 < stat_buf[f].st_size && S_ISREG (stat_buf[f].st_mode))
{
off_t file_bytes = stat_buf[f].st_size - file_position (f);
if (file_bytes < byte_number_max)
diff --git a/tests/brief-vs-stat-zero-kernel-lies b/tests/brief-vs-stat-zero-kernel-lies
index 82b33e6..7cc2dc7 100755
--- a/tests/brief-vs-stat-zero-kernel-lies
+++ b/tests/brief-vs-stat-zero-kernel-lies
@@ -35,4 +35,9 @@ printf 'diff\0--brief\0/proc/self/cmdline\0bin\0' > bin || framework_failure_
diff --brief /proc/self/cmdline bin > out 2>&1 || fail=1
compare /dev/null out || fail=1
+# Similarly for cmp -s.
+printf 'cmp\0-s\0/proc/self/cmdline\0bin\0' > bin || framework_failure_
+cmp -s /proc/self/cmdline bin > out 2>&1 || fail=1
+compare /dev/null out || fail=1
+
Exit $fail

View file

@ -1,13 +1,12 @@
Summary: GNU collection of diff utilities
Name: diffutils
Version: 3.10
Release: 7%{?dist}
Release: 8%{?dist}
URL: https://www.gnu.org/software/diffutils/diffutils.html
Source: https://ftp.gnu.org/gnu/diffutils/diffutils-%{version}.tar.xz
# Multibyte
Patch0: diffutils-i18n.patch
Patch1: 0001-diff-Fix-output-of-diff-l-y-for-non-ASCII-input-file.patch
Patch2: diffutils-3.10-cmp-s-empty.patch
Patch1: diffutils-3.10-cmp-s-empty.patch
License: GPL-3.0-or-later
Provides: bundled(gnulib)
BuildRequires: gcc
@ -57,8 +56,11 @@ make check
%{_infodir}/diffutils.info*
%changelog
* Tue Jul 30 2024 Than Ngo <than@redhat.com> - 3.10-8
- refresh patch for 'cmp -s'
* Tue Jul 23 2024 Than Ngo <than@redhat.com> - 3.10-7
- fix a regression, cmp-s returns 1 even if files are identical
- fix a regression, 'cmp -s' returns 1 even if files are identical
* Wed Jul 17 2024 Fedora Release Engineering <releng@fedoraproject.org> - 3.10-6
- Rebuilt for https://fedoraproject.org/wiki/Fedora_41_Mass_Rebuild