diff options
author | Stig Bakken <ssb@php.net> | 2002-10-12 00:40:16 +0000 |
---|---|---|
committer | Stig Bakken <ssb@php.net> | 2002-10-12 00:40:16 +0000 |
commit | 3aba20dd9ef48c4e33eee677f083a99c0df4594d (patch) | |
tree | 1783c41c8828fd7cde1266e3e0ea4921218534de /pear | |
parent | 2771434028844606def3afbabacc5c7c7e458513 (diff) | |
download | php-git-3aba20dd9ef48c4e33eee677f083a99c0df4594d.tar.gz |
* verify md5 checksums during install
Diffstat (limited to 'pear')
-rw-r--r-- | pear/PEAR/Installer.php | 31 |
1 files changed, 27 insertions, 4 deletions
diff --git a/pear/PEAR/Installer.php b/pear/PEAR/Installer.php index b11502336d..a6c5d96a0f 100644 --- a/pear/PEAR/Installer.php +++ b/pear/PEAR/Installer.php @@ -158,7 +158,7 @@ class PEAR_Installer extends PEAR_Common } // 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; } } @@ -215,15 +215,21 @@ class PEAR_Installer extends PEAR_Common $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 = ''; @@ -244,7 +250,7 @@ class PEAR_Installer extends PEAR_Common $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); } @@ -256,6 +262,13 @@ class PEAR_Installer extends PEAR_Common 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')); @@ -271,7 +284,7 @@ class PEAR_Installer extends PEAR_Common // 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; } @@ -664,4 +677,14 @@ class PEAR_Installer extends PEAR_Common // }}} } +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); + } +} + ?> |