File: turbo-correct-md5-hash

package info (click to toggle)
debarchiver 0.11.7
  • links: PTS
  • area: main
  • in suites: bookworm, sid, trixie
  • size: 724 kB
  • sloc: perl: 1,599; sh: 109; makefile: 92
file content (74 lines) | stat: -rw-r--r-- 2,589 bytes parent folder | download | duplicates (8)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
--- /usr/bin/debarchiver.old	2007-10-08 16:03:48.000000000 +0200
+++ /usr/bin/debarchiver	2007-10-08 18:26:30.000000000 +0200
@@ -38,6 +38,7 @@
 ############################# USES ############################################
 ###############################################################################
 
+use Digest::MD5;
 use File::Path qw(mkpath);
 use OpaL::action qw(pdebug action cmdaction
 		    setDebugLevel
@@ -1423,9 +1424,43 @@
 		return "reject";
 	    }
 	    else {
-		pdebug(4, "$cfile is incomplete. Missing file: $file.");
-		$CConf{ERROR} = "$CConf{ERROR}$cfile is incomplete. Missing file: $file.\n";
-		return "incomplete";
+		# $file is missing in incoming. Does it exist in the destdir?
+		my $file_installed = 0;
+		my $distrd = $CConf{Distribution};
+		my $inst_file, $hash, $size, $section;
+		foreach $distr (split /\s+/, $distrd) {
+		    my $distr = $distmapping{$distr} || $distr;
+		    my (undef, undef, $arch, undef) = parseFileName($file);
+		       ($hash, $size, $section, undef) = parseFileStruct($CFiles{$file});
+
+		    my $archsec = "source";
+		    if ($arch !~ /^source$/) {
+			$archsec = "binary-$arch";
+		    }
+		    my ($major, $section) = parseSection($section);
+
+		    $inst_file = "$destdir/$distr/$major/$archsec/$section/$file";
+		    if (-f $inst_file) {
+			$file_installed = 1;
+		    }
+		}
+
+		if ($file_installed) {
+		    # File exists. Get it's hash. The hash it SHOULD have is in $hash.
+		    open(FILE, $inst_file) or die "Can't open $inst_file: $!\n";
+		    binmode(FILE);
+
+		    $digest = Digest::MD5->new->addfile(*FILE)->hexdigest, " $inst_file\n";
+		    if ($hash != $digest) {
+			pdebug(4, "$cfile is incomplete. Missing file: $file (installed $file not the correct).");
+			$CConf{ERROR} = "$CConf{ERROR}$cfile is incomplete. Missing file: $file (installed $file not the correct).\n";
+			return "incomplete";
+		    }
+		} else {
+		    pdebug(4, "$cfile is incomplete. Missing file: $file.");
+		    $CConf{ERROR} = "$CConf{ERROR}$cfile is incomplete. Missing file: $file.\n";
+		    return "incomplete";
+		}
 	    }
 	} else {
 	    my (undef, undef, undef, undef, $fowner, undef, undef, $size) = stat($file);
@@ -1462,6 +1497,7 @@
 	    return "reject";
 	}
     }
+    return $ret;
 }
 
 ###############################################################################
@@ -1626,7 +1662,7 @@
 		   "Making directory $installto",
 		   2);
 	}
-	else {
+	elsif (-f $file) {
 	    if ($arch =~ /^source$/) {
 		cmdaction("$rmcmd $installto/${pkgname}_*$ext",
 			  "Delete $installto/${pkgname}_*$ext",