installer.php

来自「视频监控网络部分的协议ddns,的模块的实现代码,请大家大胆指正.」· PHP 代码 · 共 1,594 行 · 第 1/5 页

PHP
1,594
字号
            // To allow relative package file names            $descfile = realpath($descfile);            if (PEAR::isError($tmpdir = System::mktemp('-d'))) {                return $tmpdir;            }            $this->log(3, '+ tmp dir created at ' . $tmpdir);            // }}}        }        // Parse xml file -----------------------------------------------        $pkg = new PEAR_PackageFile($this->config, $this->debug, $tmpdir);        PEAR::staticPushErrorHandling(PEAR_ERROR_RETURN);        $p = &$pkg->fromAnyFile($descfile, PEAR_VALIDATE_INSTALLING);        PEAR::staticPopErrorHandling();        if (PEAR::isError($p)) {            if (is_array($p->getUserInfo())) {                foreach ($p->getUserInfo() as $err) {                    $loglevel = $err['level'] == 'error' ? 0 : 1;                    if (!isset($this->_options['soft'])) {                        $this->log($loglevel, ucfirst($err['level']) . ': ' . $err['message']);                    }                }            }            return $this->raiseError('Installation failed: invalid package file');        } else {            $descfile = $p->getPackageFile();        }        return $p;    }    // }}}    /**     * Set the list of PEAR_Downloader_Package objects to allow more sane     * dependency validation     * @param array     */    function setDownloadedPackages(&$pkgs)    {        PEAR::pushErrorHandling(PEAR_ERROR_RETURN);        $err = $this->analyzeDependencies($pkgs);        PEAR::popErrorHandling();        if (PEAR::isError($err)) {            return $err;        }        $this->_downloadedPackages = &$pkgs;    }    /**     * Set the list of PEAR_Downloader_Package objects to allow more sane     * dependency validation     * @param array     */    function setUninstallPackages(&$pkgs)    {        $this->_downloadedPackages = &$pkgs;    }    function getInstallPackages()    {        return $this->_downloadedPackages;    }    // {{{ install()    /**     * Installs the files within the package file specified.     *     * @param string|PEAR_Downloader_Package $pkgfile path to the package file,     *        or a pre-initialized packagefile object     * @param array $options     * recognized options:     * - installroot   : optional prefix directory for installation     * - force         : force installation     * - register-only : update registry but don't install files     * - upgrade       : upgrade existing install     * - soft          : fail silently     * - nodeps        : ignore dependency conflicts/missing dependencies     * - alldeps       : install all dependencies     * - onlyreqdeps   : install only required dependencies     *     * @return array|PEAR_Error package info if successful     */    function install($pkgfile, $options = array())    {        $this->_options = $options;        $this->_registry = &$this->config->getRegistry();        if (is_object($pkgfile)) {            $dlpkg = &$pkgfile;            $pkg = $pkgfile->getPackageFile();            $pkgfile = $pkg->getArchiveFile();            $descfile = $pkg->getPackageFile();            $tmpdir = dirname($descfile);        } else {            $descfile = $pkgfile;            $tmpdir = '';            if (PEAR::isError($pkg = &$this->_parsePackageXml($descfile, $tmpdir))) {                return $pkg;            }        }        if (realpath($descfile) != realpath($pkgfile)) {            $tar = new Archive_Tar($pkgfile);            if (!$tar->extract($tmpdir)) {                return $this->raiseError("unable to unpack $pkgfile");            }        }        $pkgname = $pkg->getName();        $channel = $pkg->getChannel();        if (isset($this->_options['packagingroot'])) {            $regdir = $this->_prependPath(                $this->config->get('php_dir', null, 'pear.php.net'),                $this->_options['packagingroot']);            $packrootphp_dir = $this->_prependPath(                $this->config->get('php_dir', null, $channel),                $this->_options['packagingroot']);        }        if (isset($options['installroot'])) {            $this->config->setInstallRoot($options['installroot']);            $this->_registry = &$this->config->getRegistry();            $installregistry = &$this->_registry;            $this->installroot = ''; // all done automagically now            $php_dir = $this->config->get('php_dir', null, $channel);        } else {            $this->config->setInstallRoot(false);            $this->_registry = &$this->config->getRegistry();            if (isset($this->_options['packagingroot'])) {                $installregistry = &new PEAR_Registry($regdir);                if (!$installregistry->channelExists($channel, true)) {                    // we need to fake a channel-discover of this channel                    $chanobj = $this->_registry->getChannel($channel, true);                    $installregistry->addChannel($chanobj);                }                $php_dir = $packrootphp_dir;            } else {                $installregistry = &$this->_registry;                $php_dir = $this->config->get('php_dir', null, $channel);            }            $this->installroot = '';        }        // {{{ checks to do when not in "force" mode        if (empty($options['force']) &&              (file_exists($this->config->get('php_dir')) &&               is_dir($this->config->get('php_dir')))) {            $testp = $channel == 'pear.php.net' ? $pkgname : array($channel, $pkgname);            $instfilelist = $pkg->getInstallationFileList(true);            if (PEAR::isError($instfilelist)) {                return $instfilelist;            }            // ensure we have the most accurate registry            $installregistry->flushFileMap();            $test = $installregistry->checkFileMap($instfilelist, $testp, '1.1');            if (PEAR::isError($test)) {                return $test;            }            if (sizeof($test)) {                $pkgs = $this->getInstallPackages();                $found = false;                foreach ($pkgs as $param) {                    if ($pkg->isSubpackageOf($param)) {                        $found = true;                        break;                    }                }                if ($found) {                    // subpackages can conflict with earlier versions of parent packages                    $parentreg = $installregistry->packageInfo($param->getPackage(), null, $param->getChannel());                    $tmp = $test;                    foreach ($tmp as $file => $info) {                        if (is_array($info)) {                            if (strtolower($info[1]) == strtolower($param->getPackage()) &&                                  strtolower($info[0]) == strtolower($param->getChannel())) {                                unset($test[$file]);                                unset($parentreg['filelist'][$file]);                            }                        } else {                            if (strtolower($param->getChannel()) != 'pear.php.net') {                                continue;                            }                            if (strtolower($info) == strtolower($param->getPackage())) {                                unset($test[$file]);                                unset($parentreg['filelist'][$file]);                            }                        }                    }                    $pfk = &new PEAR_PackageFile($this->config);                    $parentpkg = &$pfk->fromArray($parentreg);                    $installregistry->updatePackage2($parentpkg);                }                if ($param->getChannel() == 'pecl.php.net' && isset($options['upgrade'])) {                    $tmp = $test;                    foreach ($tmp as $file => $info) {                        if (is_string($info)) {                            // pear.php.net packages are always stored as strings                            if (strtolower($info) == strtolower($param->getPackage())) {                                // upgrading existing package                                unset($test[$file]);                            }                        }                    }                }                if (sizeof($test)) {                    $msg = "$channel/$pkgname: conflicting files found:\n";                    $longest = max(array_map("strlen", array_keys($test)));                    $fmt = "%${longest}s (%s)\n";                    foreach ($test as $file => $info) {                        if (!is_array($info)) {                            $info = array('pear.php.net', $info);                        }                        $info = $info[0] . '/' . $info[1];                        $msg .= sprintf($fmt, $file, $info);                    }                    if (!isset($options['ignore-errors'])) {                        return $this->raiseError($msg);                    } else {                        if (!isset($options['soft'])) {                            $this->log(0, "WARNING: $msg");                        }                    }                }            }        }        // }}}        $this->startFileTransaction();        if (empty($options['upgrade']) && empty($options['soft'])) {            // checks to do only when installing new packages            if ($channel == 'pecl.php.net') {                $test = $installregistry->packageExists($pkgname, $channel);                if (!$test) {                    $test = $installregistry->packageExists($pkgname, 'pear.php.net');                }            } else {                $test = $installregistry->packageExists($pkgname, $channel);            }            if (empty($options['force']) && $test) {                return $this->raiseError("$channel/$pkgname is already installed");            }        } else {            $usechannel = $channel;            if ($channel == 'pecl.php.net') {                $test = $installregistry->packageExists($pkgname, $channel);                if (!$test) {                    $test = $installregistry->packageExists($pkgname, 'pear.php.net');                    $usechannel = 'pear.php.net';                }            } else {                $test = $installregistry->packageExists($pkgname, $channel);            }            if ($test) {                $v1 = $installregistry->packageInfo($pkgname, 'version', $usechannel);                $v2 = $pkg->getVersion();                $cmp = version_compare("$v1", "$v2", 'gt');                if (empty($options['force']) && !version_compare("$v2", "$v1", 'gt')) {                    return $this->raiseError("upgrade to a newer version ($v2 is not newer than $v1)");                }                if (empty($options['register-only'])) {                    // when upgrading, remove old release's files first:                    if (PEAR::isError($err = $this->_deletePackageFiles($pkgname, $usechannel,                          true))) {                        if (!isset($options['ignore-errors'])) {                            return $this->raiseError($err);                        } else {                            if (!isset($options['soft'])) {                                $this->log(0, 'WARNING: ' . $err->getMessage());                            }                        }                    } else {                        $backedup = $err;                    }                }            }        }        // {{{ Copy files to dest dir ---------------------------------------        // info from the package it self we want to access from _installFile        $this->pkginfo = &$pkg;        // used to determine whether we should build any C code        $this->source_files = 0;        $savechannel = $this->config->get('default_channel');        if (empty($options['register-only']) && !is_dir($php_dir)) {            if (PEAR::isError(System::mkdir(array('-p'), $php_dir))) {                return $this->raiseError("no installation destination directory '$php_dir'\n");            }        }        $tmp_path = dirname($descfile);        if (substr($pkgfile, -4) != '.xml') {            $tmp_path .= DIRECTORY_SEPARATOR . $pkgname . '-' . $pkg->getVersion();        }        $this->configSet('default_channel', $channel);        // {{{ install files        $ver = $pkg->getPackagexmlVersion();        if (version_compare($ver, '2.0', '>=')) {            $filelist = $pkg->getInstallationFilelist();        } else {            $filelist = $pkg->getFileList();        }        if (PEAR::isError($filelist)) {            return $filelist;        }        $pkg->resetFilelist();        $pkg->setLastInstalledVersion($installregistry->packageInfo($pkg->getPackage(),            'version', $pkg->getChannel()));        foreach ($filelist as $file => $atts) {            if ($pkg->getPackagexmlVersion() == '1.0') {                $this->expectError(PEAR_INSTALLER_FAILED);                $res = $this->_installFile($file, $atts, $tmp_path, $options);                $this->popExpect();            } else {                $this->expectError(PEAR_INSTALLER_FAILED);

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?