Skip to content

Commit

Permalink
* verify md5 checksums during install
Browse files Browse the repository at this point in the history
  • Loading branch information
stigsb committed Oct 12, 2002
1 parent 2771434 commit 3aba20d
Showing 1 changed file with 27 additions and 4 deletions.
31 changes: 27 additions & 4 deletions pear/PEAR/Installer.php
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ function _installFile($file, $atts, $tmp_path)
}
// return if this file is meant for another platform
if (!$os->matchSignature($atts['platform'])) {
$this->log(2, "skipped $file (meant for $atts[platform], we are ".$os->getSignature().")");
$this->log(3, "skipped $file (meant for $atts[platform], we are ".$os->getSignature().")");
return PEAR_INSTALLER_SKIPPED;
}
}
Expand Down Expand Up @@ -215,15 +215,21 @@ function _installFile($file, $atts, $tmp_path)
$this->log(3, "+ mkdir $dest_dir");
}
if (empty($atts['replacements'])) {
if (!@copy($orig_file, $dest_file)) {
if (!copy($orig_file, $dest_file)) {
return $this->raiseError("failed to copy $orig_file to $dest_file",
PEAR_INSTALLER_FAILED);
}
$this->log(3, "+ cp $orig_file $dest_file");
if (isset($atts['md5sum'])) {
$md5sum = md5_file($dest_file);
}
} else {
$fp = fopen($orig_file, "r");
$contents = fread($fp, filesize($orig_file));
fclose($fp);
if (isset($atts['md5sum'])) {
$md5sum = md5($contents);
}
$subst_from = $subst_to = array();
foreach ($atts['replacements'] as $a) {
$to = '';
Expand All @@ -244,7 +250,7 @@ function _installFile($file, $atts, $tmp_path)
$subst_to[] = $to;
}
}
$this->log(2, "doing ".sizeof($subst_from)." substitution(s) for $dest_file");
$this->log(3, "doing ".sizeof($subst_from)." substitution(s) for $dest_file");
if (sizeof($subst_from)) {
$contents = str_replace($subst_from, $subst_to, $contents);
}
Expand All @@ -256,6 +262,13 @@ function _installFile($file, $atts, $tmp_path)
fwrite($wp, $contents);
fclose($wp);
}
if (isset($md5sum)) {
if ($md5sum == $atts['md5sum']) {
$this->log(3, "md5sum ok: $dest_file");
} else {
$this->log(0, "warning : bad md5sum for file $dest_file");
}
}
if (!OS_WINDOWS) {
if ($atts['role'] == 'script') {
$mode = 0777 & ~(int)octdec($this->config->get('umask'));
Expand All @@ -271,7 +284,7 @@ function _installFile($file, $atts, $tmp_path)
// Store the full path where the file was installed for easy unistall
$this->pkginfo['filelist'][$file]['installed_as'] = $installed_as;

$this->log(2, "installed file $dest_file");
$this->log(2, "installed: $dest_file");
return PEAR_INSTALLER_OK;
}

Expand Down Expand Up @@ -664,4 +677,14 @@ function _buildCallback($what, $data)
// }}}
}

if (!function_exists("md5_file")) {
function md5_file($filename) {
$fp = fopen($filename, "r");
if (!$fp) return null;
$contents = fread($fp, filesize($filename));
fclose($fp);
return md5($contents);
}
}

?>

0 comments on commit 3aba20d

Please sign in to comment.