bug-gnulib
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[PATCH] announce-gen: avoid failure when Digest::SHA is installed


From: Daiki Ueno
Subject: [PATCH] announce-gen: avoid failure when Digest::SHA is installed
Date: Tue, 09 Jul 2013 16:00:11 +0900
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/24.3.50 (gnu/linux)

Hi,

The 'announce-gen' script fails when Digest::SHA (not Digest::SHA1) is
installed:

  Can't locate object method "new" via package "Digest::SHA1" (perhaps you 
forgot to load "Digest::SHA1"?) at ../gnulib/build-aux/announce-gen line 165.
  zsh: exit 25    ./gnulib/build-aux/announce-gen --bootstrap-tools=automake

This is because of the following code for import:

  eval { require Digest::SHA; }
    or eval 'use Digest::SHA1';

and the usage in print_checksums:

  my $dig =
    ($meth eq 'md5'
     ? Digest::MD5->new->addfile(*IN)->hexdigest
     : Digest::SHA1->new->addfile(*IN)->hexdigest);

Here, Digest::SHA1 package may be undefined.  I'm attaching a patch.
As I'm new to Perl, comments (and a better fix) would be appreciated :)

>From 8726f48a1a263b528040f19a3323e2c558dba492 Mon Sep 17 00:00:00 2001
From: Daiki Ueno <address@hidden>
Date: Tue, 9 Jul 2013 15:54:48 +0900
Subject: [PATCH] announce-gen: avoid failure when Digest::SHA is installed

When Digest::SHA is available, Digest::SHA1 is not loaded and thus
Digest::SHA1->new in print_checksums fails.
* build-aux/announce-gen (digest_classes): New associative array
for available message digest implementations.
(print_locations): Use it.
---
 ChangeLog              |  9 +++++++++
 build-aux/announce-gen | 17 +++++++++--------
 2 files changed, 18 insertions(+), 8 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index 4247ec8..05644ae 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,12 @@
+2013-07-09  Daiki Ueno  <address@hidden>
+
+       announce-gen: avoid failure when Digest::SHA is installed
+       When Digest::SHA is available, Digest::SHA1 is not loaded and thus
+       Digest::SHA1->new in print_checksums fails.
+       * build-aux/announce-gen (digest_classes): New associative array
+       for available message digest implementations.
+       (print_locations): Use it.
+
 2013-07-07  Paul Eggert  <address@hidden>
 
        stdalign, verify: port to FreeBSD 9.1, to C11, and to C++11
diff --git a/build-aux/announce-gen b/build-aux/announce-gen
index 3a64ec6..21afd0b 100755
--- a/build-aux/announce-gen
+++ b/build-aux/announce-gen
@@ -3,7 +3,7 @@ eval '(exit $?0)' && eval 'exec perl -wS "$0" ${1+"$@"}'
     if 0;
 # Generate a release announcement message.
 
-my $VERSION = '2012-06-08 06:53'; # UTC
+my $VERSION = '2013-07-09 06:39'; # UTC
 # The definition above must lie within the first 8 lines in order
 # for the Emacs time-stamp write hook (at end) to update it.
 # If you change this file with Emacs, please let the write hook
@@ -29,15 +29,18 @@ my $VERSION = '2012-06-08 06:53'; # UTC
 use strict;
 
 use Getopt::Long;
-use Digest::MD5;
-eval { require Digest::SHA; }
-  or eval 'use Digest::SHA1';
 use POSIX qw(strftime);
 
 (my $ME = $0) =~ s|.*/||;
 
 my %valid_release_types = map {$_ => 1} qw (alpha beta stable);
 my @archive_suffixes = ('tar.gz', 'tar.bz2', 'tar.lzma', 'tar.xz');
+my %digest_classes =
+  (
+   'md5' => (eval { require Digest::MD5; } and 'Digest::MD5'),
+   'sha1' => ((eval { require Digest::SHA; } and 'Digest::SHA')
+              or (eval { require Digest::SHA1; } and 'Digest::SHA1'))
+  );
 my $srcdir = '.';
 
 sub usage ($)
@@ -157,15 +160,13 @@ sub print_checksums (@)
 
   foreach my $meth (qw (md5 sha1))
     {
+      my $class = $digest_classes{$meth} or next;
       foreach my $f (@file)
         {
           open IN, '<', $f
             or die "$ME: $f: cannot open for reading: $!\n";
           binmode IN;
-          my $dig =
-            ($meth eq 'md5'
-             ? Digest::MD5->new->addfile(*IN)->hexdigest
-             : Digest::SHA1->new->addfile(*IN)->hexdigest);
+          my $dig = $class->new->addfile(*IN)->hexdigest;
           close IN;
           print "$dig  $f\n";
         }
-- 
1.8.3.1

Regards,
-- 
Daiki Ueno

reply via email to

[Prev in Thread] Current Thread [Next in Thread]