This is an automated email from the git hooks/post-receive script. guillem pushed a commit to branch master in repository dpkg.
View the commit online: https://git.dpkg.org/cgit/dpkg/dpkg.git/commit/?id=ffe3d7aeed7e7eb9a1c22d45fd0e5c2af2c8bcad commit ffe3d7aeed7e7eb9a1c22d45fd0e5c2af2c8bcad Author: Guillem Jover <[email protected]> AuthorDate: Sun Sep 16 23:42:08 2018 +0200 Dpkg::Source::Functions: Reimplement is_binary() w/o using diff(1) The check is very simple, and can be done w/o requiring calling diff(1) for each input file. This makes the code shorter, more portable, and should be faster in the non-binary cases. --- debian/changelog | 1 + scripts/Dpkg/Source/Functions.pm | 31 ++++++++----------------------- 2 files changed, 9 insertions(+), 23 deletions(-) diff --git a/debian/changelog b/debian/changelog index 4d7e8f1ab..fd83782c3 100644 --- a/debian/changelog +++ b/debian/changelog @@ -5,6 +5,7 @@ dpkg (1.19.2) UNRELEASED; urgency=medium - Dpkg::OpenPGP: Ignore Version field in enarmored output. Fixes CPAN#127217. - Dpkg::OpenPGP: Do not read the gpg user configuration file. + - Dpkg::Source::Functions: Reimplement is_binary() w/o using diff(1). * Documentation: - dpkg-buildpackage(1): Clarify --build=source explanation. - dsc(5): Clarify what “flattened” means in Testsuite-Triggers. diff --git a/scripts/Dpkg/Source/Functions.pm b/scripts/Dpkg/Source/Functions.pm index 262b80ad1..3435f6c5a 100644 --- a/scripts/Dpkg/Source/Functions.pm +++ b/scripts/Dpkg/Source/Functions.pm @@ -110,30 +110,15 @@ sub fs_time($) { sub is_binary($) { my $file = shift; - # TODO: might want to reimplement what diff does, aka checking if the - # file contains \0 in the first 4Kb of data + # Perform the same check as diff(1), look for a NUL character in the first + # 4 KiB of the file. + open my $fh, '<', $file + or syserr(g_('cannot open file %s for binary detection'), $file); + read $fh, my $buf, 4096, 0; + my $res = index $buf, "\0"; + close $fh; - # Use diff to check if it's a binary file - my $diffgen; - my $diff_pid = spawn( - exec => [ 'diff', '-u', '--', '/dev/null', $file ], - env => { LC_ALL => 'C', LANG => 'C', TZ => 'UTC0' }, - to_pipe => \$diffgen, - ); - my $result = 0; - local $_; - while (<$diffgen>) { - if (m/^(?:binary|[^-+\@ ].*\bdiffer\b)/i) { - $result = 1; - last; - } elsif (m/^[-+\@ ]/) { - $result = 0; - last; - } - } - close($diffgen) or syserr('close on diff pipe'); - wait_child($diff_pid, nocheck => 1, cmdline => "diff -u -- /dev/null $file"); - return $result; + return $res >= 0; } 1; -- Dpkg.Org's dpkg

