summaryrefslogtreecommitdiffstats
path: root/urpm
diff options
context:
space:
mode:
authorPascal Rigaux <pixel@mandriva.com>2006-11-21 16:20:26 +0000
committerPascal Rigaux <pixel@mandriva.com>2006-11-21 16:20:26 +0000
commit761d244245fbb10dcfd79208150b0b5f6b93cb04 (patch)
tree76d74cc10f18d2b67667eb004816a9e95f6e45f2 /urpm
parent190ab2c006dd503413775aabd6af940a72df8239 (diff)
downloadurpmi-761d244245fbb10dcfd79208150b0b5f6b93cb04.tar
urpmi-761d244245fbb10dcfd79208150b0b5f6b93cb04.tar.gz
urpmi-761d244245fbb10dcfd79208150b0b5f6b93cb04.tar.bz2
urpmi-761d244245fbb10dcfd79208150b0b5f6b93cb04.tar.xz
urpmi-761d244245fbb10dcfd79208150b0b5f6b93cb04.zip
create urpm::md5sum, move md5sum functions into it:
- urpm::util::md5sum() -> urpm::md5sum::compute() - urpm::local_md5sum() -> urpm::md5sum::on_local_medium()
Diffstat (limited to 'urpm')
-rw-r--r--urpm/md5sum.pm64
-rw-r--r--urpm/util.pm17
2 files changed, 65 insertions, 16 deletions
diff --git a/urpm/md5sum.pm b/urpm/md5sum.pm
new file mode 100644
index 00000000..c94fb96e
--- /dev/null
+++ b/urpm/md5sum.pm
@@ -0,0 +1,64 @@
+package urpm::md5sum;
+
+use urpm;
+use urpm::util;
+use urpm::msg;
+
+
+#- parse an MD5SUM file from a mirror
+sub from_MD5SUM {
+ my ($md5sum_file, $f) = @_;
+ my $basename = basename($f);
+
+ my ($retrieved_md5sum) = map {
+ my ($md5sum, $file) = m|(\S+)\s+(?:\./)?(\S+)|;
+ $file && $file eq $basename ? $md5sum : @{[]};
+ } cat_($md5sum_file);
+
+ $retrieved_md5sum;
+}
+
+sub from_MD5SUM__or_warn {
+ my ($urpm, $md5sum_file, $basename) = @_;
+ $urpm->{log}(N("examining %s file", $md5sum_file));
+ my $retrieved_md5sum = from_MD5SUM($md5sum_file, $basename)
+ or $urpm->{log}(N("warning: md5sum for %s unavailable in MD5SUM file", $basename));
+ return $retrieved_md5sum;
+}
+
+sub on_local_medium {
+ my ($urpm, $medium, $force) = @_;
+ if ($force) {
+ #- force downloading the file again, else why a force option has been defined ?
+ delete $medium->{md5sum};
+ } else {
+ $medium->{md5sum} ||= compute_on_local_medium($urpm, $medium);
+ }
+ $medium->{md5sum};
+}
+
+sub compute_on_local_medium {
+ my ($urpm, $medium) = @_;
+
+ require urpm; #- help perl_checker
+ my $f = urpm::statedir_hdlist_or_synthesis($urpm, $medium);
+ $urpm->{log}(N("computing md5sum of existing source hdlist (or synthesis) [%s]", $f));
+ -e $f && compute($f);
+}
+
+sub compute {
+ my ($file) = @_;
+ 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;
+ }
+}
+
+1;
diff --git a/urpm/util.pm b/urpm/util.pm
index b12c49a0..58922349 100644
--- a/urpm/util.pm
+++ b/urpm/util.pm
@@ -8,7 +8,7 @@ our @ISA = 'Exporter';
our @EXPORT = qw(quotespace unquotespace
remove_internal_name
reduce_pathname offset_pathname
- md5sum untaint
+ untaint
copy_and_own
same_size_and_mtime
difference2 member file_size cat_ dirname basename
@@ -87,21 +87,6 @@ sub untaint {
@r == 1 ? $r[0] : @r;
}
-sub md5sum {
- my ($file) = @_;
- 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 {
my ($file, $dest) = @_;
!system("/bin/cp", "-p", "-L", "-R", $file, $dest);