downloader.php

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

PHP
1,643
字号
            }        }        PEAR::staticPopErrorHandling();        if ($hasfailed && (isset($this->_options['ignore-errors']) ||              isset($this->_options['nodeps']))) {            // this is probably not needed, but just in case            if (!isset($this->_options['soft'])) {                $this->log(0, 'WARNING: dependencies failed');            }        }    }    /**     * Retrieve the directory that downloads will happen in     * @access private     * @return string     */    function getDownloadDir()    {        if (isset($this->_downloadDir)) {            return $this->_downloadDir;        }        $downloaddir = $this->config->get('download_dir');        if (empty($downloaddir)) {            if (!class_exists('System')) {                require_once 'System.php';            }            if (PEAR::isError($downloaddir = System::mktemp('-d'))) {                return $downloaddir;            }            $this->log(3, '+ tmp dir created at ' . $downloaddir);        }        if (!is_writable($downloaddir)) {            if (PEAR::isError(System::mkdir(array('-p', $downloaddir))) ||                  !is_writable($downloaddir)) {                return PEAR::raiseError('download directory "' . $downloaddir .                    '" is not writeable.  Change download_dir config variable to ' .                    'a writeable dir');            }        }        return $this->_downloadDir = $downloaddir;    }    function setDownloadDir($dir)    {        if (!@is_writable($dir)) {            if (PEAR::isError(System::mkdir(array('-p', $dir)))) {                return PEAR::raiseError('download directory "' . $dir .                    '" is not writeable.  Change download_dir config variable to ' .                    'a writeable dir');            }        }        $this->_downloadDir = $dir;    }    // }}}    // {{{ configSet()    function configSet($key, $value, $layer = 'user', $channel = false)    {        $this->config->set($key, $value, $layer, $channel);        $this->_preferredState = $this->config->get('preferred_state', null, $channel);        if (!$this->_preferredState) {            // don't inadvertantly use a non-set preferred_state            $this->_preferredState = null;        }    }    // }}}    // {{{ setOptions()    function setOptions($options)    {        $this->_options = $options;    }    // }}}    // {{{ setOptions()    function getOptions()    {        return $this->_options;    }    // }}}    /**     * For simpler unit-testing     * @param PEAR_Config     * @param int     * @param string     */    function &getPackagefileObject(&$c, $d, $t = false)    {        if (!class_exists('PEAR_PackageFile')) {            require_once 'PEAR/PackageFile.php';        }        $a = &new PEAR_PackageFile($c, $d, $t);        return $a;    }    // {{{ _getPackageDownloadUrl()    /**     * @param array output of {@link parsePackageName()}     * @access private     */    function _getPackageDownloadUrl($parr)    {        $curchannel = $this->config->get('default_channel');        $this->configSet('default_channel', $parr['channel']);        // getDownloadURL returns an array.  On error, it only contains information        // on the latest release as array(version, info).  On success it contains        // array(version, info, download url string)        $state = isset($parr['state']) ? $parr['state'] : $this->config->get('preferred_state');        if (!$this->_registry->channelExists($parr['channel'])) {            do {                if ($this->config->get('auto_discover')) {                    if ($this->discover($parr['channel'])) {                        break;                    }                }                $this->configSet('default_channel', $curchannel);                return PEAR::raiseError('Unknown remote channel: ' . $remotechannel);            } while (false);        }        $chan = &$this->_registry->getChannel($parr['channel']);        if (PEAR::isError($chan)) {            return $chan;        }        $version = $this->_registry->packageInfo($parr['package'], 'version',            $parr['channel']);        $base2 = false;        if ($chan->supportsREST($this->config->get('preferred_mirror')) &&              (($base2 = $chan->getBaseURL('REST1.3', $this->config->get('preferred_mirror'))) ||              ($base = $chan->getBaseURL('REST1.0', $this->config->get('preferred_mirror'))))) {            if ($base2) {                $rest = &$this->config->getREST('1.3', $this->_options);                $base = $base2;            } else {                $rest = &$this->config->getREST('1.0', $this->_options);            }            if (!isset($parr['version']) && !isset($parr['state']) && $version                  && !isset($this->_options['downloadonly'])) {                $url = $rest->getDownloadURL($base, $parr, $state, $version);            } else {                $url = $rest->getDownloadURL($base, $parr, $state, false);            }            if (PEAR::isError($url)) {                $this->configSet('default_channel', $curchannel);                return $url;            }            if ($parr['channel'] != $curchannel) {                $this->configSet('default_channel', $curchannel);            }            if (!is_array($url)) {                return $url;            }            $url['raw'] = false; // no checking is necessary for REST            if (!is_array($url['info'])) {                return PEAR::raiseError('Invalid remote dependencies retrieved from REST - ' .                    'this should never happen');            }            PEAR::staticPushErrorHandling(PEAR_ERROR_RETURN);            $testversion = $this->_registry->packageInfo($url['package'], 'version',                $parr['channel']);            PEAR::staticPopErrorHandling();            if (!isset($this->_options['force']) &&                  !isset($this->_options['downloadonly']) &&                  !PEAR::isError($testversion) &&                  !isset($parr['group'])) {                if (version_compare($testversion, $url['version'], '>=')) {                    return PEAR::raiseError($this->_registry->parsedPackageNameToString(                        $parr, true) . ' is already installed and is newer than detected ' .                        'release version ' . $url['version'], -976);                }            }            if (isset($url['info']['required']) || $url['compatible']) {                require_once 'PEAR/PackageFile/v2.php';                $pf = new PEAR_PackageFile_v2;                $pf->setRawChannel($parr['channel']);                if ($url['compatible']) {                    $pf->setRawCompatible($url['compatible']);                }            } else {                require_once 'PEAR/PackageFile/v1.php';                $pf = new PEAR_PackageFile_v1;            }            $pf->setRawPackage($url['package']);            $pf->setDeps($url['info']);            if ($url['compatible']) {                $pf->setCompatible($url['compatible']);            }            $pf->setRawState($url['stability']);            $url['info'] = &$pf;            if (!extension_loaded("zlib") || isset($this->_options['nocompress'])) {                $ext = '.tar';            } else {                $ext = '.tgz';            }            if (is_array($url)) {                if (isset($url['url'])) {                    $url['url'] .= $ext;                }            }            return $url;        } elseif ($chan->supports('xmlrpc', 'package.getDownloadURL', false, '1.1')) {            // don't install with the old version information unless we're doing a plain            // vanilla simple installation.  If the user says to install a particular            // version or state, ignore the current installed version            if (!isset($parr['version']) && !isset($parr['state']) && $version                  && !isset($this->_options['downloadonly'])) {                $url = $this->_remote->call('package.getDownloadURL', $parr, $state, $version);            } else {                $url = $this->_remote->call('package.getDownloadURL', $parr, $state);            }        } else {            $url = $this->_remote->call('package.getDownloadURL', $parr, $state);        }        if (PEAR::isError($url)) {            return $url;        }        if ($parr['channel'] != $curchannel) {            $this->configSet('default_channel', $curchannel);        }        if (isset($url['__PEAR_ERROR_CLASS__'])) {            return PEAR::raiseError($url['message']);        }        if (!is_array($url)) {            return $url;        }        $url['raw'] = $url['info'];        if (isset($this->_options['downloadonly'])) {            $pkg = &$this->getPackagefileObject($this->config, $this->debug);        } else {            PEAR::staticPushErrorHandling(PEAR_ERROR_RETURN);            if (PEAR::isError($dir = $this->getDownloadDir())) {                PEAR::staticPopErrorHandling();                return $dir;            }            PEAR::staticPopErrorHandling();            $pkg = &$this->getPackagefileObject($this->config, $this->debug, $dir);        }        PEAR::staticPushErrorHandling(PEAR_ERROR_RETURN);        $pinfo = &$pkg->fromXmlString($url['info'], PEAR_VALIDATE_DOWNLOADING, 'remote');        PEAR::staticPopErrorHandling();        if (PEAR::isError($pinfo)) {            if (!isset($this->_options['soft'])) {                $this->log(0, $pinfo->getMessage());            }            return PEAR::raiseError('Remote package.xml is not valid - this should never happen');        }        $url['info'] = &$pinfo;        if (!extension_loaded("zlib") || isset($this->_options['nocompress'])) {            $ext = '.tar';        } else {            $ext = '.tgz';        }        if (is_array($url)) {            if (isset($url['url'])) {                $url['url'] .= $ext;            }        }        return $url;    }    // }}}    // {{{ getDepPackageDownloadUrl()    /**     * @param array dependency array     * @access private     */    function _getDepPackageDownloadUrl($dep, $parr)    {        $xsdversion = isset($dep['rel']) ? '1.0' : '2.0';        $curchannel = $this->config->get('default_channel');        if (isset($dep['uri'])) {            $xsdversion = '2.0';            $chan = &$this->_registry->getChannel('__uri');            if (PEAR::isError($chan)) {                return $chan;            }            $version = $this->_registry->packageInfo($dep['name'], 'version', '__uri');            $this->configSet('default_channel', '__uri');        } else {            if (isset($dep['channel'])) {                $remotechannel = $dep['channel'];            } else {                $remotechannel = 'pear.php.net';            }            if (!$this->_registry->channelExists($remotechannel)) {                do {                    if ($this->config->get('auto_discover')) {                        if ($this->discover($remotechannel)) {                            break;                        }                    }                    return PEAR::raiseError('Unknown remote channel: ' . $remotechannel);                } while (false);            }            $chan = &$this->_registry->getChannel($remotechannel);            if (PEAR::isError($chan)) {                return $chan;            }            $version = $this->_registry->packageInfo($dep['name'], 'version',                $remotechannel);            $this->configSet('default_channel', $remotechannel);        }        $state = isset($parr['state']) ? $parr['state'] : $this->config->get('preferred_state');        if (isset($parr['state']) && isset($parr['version'])) {            unset($parr['state']);        }        if (isset($dep['uri'])) {            $info = &$this->newDownloaderPackage($this);            PEAR::staticPushErrorHandling(PEAR_ERROR_RETURN);            $err = $info->initialize($dep);            PEAR::staticPopErrorHandling();            if (!$err) {                // skip parameters that were missed by preferred_state                return PEAR::raiseError('Cannot initialize dependency');            }            if (PEAR::isError($err)) {                if (!isset($this->_options['soft'])) {                    $this->log(0, $err->getMessage());                }                if (is_object($info)) {                    $param = $info->getChannel() . '/' . $info->getPackage();                }                return PEAR::raiseError('Package "' . $param . '" is not valid');            }            return $info;        } elseif ($chan->supportsREST($this->config->get('preferred_mirror')) &&

⌨️ 快捷键说明

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