function _installFile($file, $atts, $tmp_path) { static $os; if (isset($atts['platform'])) { if (empty($os)) { include_once "OS/Guess.php"; $os = new OS_Guess(); } // return if this file is meant for another platform if (!$os->matchSignature($atts['platform'])) { $this->log(3, "skipped {$file} (meant for {$atts['platform']}, we are " . $os->getSignature() . ")"); return PEAR_INSTALLER_SKIPPED; } } switch ($atts['role']) { case 'doc': case 'data': case 'test': $dest_dir = $this->config->get($atts['role'] . '_dir') . DIRECTORY_SEPARATOR . $this->pkginfo['package']; unset($atts['baseinstalldir']); break; case 'ext': case 'php': $dest_dir = $this->config->get($atts['role'] . '_dir'); break; case 'script': $dest_dir = $this->config->get('bin_dir'); break; case 'src': case 'extsrc': $this->source_files++; return; default: return $this->raiseError("Invalid role `{$atts['role']}' for file {$file}"); } if (!empty($atts['baseinstalldir'])) { $dest_dir .= DIRECTORY_SEPARATOR . $atts['baseinstalldir']; } if (dirname($file) != '.' && empty($atts['install-as'])) { $dest_dir .= DIRECTORY_SEPARATOR . dirname($file); } if (empty($atts['install-as'])) { $dest_file = $dest_dir . DIRECTORY_SEPARATOR . basename($file); } else { $dest_file = $dest_dir . DIRECTORY_SEPARATOR . $atts['install-as']; } $orig_file = $tmp_path . DIRECTORY_SEPARATOR . $file; // Clean up the DIRECTORY_SEPARATOR mess $ds2 = DIRECTORY_SEPARATOR . DIRECTORY_SEPARATOR; list($dest_file, $orig_file) = preg_replace(array('!\\\\+!', '!/!', "!{$ds2}+!"), DIRECTORY_SEPARATOR, array($dest_file, $orig_file)); $installed_as = $dest_file; $final_dest_file = $this->_prependPath($dest_file, $this->installroot); $dest_dir = dirname($final_dest_file); $dest_file = $dest_dir . DIRECTORY_SEPARATOR . '.tmp' . basename($final_dest_file); if (!@is_dir($dest_dir)) { if (!$this->mkDirHier($dest_dir)) { return $this->raiseError("failed to mkdir {$dest_dir}", PEAR_INSTALLER_FAILED); } $this->log(3, "+ mkdir {$dest_dir}"); } if (empty($atts['replacements'])) { if (!@copy($orig_file, $dest_file)) { return $this->raiseError("failed to write {$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 = ''; if ($a['type'] == 'php-const') { if (preg_match('/^[a-z0-9_]+$/i', $a['to'])) { eval("\$to = {$a['to']};"); } else { $this->log(0, "invalid php-const replacement: {$a['to']}"); continue; } } elseif ($a['type'] == 'pear-config') { $to = $this->config->get($a['to']); } elseif ($a['type'] == 'package-info') { $to = $this->pkginfo[$a['to']]; } if ($to) { $subst_from[] = $a['from']; $subst_to[] = $to; } } $this->log(3, "doing " . sizeof($subst_from) . " substitution(s) for {$final_dest_file}"); if (sizeof($subst_from)) { $contents = str_replace($subst_from, $subst_to, $contents); } $wp = @fopen($dest_file, "w"); if (!is_resource($wp)) { return $this->raiseError("failed to create {$dest_file}: {$php_errormsg}", PEAR_INSTALLER_FAILED); } if (!fwrite($wp, $contents)) { return $this->raiseError("failed writing to {$dest_file}: {$php_errormsg}", PEAR_INSTALLER_FAILED); } fclose($wp); } if (isset($md5sum)) { if ($md5sum == $atts['md5sum']) { $this->log(3, "md5sum ok: {$final_dest_file}"); } else { $this->log(0, "warning : bad md5sum for file {$final_dest_file}"); } } if (!OS_WINDOWS) { if ($atts['role'] == 'script') { $mode = 0777 & ~(int) octdec($this->config->get('umask')); $this->log(3, "+ chmod +x {$dest_file}"); } else { $mode = 0666 & ~(int) octdec($this->config->get('umask')); } $this->addFileOperation("chmod", array($mode, $dest_file)); if (!@chmod($dest_file, $mode)) { $this->log(0, "failed to change mode of {$dest_file}"); } } $this->addFileOperation("rename", array($dest_file, $final_dest_file)); // XXX SHOULD BE DONE ONLY AFTER COMMIT // Store the full path where the file was installed for easy unistall $this->pkginfo['filelist'][$file]['installed_as'] = $installed_as; //$this->log(2, "installed: $dest_file"); return PEAR_INSTALLER_OK; }
/** * @param string filename * @param array attributes from <file> tag in package.xml * @param string path to install the file in * @param array options from command-line * @access private */ function _installFile($file, $atts, $tmp_path, $options) { // {{{ return if this file is meant for another platform static $os; if (!isset($this->_registry)) { $this->_registry =& $this->config->getRegistry(); } if (isset($atts['platform'])) { if (empty($os)) { $os = new OS_Guess(); } if (strlen($atts['platform']) && $atts['platform'][0] == '!') { $negate = true; $platform = substr($atts['platform'], 1); } else { $negate = false; $platform = $atts['platform']; } if ((bool) $os->matchSignature($platform) === $negate) { $this->log(3, "skipped {$file} (meant for {$atts['platform']}, we are " . $os->getSignature() . ")"); return PEAR_INSTALLER_SKIPPED; } } // }}} $channel = $this->pkginfo->getChannel(); // {{{ assemble the destination paths switch ($atts['role']) { case 'doc': case 'data': case 'test': $dest_dir = $this->config->get($atts['role'] . '_dir', null, $channel) . DIRECTORY_SEPARATOR . $this->pkginfo->getPackage(); unset($atts['baseinstalldir']); break; case 'ext': case 'php': $dest_dir = $this->config->get($atts['role'] . '_dir', null, $channel); break; case 'script': $dest_dir = $this->config->get('bin_dir', null, $channel); break; case 'src': case 'extsrc': $this->source_files++; return; default: return $this->raiseError("Invalid role `{$atts['role']}' for file {$file}"); } $save_destdir = $dest_dir; if (!empty($atts['baseinstalldir'])) { $dest_dir .= DIRECTORY_SEPARATOR . $atts['baseinstalldir']; } if (dirname($file) != '.' && empty($atts['install-as'])) { $dest_dir .= DIRECTORY_SEPARATOR . dirname($file); } if (empty($atts['install-as'])) { $dest_file = $dest_dir . DIRECTORY_SEPARATOR . basename($file); } else { $dest_file = $dest_dir . DIRECTORY_SEPARATOR . $atts['install-as']; } $orig_file = $tmp_path . DIRECTORY_SEPARATOR . $file; // Clean up the DIRECTORY_SEPARATOR mess $ds2 = DIRECTORY_SEPARATOR . DIRECTORY_SEPARATOR; list($dest_file, $orig_file) = preg_replace(array('!\\\\+!', '!/!', "!{$ds2}+!"), array(DIRECTORY_SEPARATOR, DIRECTORY_SEPARATOR, DIRECTORY_SEPARATOR), array($dest_file, $orig_file)); $final_dest_file = $installed_as = $dest_file; if (isset($this->_options['packagingroot'])) { $installedas_dest_dir = dirname($final_dest_file); $installedas_dest_file = $dest_dir . DIRECTORY_SEPARATOR . '.tmp' . basename($final_dest_file); $final_dest_file = $this->_prependPath($final_dest_file, $this->_options['packagingroot']); } else { $installedas_dest_dir = dirname($final_dest_file); $installedas_dest_file = $installedas_dest_dir . DIRECTORY_SEPARATOR . '.tmp' . basename($final_dest_file); } $dest_dir = dirname($final_dest_file); $dest_file = $dest_dir . DIRECTORY_SEPARATOR . '.tmp' . basename($final_dest_file); // }}} if (empty($this->_options['register-only']) && !@is_dir($dest_dir)) { if (!$this->mkDirHier($dest_dir)) { return $this->raiseError("failed to mkdir {$dest_dir}", PEAR_INSTALLER_FAILED); } $this->log(3, "+ mkdir {$dest_dir}"); } // pretty much nothing happens if we are only registering the install if (empty($this->_options['register-only'])) { if (empty($atts['replacements'])) { if (!file_exists($orig_file)) { return $this->raiseError("file {$orig_file} does not exist", PEAR_INSTALLER_FAILED); } if (!@copy($orig_file, $dest_file)) { return $this->raiseError("failed to write {$dest_file}", PEAR_INSTALLER_FAILED); } $this->log(3, "+ cp {$orig_file} {$dest_file}"); if (isset($atts['md5sum'])) { $md5sum = md5_file($dest_file); } } else { // {{{ file with replacements if (!file_exists($orig_file)) { return $this->raiseError("file does not exist", PEAR_INSTALLER_FAILED); } if (function_exists('file_get_contents')) { $contents = file_get_contents($orig_file); } else { $fp = fopen($orig_file, "r"); $contents = @fread($fp, filesize($orig_file)); fclose($fp); } if ($contents === false) { $contents = ''; } if (isset($atts['md5sum'])) { $md5sum = md5($contents); } $subst_from = $subst_to = array(); foreach ($atts['replacements'] as $a) { $to = ''; if ($a['type'] == 'php-const') { if (preg_match('/^[a-z0-9_]+$/i', $a['to'])) { eval("\$to = {$a['to']};"); } else { if (!isset($options['soft'])) { $this->log(0, "invalid php-const replacement: {$a['to']}"); } continue; } } elseif ($a['type'] == 'pear-config') { if ($a['to'] == 'master_server') { $chan = $this->_registry->getChannel($channel); if (!PEAR::isError($chan)) { $to = $chan->getServer(); } else { $to = $this->config->get($a['to'], null, $channel); } } else { $to = $this->config->get($a['to'], null, $channel); } if (is_null($to)) { if (!isset($options['soft'])) { $this->log(0, "invalid pear-config replacement: {$a['to']}"); } continue; } } elseif ($a['type'] == 'package-info') { if ($t = $this->pkginfo->packageInfo($a['to'])) { $to = $t; } else { if (!isset($options['soft'])) { $this->log(0, "invalid package-info replacement: {$a['to']}"); } continue; } } if (!is_null($to)) { $subst_from[] = $a['from']; $subst_to[] = $to; } } $this->log(3, "doing " . sizeof($subst_from) . " substitution(s) for {$final_dest_file}"); if (sizeof($subst_from)) { $contents = str_replace($subst_from, $subst_to, $contents); } $wp = @fopen($dest_file, "wb"); if (!is_resource($wp)) { return $this->raiseError("failed to create {$dest_file}: {$php_errormsg}", PEAR_INSTALLER_FAILED); } if (fwrite($wp, $contents) === false) { return $this->raiseError("failed writing to {$dest_file}: {$php_errormsg}", PEAR_INSTALLER_FAILED); } fclose($wp); // }}} } // {{{ check the md5 if (isset($md5sum)) { if (strtolower($md5sum) == strtolower($atts['md5sum'])) { $this->log(2, "md5sum ok: {$final_dest_file}"); } else { if (empty($options['force'])) { // delete the file @unlink($dest_file); if (!isset($options['ignore-errors'])) { return $this->raiseError("bad md5sum for file {$final_dest_file}", PEAR_INSTALLER_FAILED); } else { if (!isset($options['soft'])) { $this->log(0, "warning : bad md5sum for file {$final_dest_file}"); } } } else { if (!isset($options['soft'])) { $this->log(0, "warning : bad md5sum for file {$final_dest_file}"); } } } } // }}} // {{{ set file permissions if (!OS_WINDOWS) { if ($atts['role'] == 'script') { $mode = 0777 & ~(int) octdec($this->config->get('umask')); $this->log(3, "+ chmod +x {$dest_file}"); } else { $mode = 0666 & ~(int) octdec($this->config->get('umask')); } $this->addFileOperation("chmod", array($mode, $dest_file)); if (!@chmod($dest_file, $mode)) { if (!isset($options['soft'])) { $this->log(0, "failed to change mode of {$dest_file}"); } } } // }}} $this->addFileOperation("rename", array($dest_file, $final_dest_file, $atts['role'] == 'ext')); } // Store the full path where the file was installed for easy unistall $this->addFileOperation("installed_as", array($file, $installed_as, $save_destdir, dirname(substr($installedas_dest_file, strlen($save_destdir))))); //$this->log(2, "installed: $dest_file"); return PEAR_INSTALLER_OK; }
//C:\php\pear\docs\XML_Util\examples\example.php require_once 'XML/Util.php'; /** * building document type declaration */ print 'building DocType declaration:<br>'; print htmlspecialchars(XML_Util::getDocTypeDeclaration('package', 'http://pear.php.net/dtd/package-1.0')); print "\n<br><br>\n"; $modes = mcrypt_list_modes(); echo "mcrypt_list_modes <br>\n"; echo print_r_xml($modes); //F:\bit5411\php\PEAR\OS\Guess.php class OS_Guess require_once 'OS/Guess.php'; $phpwhat = new OS_Guess(); //$phpwhat = OS_Guess::getSignature(); //fatal this $tmp = $phpwhat->getSignature(); echo $tmp; echo PHP_EOL; $tmp = $phpwhat->getSysname(); echo $tmp; echo PHP_EOL; $tmp = $phpwhat->getNodename(); echo $tmp; echo PHP_EOL; $tmp = $phpwhat->getCpu(); echo $tmp; echo PHP_EOL; $tmp = $phpwhat->getRelease(); echo $tmp; echo PHP_EOL; $tmp = $phpwhat->getExtra();