From e884114e68874533a3156add77ebb9fedae8ec8e Mon Sep 17 00:00:00 2001 From: Rafael Garcia-Suarez Date: Tue, 24 Jan 2006 11:13:24 +0000 Subject: Use Digest::MD5 when available --- urpm/util.pm | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) (limited to 'urpm/util.pm') diff --git a/urpm/util.pm b/urpm/util.pm index 51091a6b..dfd133f8 100644 --- a/urpm/util.pm +++ b/urpm/util.pm @@ -82,9 +82,18 @@ sub untaint { } sub md5sum { - #- Use an external command to avoid depending on perl my ($file) = @_; - return((split ' ', `/usr/bin/md5sum '$file'`)[0]); + eval { require Digest::MD5 }; + if ($@) { + #- Use an external command to avoid depending on perl + return((split ' ', `/usr/bin/md5sum '$file'`)[0]); + } else { + my $ctx = Digest::MD5->new; + open my $fh, $file or return ''; + $ctx->addfile($fh); + close $fh; + return $ctx->hexdigest; + } } sub copy { @@ -115,6 +124,6 @@ urpm::util - Misc. utilities subs for urpmi Copyright (C) 2005 MandrakeSoft SA -Copyright (C) 2005 Mandriva SA +Copyright (C) 2005, 2006 Mandriva SA =cut -- cgit v1.2.1