Subversion Repositories Applications.gtt

Rev

Rev 94 | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 94 Rev 187
1
<?php
1
<?php
2
/**
2
/**
3
 * PEAR_Registry
3
 * PEAR_Registry
4
 *
4
 *
5
 * PHP versions 4 and 5
5
 * PHP versions 4 and 5
6
 *
6
 *
7
 * LICENSE: This source file is subject to version 3.0 of the PHP license
-
 
8
 * that is available through the world-wide-web at the following URI:
-
 
9
 * http://www.php.net/license/3_0.txt.  If you did not receive a copy of
-
 
10
 * the PHP License and are unable to obtain it through the web, please
-
 
11
 * send a note to license@php.net so we can mail you a copy immediately.
-
 
12
 *
-
 
13
 * @category   pear
7
 * @category   pear
14
 * @package    PEAR
8
 * @package    PEAR
15
 * @author     Stig Bakken <ssb@php.net>
9
 * @author     Stig Bakken <ssb@php.net>
16
 * @author     Tomas V. V. Cox <cox@idecnet.com>
10
 * @author     Tomas V. V. Cox <cox@idecnet.com>
17
 * @author     Greg Beaver <cellog@php.net>
11
 * @author     Greg Beaver <cellog@php.net>
18
 * @copyright  1997-2006 The PHP Group
12
 * @copyright  1997-2009 The Authors
19
 * @license    http://www.php.net/license/3_0.txt  PHP License 3.0
13
 * @license    http://opensource.org/licenses/bsd-license.php New BSD License
20
 * @version    CVS: $Id: Registry.php,v 1.159 2006/12/20 19:34:03 cellog Exp $
-
 
21
 * @link       http://pear.php.net/package/PEAR
14
 * @link       http://pear.php.net/package/PEAR
22
 * @since      File available since Release 0.1
15
 * @since      File available since Release 0.1
23
 */
16
 */
24
 
17
 
25
/**
18
/**
26
 * for PEAR_Error
19
 * for PEAR_Error
27
 */
20
 */
28
require_once 'PEAR.php';
21
require_once 'PEAR.php';
29
require_once 'PEAR/DependencyDB.php';
22
require_once 'PEAR/DependencyDB.php';
30
 
23
 
31
define('PEAR_REGISTRY_ERROR_LOCK',   -2);
24
define('PEAR_REGISTRY_ERROR_LOCK',         -2);
32
define('PEAR_REGISTRY_ERROR_FORMAT', -3);
25
define('PEAR_REGISTRY_ERROR_FORMAT',       -3);
33
define('PEAR_REGISTRY_ERROR_FILE',   -4);
26
define('PEAR_REGISTRY_ERROR_FILE',         -4);
34
define('PEAR_REGISTRY_ERROR_CONFLICT', -5);
27
define('PEAR_REGISTRY_ERROR_CONFLICT',     -5);
35
define('PEAR_REGISTRY_ERROR_CHANNEL_FILE', -6);
28
define('PEAR_REGISTRY_ERROR_CHANNEL_FILE', -6);
36
 
29
 
37
/**
30
/**
38
 * Administration class used to maintain the installed package database.
31
 * Administration class used to maintain the installed package database.
39
 * @category   pear
32
 * @category   pear
40
 * @package    PEAR
33
 * @package    PEAR
41
 * @author     Stig Bakken <ssb@php.net>
34
 * @author     Stig Bakken <ssb@php.net>
42
 * @author     Tomas V. V. Cox <cox@idecnet.com>
35
 * @author     Tomas V. V. Cox <cox@idecnet.com>
43
 * @author     Greg Beaver <cellog@php.net>
36
 * @author     Greg Beaver <cellog@php.net>
44
 * @copyright  1997-2006 The PHP Group
37
 * @copyright  1997-2009 The Authors
45
 * @license    http://www.php.net/license/3_0.txt  PHP License 3.0
38
 * @license    http://opensource.org/licenses/bsd-license.php New BSD License
46
 * @version    Release: 1.5.1
39
 * @version    Release: 1.10.1
47
 * @link       http://pear.php.net/package/PEAR
40
 * @link       http://pear.php.net/package/PEAR
48
 * @since      Class available since Release 1.4.0a1
41
 * @since      Class available since Release 1.4.0a1
49
 */
42
 */
50
class PEAR_Registry extends PEAR
43
class PEAR_Registry extends PEAR
51
{
44
{
52
    // {{{ properties
-
 
53
 
-
 
54
    /**
45
    /**
55
     * File containing all channel information.
46
     * File containing all channel information.
56
     * @var string
47
     * @var string
57
     */
48
     */
58
    var $channels = '';
49
    var $channels = '';
59
 
50
 
60
    /** Directory where registry files are stored.
51
    /** Directory where registry files are stored.
61
     * @var string
52
     * @var string
62
     */
53
     */
63
    var $statedir = '';
54
    var $statedir = '';
64
 
55
 
65
    /** File where the file map is stored
56
    /** File where the file map is stored
66
     * @var string
57
     * @var string
67
     */
58
     */
68
    var $filemap = '';
59
    var $filemap = '';
69
 
60
 
70
    /** Directory where registry files for channels are stored.
61
    /** Directory where registry files for channels are stored.
71
     * @var string
62
     * @var string
72
     */
63
     */
73
    var $channelsdir = '';
64
    var $channelsdir = '';
74
 
65
 
75
    /** Name of file used for locking the registry
66
    /** Name of file used for locking the registry
76
     * @var string
67
     * @var string
77
     */
68
     */
78
    var $lockfile = '';
69
    var $lockfile = '';
79
 
70
 
80
    /** File descriptor used during locking
71
    /** File descriptor used during locking
81
     * @var resource
72
     * @var resource
82
     */
73
     */
83
    var $lock_fp = null;
74
    var $lock_fp = null;
84
 
75
 
85
    /** Mode used during locking
76
    /** Mode used during locking
86
     * @var int
77
     * @var int
87
     */
78
     */
88
    var $lock_mode = 0; // XXX UNUSED
79
    var $lock_mode = 0; // XXX UNUSED
89
 
80
 
90
    /** Cache of package information.  Structure:
81
    /** Cache of package information.  Structure:
91
     * array(
82
     * array(
92
     *   'package' => array('id' => ... ),
83
     *   'package' => array('id' => ... ),
93
     *   ... )
84
     *   ... )
94
     * @var array
85
     * @var array
95
     */
86
     */
96
    var $pkginfo_cache = array();
87
    var $pkginfo_cache = array();
97
 
88
 
98
    /** Cache of file map.  Structure:
89
    /** Cache of file map.  Structure:
99
     * array( '/path/to/file' => 'package', ... )
90
     * array( '/path/to/file' => 'package', ... )
100
     * @var array
91
     * @var array
101
     */
92
     */
102
    var $filemap_cache = array();
93
    var $filemap_cache = array();
103
 
94
 
104
    /**
95
    /**
105
     * @var false|PEAR_ChannelFile
96
     * @var false|PEAR_ChannelFile
106
     */
97
     */
107
    var $_pearChannel;
98
    var $_pearChannel;
108
 
99
 
109
    /**
100
    /**
110
     * @var false|PEAR_ChannelFile
101
     * @var false|PEAR_ChannelFile
111
     */
102
     */
112
    var $_peclChannel;
103
    var $_peclChannel;
113
 
104
 
114
    /**
105
    /**
-
 
106
     * @var false|PEAR_ChannelFile
-
 
107
     */
-
 
108
    var $_docChannel;
-
 
109
 
-
 
110
    /**
115
     * @var PEAR_DependencyDB
111
     * @var PEAR_DependencyDB
116
     */
112
     */
117
    var $_dependencyDB;
113
    var $_dependencyDB;
118
 
114
 
119
    /**
115
    /**
120
     * @var PEAR_Config
116
     * @var PEAR_Config
121
     */
117
     */
122
    var $_config;
118
    var $_config;
123
    // }}}
-
 
124
 
-
 
125
    // {{{ constructor
-
 
126
 
119
 
127
    /**
120
    /**
128
     * PEAR_Registry constructor.
121
     * PEAR_Registry constructor.
129
     *
122
     *
130
     * @param string (optional) PEAR install directory (for .php files)
123
     * @param string (optional) PEAR install directory (for .php files)
131
     * @param PEAR_ChannelFile PEAR_ChannelFile object representing the PEAR channel, if
124
     * @param PEAR_ChannelFile PEAR_ChannelFile object representing the PEAR channel, if
132
     *        default values are not desired.  Only used the very first time a PEAR
125
     *        default values are not desired.  Only used the very first time a PEAR
133
     *        repository is initialized
126
     *        repository is initialized
134
     * @param PEAR_ChannelFile PEAR_ChannelFile object representing the PECL channel, if
127
     * @param PEAR_ChannelFile PEAR_ChannelFile object representing the PECL channel, if
135
     *        default values are not desired.  Only used the very first time a PEAR
128
     *        default values are not desired.  Only used the very first time a PEAR
136
     *        repository is initialized
129
     *        repository is initialized
137
     *
130
     *
138
     * @access public
131
     * @access public
139
     */
132
     */
140
    function PEAR_Registry($pear_install_dir = PEAR_INSTALL_DIR, $pear_channel = false,
133
    function __construct($pear_install_dir = PEAR_INSTALL_DIR, $pear_channel = false,
141
                           $pecl_channel = false)
134
                           $pecl_channel = false, $pear_metadata_dir = '')
142
    {
135
    {
143
        parent::PEAR();
136
        parent::__construct();
144
        $ds = DIRECTORY_SEPARATOR;
-
 
145
        $this->install_dir = $pear_install_dir;
-
 
146
        $this->channelsdir = $pear_install_dir.$ds.'.channels';
-
 
147
        $this->statedir = $pear_install_dir.$ds.'.registry';
137
        $this->setInstallDir($pear_install_dir, $pear_metadata_dir);
148
        $this->filemap  = $pear_install_dir.$ds.'.filemap';
-
 
149
        $this->lockfile = $pear_install_dir.$ds.'.lock';
-
 
150
        $this->_pearChannel = $pear_channel;
138
        $this->_pearChannel = $pear_channel;
151
        $this->_peclChannel = $pecl_channel;
139
        $this->_peclChannel = $pecl_channel;
152
        $this->_config = false;
140
        $this->_config      = false;
-
 
141
    }
-
 
142
 
-
 
143
    function setInstallDir($pear_install_dir = PEAR_INSTALL_DIR, $pear_metadata_dir = '')
-
 
144
    {
-
 
145
        $ds = DIRECTORY_SEPARATOR;
-
 
146
        $this->install_dir = $pear_install_dir;
-
 
147
        if (!$pear_metadata_dir) {
-
 
148
            $pear_metadata_dir = $pear_install_dir;
-
 
149
        }
-
 
150
        $this->channelsdir = $pear_metadata_dir.$ds.'.channels';
-
 
151
        $this->statedir    = $pear_metadata_dir.$ds.'.registry';
-
 
152
        $this->filemap     = $pear_metadata_dir.$ds.'.filemap';
-
 
153
        $this->lockfile    = $pear_metadata_dir.$ds.'.lock';
153
    }
154
    }
154
 
155
 
155
    function hasWriteAccess()
156
    function hasWriteAccess()
156
    {
157
    {
157
        if (!file_exists($this->install_dir)) {
158
        if (!file_exists($this->install_dir)) {
158
            $dir = $this->install_dir;
159
            $dir = $this->install_dir;
159
            while ($dir && $dir != '.') {
160
            while ($dir && $dir != '.') {
-
 
161
                $olddir = $dir;
160
                $dir = dirname($dir); // cd ..
162
                $dir    = dirname($dir);
161
                if ($dir != '.' && file_exists($dir)) {
163
                if ($dir != '.' && file_exists($dir)) {
162
                    if (is_writeable($dir)) {
164
                    if (is_writeable($dir)) {
163
                        return true;
165
                        return true;
164
                    } else {
-
 
165
                        return false;
-
 
166
                    }
166
                    }
-
 
167
 
-
 
168
                    return false;
-
 
169
                }
-
 
170
 
-
 
171
                if ($dir == $olddir) { // this can happen in safe mode
-
 
172
                    return @is_writable($dir);
167
                }
173
                }
168
            }
174
            }
-
 
175
 
169
            return false;
176
            return false;
170
        }
177
        }
-
 
178
 
171
        return is_writeable($this->install_dir);
179
        return is_writeable($this->install_dir);
172
    }
180
    }
173
 
181
 
174
    function setConfig(&$config)
182
    function setConfig(&$config, $resetInstallDir = true)
175
    {
183
    {
-
 
184
        $this->_config = &$config;
-
 
185
        if ($resetInstallDir) {
-
 
186
            $this->setInstallDir($config->get('php_dir'), $config->get('metadata_dir'));
176
        $this->_config = &$config;
187
        }
177
    }
188
    }
178
 
189
 
179
    function _initializeChannelDirs()
190
    function _initializeChannelDirs()
180
    {
191
    {
181
        static $running = false;
192
        static $running = false;
182
        if (!$running) {
193
        if (!$running) {
183
            $running = true;
194
            $running = true;
184
            $ds = DIRECTORY_SEPARATOR;
195
            $ds = DIRECTORY_SEPARATOR;
185
            if (!is_dir($this->channelsdir) ||
196
            if (!is_dir($this->channelsdir) ||
186
                  !file_exists($this->channelsdir . $ds . 'pear.php.net.reg') ||
197
                  !file_exists($this->channelsdir . $ds . 'pear.php.net.reg') ||
187
                  !file_exists($this->channelsdir . $ds . 'pecl.php.net.reg') ||
198
                  !file_exists($this->channelsdir . $ds . 'pecl.php.net.reg') ||
-
 
199
                  !file_exists($this->channelsdir . $ds . 'doc.php.net.reg') ||
188
                  !file_exists($this->channelsdir . $ds . '__uri.reg')) {
200
                  !file_exists($this->channelsdir . $ds . '__uri.reg')) {
189
                if (!file_exists($this->channelsdir . $ds . 'pear.php.net.reg')) {
201
                if (!file_exists($this->channelsdir . $ds . 'pear.php.net.reg')) {
190
                    $pear_channel = $this->_pearChannel;
202
                    $pear_channel = $this->_pearChannel;
191
                    if (!is_a($pear_channel, 'PEAR_ChannelFile') || !$pear_channel->validate()) {
203
                    if (!is_a($pear_channel, 'PEAR_ChannelFile') || !$pear_channel->validate()) {
192
                        if (!class_exists('PEAR_ChannelFile')) {
204
                        if (!class_exists('PEAR_ChannelFile')) {
193
                            require_once 'PEAR/ChannelFile.php';
205
                            require_once 'PEAR/ChannelFile.php';
194
                        }
206
                        }
-
 
207
 
195
                        $pear_channel = new PEAR_ChannelFile;
208
                        $pear_channel = new PEAR_ChannelFile;
196
                        $pear_channel->setName('pear.php.net');
-
 
197
                        $pear_channel->setAlias('pear');
209
                        $pear_channel->setAlias('pear');
198
                        $pear_channel->setServer('pear.php.net');
210
                        $pear_channel->setServer('pear.php.net');
199
                        $pear_channel->setSummary('PHP Extension and Application Repository');
211
                        $pear_channel->setSummary('PHP Extension and Application Repository');
200
                        $pear_channel->setDefaultPEARProtocols();
212
                        $pear_channel->setDefaultPEARProtocols();
201
                        $pear_channel->setBaseURL('REST1.0', 'http://pear.php.net/rest/');
213
                        $pear_channel->setBaseURL('REST1.0', 'http://pear.php.net/rest/');
202
                        $pear_channel->setBaseURL('REST1.1', 'http://pear.php.net/rest/');
214
                        $pear_channel->setBaseURL('REST1.1', 'http://pear.php.net/rest/');
-
 
215
                        $pear_channel->setBaseURL('REST1.3', 'http://pear.php.net/rest/');
-
 
216
                        //$pear_channel->setBaseURL('REST1.4', 'http://pear.php.net/rest/');
203
                    } else {
217
                    } else {
204
                        $pear_channel->setName('pear.php.net');
218
                        $pear_channel->setServer('pear.php.net');
205
                        $pear_channel->setAlias('pear');
219
                        $pear_channel->setAlias('pear');
206
                    }
220
                    }
-
 
221
 
207
                    $pear_channel->validate();
222
                    $pear_channel->validate();
208
                    $this->_addChannel($pear_channel);
223
                    $this->_addChannel($pear_channel);
209
                }
224
                }
-
 
225
 
210
                if (!file_exists($this->channelsdir . $ds . 'pecl.php.net.reg')) {
226
                if (!file_exists($this->channelsdir . $ds . 'pecl.php.net.reg')) {
211
                    $pecl_channel = $this->_peclChannel;
227
                    $pecl_channel = $this->_peclChannel;
212
                    if (!is_a($pecl_channel, 'PEAR_ChannelFile') || !$pecl_channel->validate()) {
228
                    if (!is_a($pecl_channel, 'PEAR_ChannelFile') || !$pecl_channel->validate()) {
213
                        if (!class_exists('PEAR_ChannelFile')) {
229
                        if (!class_exists('PEAR_ChannelFile')) {
214
                            require_once 'PEAR/ChannelFile.php';
230
                            require_once 'PEAR/ChannelFile.php';
215
                        }
231
                        }
-
 
232
 
216
                        $pecl_channel = new PEAR_ChannelFile;
233
                        $pecl_channel = new PEAR_ChannelFile;
217
                        $pecl_channel->setName('pecl.php.net');
-
 
218
                        $pecl_channel->setAlias('pecl');
234
                        $pecl_channel->setAlias('pecl');
219
                        $pecl_channel->setServer('pecl.php.net');
235
                        $pecl_channel->setServer('pecl.php.net');
220
                        $pecl_channel->setSummary('PHP Extension Community Library');
236
                        $pecl_channel->setSummary('PHP Extension Community Library');
221
                        $pecl_channel->setDefaultPEARProtocols();
237
                        $pecl_channel->setDefaultPEARProtocols();
222
                        $pecl_channel->setBaseURL('REST1.0', 'http://pecl.php.net/rest/');
238
                        $pecl_channel->setBaseURL('REST1.0', 'http://pecl.php.net/rest/');
223
                        $pecl_channel->setBaseURL('REST1.1', 'http://pecl.php.net/rest/');
239
                        $pecl_channel->setBaseURL('REST1.1', 'http://pecl.php.net/rest/');
224
                        $pecl_channel->setValidationPackage('PEAR_Validator_PECL', '1.0');
240
                        $pecl_channel->setValidationPackage('PEAR_Validator_PECL', '1.0');
225
                    } else {
241
                    } else {
226
                        $pecl_channel->setName('pecl.php.net');
242
                        $pecl_channel->setServer('pecl.php.net');
227
                        $pecl_channel->setAlias('pecl');
243
                        $pecl_channel->setAlias('pecl');
228
                    }
244
                    }
-
 
245
 
229
                    $pecl_channel->validate();
246
                    $pecl_channel->validate();
230
                    $this->_addChannel($pecl_channel);
247
                    $this->_addChannel($pecl_channel);
231
                }
248
                }
-
 
249
 
-
 
250
                if (!file_exists($this->channelsdir . $ds . 'doc.php.net.reg')) {
-
 
251
                    $doc_channel = $this->_docChannel;
-
 
252
                    if (!is_a($doc_channel, 'PEAR_ChannelFile') || !$doc_channel->validate()) {
-
 
253
                        if (!class_exists('PEAR_ChannelFile')) {
-
 
254
                            require_once 'PEAR/ChannelFile.php';
-
 
255
                        }
-
 
256
 
-
 
257
                        $doc_channel = new PEAR_ChannelFile;
-
 
258
                        $doc_channel->setAlias('phpdocs');
-
 
259
                        $doc_channel->setServer('doc.php.net');
-
 
260
                        $doc_channel->setSummary('PHP Documentation Team');
-
 
261
                        $doc_channel->setDefaultPEARProtocols();
-
 
262
                        $doc_channel->setBaseURL('REST1.0', 'http://doc.php.net/rest/');
-
 
263
                        $doc_channel->setBaseURL('REST1.1', 'http://doc.php.net/rest/');
-
 
264
                        $doc_channel->setBaseURL('REST1.3', 'http://doc.php.net/rest/');
-
 
265
                    } else {
-
 
266
                        $doc_channel->setServer('doc.php.net');
-
 
267
                        $doc_channel->setAlias('doc');
-
 
268
                    }
-
 
269
 
-
 
270
                    $doc_channel->validate();
-
 
271
                    $this->_addChannel($doc_channel);
-
 
272
                }
-
 
273
 
232
                if (!file_exists($this->channelsdir . $ds . '__uri.reg')) {
274
                if (!file_exists($this->channelsdir . $ds . '__uri.reg')) {
233
                    if (!class_exists('PEAR_ChannelFile')) {
275
                    if (!class_exists('PEAR_ChannelFile')) {
234
                        require_once 'PEAR/ChannelFile.php';
276
                        require_once 'PEAR/ChannelFile.php';
235
                    }
277
                    }
-
 
278
 
236
                    $private = new PEAR_ChannelFile;
279
                    $private = new PEAR_ChannelFile;
237
                    $private->setName('__uri');
280
                    $private->setName('__uri');
-
 
281
                    $private->setDefaultPEARProtocols();
238
                    $private->addFunction('xmlrpc', '1.0', '****');
282
                    $private->setBaseURL('REST1.0', '****');
239
                    $private->setSummary('Pseudo-channel for static packages');
283
                    $private->setSummary('Pseudo-channel for static packages');
240
                    $this->_addChannel($private);
284
                    $this->_addChannel($private);
241
                }
285
                }
242
                $this->_rebuildFileMap();
286
                $this->_rebuildFileMap();
243
            }
287
            }
-
 
288
 
244
            $running = false;
289
            $running = false;
245
        }
290
        }
246
    }
291
    }
247
 
292
 
248
    function _initializeDirs()
293
    function _initializeDirs()
249
    {
294
    {
250
        $ds = DIRECTORY_SEPARATOR;
295
        $ds = DIRECTORY_SEPARATOR;
251
        // XXX Compatibility code should be removed in the future
296
        // XXX Compatibility code should be removed in the future
252
        // rename all registry files if any to lowercase
297
        // rename all registry files if any to lowercase
253
        if (!OS_WINDOWS && file_exists($this->statedir) && is_dir($this->statedir) &&
298
        if (!OS_WINDOWS && file_exists($this->statedir) && is_dir($this->statedir) &&
254
              $handle = opendir($this->statedir)) {
299
              $handle = opendir($this->statedir)) {
255
            $dest = $this->statedir . $ds;
300
            $dest = $this->statedir . $ds;
256
            while (false !== ($file = readdir($handle))) {
301
            while (false !== ($file = readdir($handle))) {
257
                if (preg_match('/^.*[A-Z].*\.reg$/', $file)) {
302
                if (preg_match('/^.*[A-Z].*\.reg\\z/', $file)) {
258
                    rename($dest . $file, $dest . strtolower($file));
303
                    rename($dest . $file, $dest . strtolower($file));
259
                }
304
                }
260
            }
305
            }
261
            closedir($handle);
306
            closedir($handle);
262
        }
307
        }
-
 
308
 
263
        $this->_initializeChannelDirs();
309
        $this->_initializeChannelDirs();
264
        if (!file_exists($this->filemap)) {
310
        if (!file_exists($this->filemap)) {
265
            $this->_rebuildFileMap();
311
            $this->_rebuildFileMap();
266
        }
312
        }
267
        $this->_initializeDepDB();
313
        $this->_initializeDepDB();
268
    }
314
    }
269
 
315
 
270
    function _initializeDepDB()
316
    function _initializeDepDB()
271
    {
317
    {
272
        if (!isset($this->_dependencyDB)) {
318
        if (!isset($this->_dependencyDB)) {
273
            static $initializing = false;
319
            static $initializing = false;
274
            if (!$initializing) {
320
            if (!$initializing) {
275
                $initializing = true;
321
                $initializing = true;
276
                if (!$this->_config) { // never used?
322
                if (!$this->_config) { // never used?
277
                    if (OS_WINDOWS) {
-
 
278
                        $file = 'pear.ini';
-
 
279
                    } else {
-
 
280
                        $file = '.pearrc';
323
                    $file = OS_WINDOWS ? 'pear.ini' : '.pearrc';
281
                    }
-
 
282
                    $this->_config = &new PEAR_Config($this->statedir . DIRECTORY_SEPARATOR .
324
                    $this->_config = new PEAR_Config($this->statedir . DIRECTORY_SEPARATOR .
283
                        $file);
325
                        $file);
284
                    $this->_config->setRegistry($this);
326
                    $this->_config->setRegistry($this);
285
                    $this->_config->set('php_dir', $this->install_dir);
327
                    $this->_config->set('php_dir', $this->install_dir);
286
                }
328
                }
-
 
329
 
287
                $this->_dependencyDB = &PEAR_DependencyDB::singleton($this->_config);
330
                $this->_dependencyDB = &PEAR_DependencyDB::singleton($this->_config);
288
                if (PEAR::isError($this->_dependencyDB)) {
331
                if (PEAR::isError($this->_dependencyDB)) {
289
                    // attempt to recover by removing the dep db
332
                    // attempt to recover by removing the dep db
290
                    if (file_exists($this->_config->get('php_dir', null, 'pear.php.net') .
333
                    if (file_exists($this->_config->get('metadata_dir', null, 'pear.php.net') .
291
                        DIRECTORY_SEPARATOR . '.depdb')) {
334
                        DIRECTORY_SEPARATOR . '.depdb')) {
292
                        @unlink($this->_config->get('php_dir', null, 'pear.php.net') .
335
                        @unlink($this->_config->get('metadata_dir', null, 'pear.php.net') .
293
                            DIRECTORY_SEPARATOR . '.depdb');
336
                            DIRECTORY_SEPARATOR . '.depdb');
294
                    }
337
                    }
-
 
338
 
295
                    $this->_dependencyDB = &PEAR_DependencyDB::singleton($this->_config);
339
                    $this->_dependencyDB = &PEAR_DependencyDB::singleton($this->_config);
296
                    if (PEAR::isError($this->_dependencyDB)) {
340
                    if (PEAR::isError($this->_dependencyDB)) {
297
                        echo $this->_dependencyDB->getMessage();
341
                        echo $this->_dependencyDB->getMessage();
298
                        echo 'Unrecoverable error';
342
                        echo 'Unrecoverable error';
299
                        exit(1);
343
                        exit(1);
300
                    }
344
                    }
301
                }
345
                }
-
 
346
 
302
                $initializing = false;
347
                $initializing = false;
303
            }
348
            }
304
        }
349
        }
305
    }
350
    }
306
    // }}}
-
 
307
    // {{{ destructor
-
 
308
 
351
 
309
    /**
352
    /**
310
     * PEAR_Registry destructor.  Makes sure no locks are forgotten.
353
     * PEAR_Registry destructor.  Makes sure no locks are forgotten.
311
     *
354
     *
312
     * @access private
355
     * @access private
313
     */
356
     */
314
    function _PEAR_Registry()
357
    function _PEAR_Registry()
315
    {
358
    {
316
        parent::_PEAR();
359
        parent::_PEAR();
317
        if (is_resource($this->lock_fp)) {
360
        if (is_resource($this->lock_fp)) {
318
            $this->_unlock();
361
            $this->_unlock();
319
        }
362
        }
320
    }
363
    }
321
 
-
 
322
    // }}}
-
 
323
 
-
 
324
    // {{{ _assertStateDir()
-
 
325
 
364
 
326
    /**
365
    /**
327
     * Make sure the directory where we keep registry files exists.
366
     * Make sure the directory where we keep registry files exists.
328
     *
367
     *
329
     * @return bool TRUE if directory exists, FALSE if it could not be
368
     * @return bool TRUE if directory exists, FALSE if it could not be
330
     * created
369
     * created
331
     *
370
     *
332
     * @access private
371
     * @access private
333
     */
372
     */
334
    function _assertStateDir($channel = false)
373
    function _assertStateDir($channel = false)
335
    {
374
    {
336
        if ($channel && $this->_getChannelFromAlias($channel) != 'pear.php.net') {
375
        if ($channel && $this->_getChannelFromAlias($channel) != 'pear.php.net') {
337
            return $this->_assertChannelStateDir($channel);
376
            return $this->_assertChannelStateDir($channel);
338
        }
377
        }
-
 
378
 
339
        static $init = false;
379
        static $init = false;
340
        if (!file_exists($this->statedir)) {
380
        if (!file_exists($this->statedir)) {
341
            if (!$this->hasWriteAccess()) {
381
            if (!$this->hasWriteAccess()) {
342
                return false;
382
                return false;
343
            }
383
            }
-
 
384
 
344
            require_once 'System.php';
385
            require_once 'System.php';
345
            if (!System::mkdir(array('-p', $this->statedir))) {
386
            if (!System::mkdir(array('-p', $this->statedir))) {
346
                return $this->raiseError("could not create directory '{$this->statedir}'");
387
                return $this->raiseError("could not create directory '{$this->statedir}'");
347
            }
388
            }
348
            $init = true;
389
            $init = true;
349
        } elseif (!is_dir($this->statedir)) {
390
        } elseif (!is_dir($this->statedir)) {
350
            return $this->raiseError('Cannot create directory ' . $this->statedir . ', ' .
391
            return $this->raiseError('Cannot create directory ' . $this->statedir . ', ' .
351
                'it already exists and is not a directory');
392
                'it already exists and is not a directory');
352
        }
393
        }
-
 
394
 
353
        $ds = DIRECTORY_SEPARATOR;
395
        $ds = DIRECTORY_SEPARATOR;
354
        if (!file_exists($this->channelsdir)) {
396
        if (!file_exists($this->channelsdir)) {
355
            if (!file_exists($this->channelsdir . $ds . 'pear.php.net.reg') ||
397
            if (!file_exists($this->channelsdir . $ds . 'pear.php.net.reg') ||
356
                  !file_exists($this->channelsdir . $ds . 'pecl.php.net.reg') ||
398
                  !file_exists($this->channelsdir . $ds . 'pecl.php.net.reg') ||
-
 
399
                  !file_exists($this->channelsdir . $ds . 'doc.php.net.reg') ||
357
                  !file_exists($this->channelsdir . $ds . '__uri.reg')) {
400
                  !file_exists($this->channelsdir . $ds . '__uri.reg')) {
358
                $init = true;
401
                $init = true;
359
            }
402
            }
360
        } elseif (!is_dir($this->channelsdir)) {
403
        } elseif (!is_dir($this->channelsdir)) {
361
            return $this->raiseError('Cannot create directory ' . $this->channelsdir . ', ' .
404
            return $this->raiseError('Cannot create directory ' . $this->channelsdir . ', ' .
362
                'it already exists and is not a directory');
405
                'it already exists and is not a directory');
363
        }
406
        }
-
 
407
 
364
        if ($init) {
408
        if ($init) {
365
            static $running = false;
409
            static $running = false;
366
            if (!$running) {
410
            if (!$running) {
367
                $running = true;
411
                $running = true;
368
                $this->_initializeDirs();
412
                $this->_initializeDirs();
369
                $running = false;
413
                $running = false;
370
                $init = false;
414
                $init = false;
371
            }
415
            }
372
        } else {
416
        } else {
373
            $this->_initializeDepDB();
417
            $this->_initializeDepDB();
374
        }
418
        }
-
 
419
 
375
        return true;
420
        return true;
376
    }
421
    }
377
 
-
 
378
    // }}}
-
 
379
    // {{{ _assertChannelStateDir()
-
 
380
 
422
 
381
    /**
423
    /**
382
     * Make sure the directory where we keep registry files exists for a non-standard channel.
424
     * Make sure the directory where we keep registry files exists for a non-standard channel.
383
     *
425
     *
384
     * @param string channel name
426
     * @param string channel name
385
     * @return bool TRUE if directory exists, FALSE if it could not be
427
     * @return bool TRUE if directory exists, FALSE if it could not be
386
     * created
428
     * created
387
     *
429
     *
388
     * @access private
430
     * @access private
389
     */
431
     */
390
    function _assertChannelStateDir($channel)
432
    function _assertChannelStateDir($channel)
391
    {
433
    {
392
        $ds = DIRECTORY_SEPARATOR;
434
        $ds = DIRECTORY_SEPARATOR;
393
        if (!$channel || $this->_getChannelFromAlias($channel) == 'pear.php.net') {
435
        if (!$channel || $this->_getChannelFromAlias($channel) == 'pear.php.net') {
394
            if (!file_exists($this->channelsdir . $ds . 'pear.php.net.reg')) {
436
            if (!file_exists($this->channelsdir . $ds . 'pear.php.net.reg')) {
395
                $this->_initializeChannelDirs();
437
                $this->_initializeChannelDirs();
396
            }
438
            }
397
            return $this->_assertStateDir($channel);
439
            return $this->_assertStateDir($channel);
398
        }
440
        }
-
 
441
 
399
        $channelDir = $this->_channelDirectoryName($channel);
442
        $channelDir = $this->_channelDirectoryName($channel);
400
        if (!is_dir($this->channelsdir) ||
443
        if (!is_dir($this->channelsdir) ||
401
              !file_exists($this->channelsdir . $ds . 'pear.php.net.reg')) {
444
              !file_exists($this->channelsdir . $ds . 'pear.php.net.reg')) {
402
            $this->_initializeChannelDirs();
445
            $this->_initializeChannelDirs();
403
        }
446
        }
-
 
447
 
404
        if (!file_exists($channelDir)) {
448
        if (!file_exists($channelDir)) {
405
            if (!$this->hasWriteAccess()) {
449
            if (!$this->hasWriteAccess()) {
406
                return false;
450
                return false;
407
            }
451
            }
-
 
452
 
408
            require_once 'System.php';
453
            require_once 'System.php';
409
            if (!System::mkdir(array('-p', $channelDir))) {
454
            if (!System::mkdir(array('-p', $channelDir))) {
410
                return $this->raiseError("could not create directory '" . $channelDir .
455
                return $this->raiseError("could not create directory '" . $channelDir .
411
                    "'");
456
                    "'");
412
            }
457
            }
413
        } elseif (!is_dir($channelDir)) {
458
        } elseif (!is_dir($channelDir)) {
414
            return $this->raiseError("could not create directory '" . $channelDir .
459
            return $this->raiseError("could not create directory '" . $channelDir .
415
                "', already exists and is not a directory");
460
                "', already exists and is not a directory");
416
        }
461
        }
-
 
462
 
417
        return true;
463
        return true;
418
    }
464
    }
419
 
-
 
420
    // }}}
-
 
421
    // {{{ _assertChannelDir()
-
 
422
 
465
 
423
    /**
466
    /**
424
     * Make sure the directory where we keep registry files for channels exists
467
     * Make sure the directory where we keep registry files for channels exists
425
     *
468
     *
426
     * @return bool TRUE if directory exists, FALSE if it could not be
469
     * @return bool TRUE if directory exists, FALSE if it could not be
427
     * created
470
     * created
428
     *
471
     *
429
     * @access private
472
     * @access private
430
     */
473
     */
431
    function _assertChannelDir()
474
    function _assertChannelDir()
432
    {
475
    {
433
        if (!file_exists($this->channelsdir)) {
476
        if (!file_exists($this->channelsdir)) {
434
            if (!$this->hasWriteAccess()) {
477
            if (!$this->hasWriteAccess()) {
435
                return false;
478
                return false;
436
            }
479
            }
-
 
480
 
437
            require_once 'System.php';
481
            require_once 'System.php';
438
            if (!System::mkdir(array('-p', $this->channelsdir))) {
482
            if (!System::mkdir(array('-p', $this->channelsdir))) {
439
                return $this->raiseError("could not create directory '{$this->channelsdir}'");
483
                return $this->raiseError("could not create directory '{$this->channelsdir}'");
440
            }
484
            }
441
        } elseif (!is_dir($this->channelsdir)) {
485
        } elseif (!is_dir($this->channelsdir)) {
442
            return $this->raiseError("could not create directory '{$this->channelsdir}" .
486
            return $this->raiseError("could not create directory '{$this->channelsdir}" .
443
                "', it already exists and is not a directory");
487
                "', it already exists and is not a directory");
444
            
-
 
445
        }
488
        }
-
 
489
 
446
        if (!file_exists($this->channelsdir . DIRECTORY_SEPARATOR . '.alias')) {
490
        if (!file_exists($this->channelsdir . DIRECTORY_SEPARATOR . '.alias')) {
447
            if (!$this->hasWriteAccess()) {
491
            if (!$this->hasWriteAccess()) {
448
                return false;
492
                return false;
449
            }
493
            }
-
 
494
 
450
            require_once 'System.php';
495
            require_once 'System.php';
451
            if (!System::mkdir(array('-p', $this->channelsdir . DIRECTORY_SEPARATOR . '.alias'))) {
496
            if (!System::mkdir(array('-p', $this->channelsdir . DIRECTORY_SEPARATOR . '.alias'))) {
452
                return $this->raiseError("could not create directory '{$this->channelsdir}/.alias'");
497
                return $this->raiseError("could not create directory '{$this->channelsdir}/.alias'");
453
            }
498
            }
454
        } elseif (!is_dir($this->channelsdir . DIRECTORY_SEPARATOR . '.alias')) {
499
        } elseif (!is_dir($this->channelsdir . DIRECTORY_SEPARATOR . '.alias')) {
455
            return $this->raiseError("could not create directory '{$this->channelsdir}" .
500
            return $this->raiseError("could not create directory '{$this->channelsdir}" .
456
                "/.alias', it already exists and is not a directory");
501
                "/.alias', it already exists and is not a directory");
457
            
-
 
458
        }
502
        }
-
 
503
 
459
        return true;
504
        return true;
460
    }
505
    }
461
 
-
 
462
    // }}}
-
 
463
    // {{{ _packageFileName()
-
 
464
 
506
 
465
    /**
507
    /**
466
     * Get the name of the file where data for a given package is stored.
508
     * Get the name of the file where data for a given package is stored.
467
     *
509
     *
468
     * @param string channel name, or false if this is a PEAR package
510
     * @param string channel name, or false if this is a PEAR package
469
     * @param string package name
511
     * @param string package name
470
     *
512
     *
471
     * @return string registry file name
513
     * @return string registry file name
472
     *
514
     *
473
     * @access public
515
     * @access public
474
     */
516
     */
475
    function _packageFileName($package, $channel = false)
517
    function _packageFileName($package, $channel = false)
476
    {
518
    {
477
        if ($channel && $this->_getChannelFromAlias($channel) != 'pear.php.net') {
519
        if ($channel && $this->_getChannelFromAlias($channel) != 'pear.php.net') {
478
            return $this->_channelDirectoryName($channel) . DIRECTORY_SEPARATOR .
520
            return $this->_channelDirectoryName($channel) . DIRECTORY_SEPARATOR .
479
                strtolower($package) . '.reg';
521
                strtolower($package) . '.reg';
480
        }
522
        }
-
 
523
 
481
        return $this->statedir . DIRECTORY_SEPARATOR . strtolower($package) . '.reg';
524
        return $this->statedir . DIRECTORY_SEPARATOR . strtolower($package) . '.reg';
482
    }
525
    }
483
 
-
 
484
    // }}}
-
 
485
    // {{{ _channelFileName()
-
 
486
 
526
 
487
    /**
527
    /**
488
     * Get the name of the file where data for a given channel is stored.
528
     * Get the name of the file where data for a given channel is stored.
489
     * @param string channel name
529
     * @param string channel name
490
     * @return string registry file name
530
     * @return string registry file name
491
     */
531
     */
492
    function _channelFileName($channel, $noaliases = false)
532
    function _channelFileName($channel, $noaliases = false)
493
    {
533
    {
494
        if (!$noaliases) {
534
        if (!$noaliases) {
495
            if (file_exists($this->_getChannelAliasFileName($channel))) {
535
            if (file_exists($this->_getChannelAliasFileName($channel))) {
496
                $channel = implode('', file($this->_getChannelAliasFileName($channel)));
536
                $channel = implode('', file($this->_getChannelAliasFileName($channel)));
497
            }
537
            }
498
        }
538
        }
499
        return $this->channelsdir . DIRECTORY_SEPARATOR . str_replace('/', '_',
539
        return $this->channelsdir . DIRECTORY_SEPARATOR . str_replace('/', '_',
500
            strtolower($channel)) . '.reg';
540
            strtolower($channel)) . '.reg';
501
    }
541
    }
502
 
-
 
503
    // }}}
-
 
504
    // {{{ getChannelAliasFileName()
-
 
505
 
542
 
506
    /**
543
    /**
507
     * @param string
544
     * @param string
508
     * @return string
545
     * @return string
509
     */
546
     */
510
    function _getChannelAliasFileName($alias)
547
    function _getChannelAliasFileName($alias)
511
    {
548
    {
512
        return $this->channelsdir . DIRECTORY_SEPARATOR . '.alias' .
549
        return $this->channelsdir . DIRECTORY_SEPARATOR . '.alias' .
513
              DIRECTORY_SEPARATOR . str_replace('/', '_', strtolower($alias)) . '.txt';
550
              DIRECTORY_SEPARATOR . str_replace('/', '_', strtolower($alias)) . '.txt';
514
    }
551
    }
515
 
-
 
516
    // }}}
-
 
517
    // {{{ _getChannelFromAlias()
-
 
518
 
552
 
519
    /**
553
    /**
520
     * Get the name of a channel from its alias
554
     * Get the name of a channel from its alias
521
     */
555
     */
522
    function _getChannelFromAlias($channel)
556
    function _getChannelFromAlias($channel)
523
    {
557
    {
524
        if (!$this->_channelExists($channel)) {
558
        if (!$this->_channelExists($channel)) {
525
            if ($channel == 'pear.php.net') {
559
            if ($channel == 'pear.php.net') {
526
                return 'pear.php.net';
560
                return 'pear.php.net';
527
            }
561
            }
-
 
562
 
528
            if ($channel == 'pecl.php.net') {
563
            if ($channel == 'pecl.php.net') {
529
                return 'pecl.php.net';
564
                return 'pecl.php.net';
530
            }
565
            }
-
 
566
 
-
 
567
            if ($channel == 'doc.php.net') {
-
 
568
                return 'doc.php.net';
-
 
569
            }
-
 
570
 
531
            if ($channel == '__uri') {
571
            if ($channel == '__uri') {
532
                return '__uri';
572
                return '__uri';
533
            }
573
            }
-
 
574
 
534
            return false;
575
            return false;
535
        }
576
        }
-
 
577
 
536
        $channel = strtolower($channel);
578
        $channel = strtolower($channel);
537
        if (file_exists($this->_getChannelAliasFileName($channel))) {
579
        if (file_exists($this->_getChannelAliasFileName($channel))) {
538
            // translate an alias to an actual channel
580
            // translate an alias to an actual channel
539
            return implode('', file($this->_getChannelAliasFileName($channel)));
581
            return implode('', file($this->_getChannelAliasFileName($channel)));
540
        } else {
-
 
541
            return $channel;
-
 
542
        }
582
        }
-
 
583
 
-
 
584
        return $channel;
543
    }    
585
    }
544
    // }}}
-
 
545
    // {{{ _getChannelFromAlias()
-
 
546
 
586
 
547
    /**
587
    /**
548
     * Get the alias of a channel from its alias or its name
588
     * Get the alias of a channel from its alias or its name
549
     */
589
     */
550
    function _getAlias($channel)
590
    function _getAlias($channel)
551
    {
591
    {
552
        if (!$this->_channelExists($channel)) {
592
        if (!$this->_channelExists($channel)) {
553
            if ($channel == 'pear.php.net') {
593
            if ($channel == 'pear.php.net') {
554
                return 'pear';
594
                return 'pear';
555
            }
595
            }
-
 
596
 
556
            if ($channel == 'pecl.php.net') {
597
            if ($channel == 'pecl.php.net') {
557
                return 'pecl';
598
                return 'pecl';
558
            }
599
            }
-
 
600
 
-
 
601
            if ($channel == 'doc.php.net') {
-
 
602
                return 'phpdocs';
-
 
603
            }
-
 
604
 
559
            return false;
605
            return false;
560
        }
606
        }
-
 
607
 
561
        $channel = $this->_getChannel($channel);
608
        $channel = $this->_getChannel($channel);
562
        if (PEAR::isError($channel)) {
609
        if (PEAR::isError($channel)) {
563
            return $channel;
610
            return $channel;
564
        }
611
        }
-
 
612
 
565
        return $channel->getAlias();
613
        return $channel->getAlias();
566
    }    
614
    }
567
    // }}}
-
 
568
    // {{{ _channelDirectoryName()
-
 
569
 
615
 
570
    /**
616
    /**
571
     * Get the name of the file where data for a given package is stored.
617
     * Get the name of the file where data for a given package is stored.
572
     *
618
     *
573
     * @param string channel name, or false if this is a PEAR package
619
     * @param string channel name, or false if this is a PEAR package
574
     * @param string package name
620
     * @param string package name
575
     *
621
     *
576
     * @return string registry file name
622
     * @return string registry file name
577
     *
623
     *
578
     * @access public
624
     * @access public
579
     */
625
     */
580
    function _channelDirectoryName($channel)
626
    function _channelDirectoryName($channel)
581
    {
627
    {
582
        if (!$channel || $this->_getChannelFromAlias($channel) == 'pear.php.net') {
628
        if (!$channel || $this->_getChannelFromAlias($channel) == 'pear.php.net') {
583
            return $this->statedir;
629
            return $this->statedir;
584
        } else {
-
 
585
            $ch = $this->_getChannelFromAlias($channel);
-
 
586
            if (!$ch) {
-
 
587
                $ch = $channel;
-
 
588
            }
-
 
589
            return $this->statedir . DIRECTORY_SEPARATOR . strtolower('.channel.' .
-
 
590
                str_replace('/', '_', $ch));
-
 
591
        }
630
        }
592
    }
-
 
-
 
631
 
-
 
632
        $ch = $this->_getChannelFromAlias($channel);
-
 
633
        if (!$ch) {
593
 
634
            $ch = $channel;
-
 
635
        }
-
 
636
 
594
    // }}}
637
        return $this->statedir . DIRECTORY_SEPARATOR . strtolower('.channel.' .
-
 
638
            str_replace('/', '_', $ch));
595
    // {{{ _openPackageFile()
639
    }
596
 
640
 
597
    function _openPackageFile($package, $mode, $channel = false)
641
    function _openPackageFile($package, $mode, $channel = false)
598
    {
642
    {
599
        if (!$this->_assertStateDir($channel)) {
643
        if (!$this->_assertStateDir($channel)) {
600
            return null;
644
            return null;
601
        }
645
        }
-
 
646
 
602
        if (!in_array($mode, array('r', 'rb')) && !$this->hasWriteAccess()) {
647
        if (!in_array($mode, array('r', 'rb')) && !$this->hasWriteAccess()) {
603
            return null;
648
            return null;
604
        }
649
        }
-
 
650
 
605
        $file = $this->_packageFileName($package, $channel);
651
        $file = $this->_packageFileName($package, $channel);
606
        if (!file_exists($file) && $mode == 'r' || $mode == 'rb') {
652
        if (!file_exists($file) && $mode == 'r' || $mode == 'rb') {
607
            return null;
653
            return null;
608
        }
654
        }
-
 
655
 
609
        $fp = @fopen($file, $mode);
656
        $fp = @fopen($file, $mode);
610
        if (!$fp) {
657
        if (!$fp) {
611
            return null;
658
            return null;
612
        }
659
        }
-
 
660
 
613
        return $fp;
661
        return $fp;
614
    }
662
    }
615
 
-
 
616
    // }}}
-
 
617
    // {{{ _closePackageFile()
-
 
618
 
663
 
619
    function _closePackageFile($fp)
664
    function _closePackageFile($fp)
620
    {
665
    {
621
        fclose($fp);
666
        fclose($fp);
622
    }
667
    }
623
 
-
 
624
    // }}}
-
 
625
    // {{{ _openChannelFile()
-
 
626
 
668
 
627
    function _openChannelFile($channel, $mode)
669
    function _openChannelFile($channel, $mode)
628
    {
670
    {
629
        if (!$this->_assertChannelDir()) {
671
        if (!$this->_assertChannelDir()) {
630
            return null;
672
            return null;
631
        }
673
        }
-
 
674
 
632
        if (!in_array($mode, array('r', 'rb')) && !$this->hasWriteAccess()) {
675
        if (!in_array($mode, array('r', 'rb')) && !$this->hasWriteAccess()) {
633
            return null;
676
            return null;
634
        }
677
        }
-
 
678
 
635
        $file = $this->_channelFileName($channel);
679
        $file = $this->_channelFileName($channel);
636
        if (!file_exists($file) && $mode == 'r' || $mode == 'rb') {
680
        if (!file_exists($file) && $mode == 'r' || $mode == 'rb') {
637
            return null;
681
            return null;
638
        }
682
        }
-
 
683
 
639
        $fp = @fopen($file, $mode);
684
        $fp = @fopen($file, $mode);
640
        if (!$fp) {
685
        if (!$fp) {
641
            return null;
686
            return null;
642
        }
687
        }
-
 
688
 
643
        return $fp;
689
        return $fp;
644
    }
690
    }
645
 
-
 
646
    // }}}
-
 
647
    // {{{ _closePackageFile()
-
 
648
 
691
 
649
    function _closeChannelFile($fp)
692
    function _closeChannelFile($fp)
650
    {
693
    {
651
        fclose($fp);
694
        fclose($fp);
652
    }
695
    }
653
 
-
 
654
    // }}}
-
 
655
    // {{{ _rebuildFileMap()
-
 
656
 
696
 
657
    function _rebuildFileMap()
697
    function _rebuildFileMap()
658
    {
698
    {
659
        if (!class_exists('PEAR_Installer_Role')) {
699
        if (!class_exists('PEAR_Installer_Role')) {
660
            require_once 'PEAR/Installer/Role.php';
700
            require_once 'PEAR/Installer/Role.php';
661
        }
701
        }
-
 
702
 
662
        $channels = $this->_listAllPackages();
703
        $channels = $this->_listAllPackages();
663
        $files = array();
704
        $files = array();
664
        foreach ($channels as $channel => $packages) {
705
        foreach ($channels as $channel => $packages) {
665
            foreach ($packages as $package) {
706
            foreach ($packages as $package) {
666
                $version = $this->_packageInfo($package, 'version', $channel);
707
                $version = $this->_packageInfo($package, 'version', $channel);
667
                $filelist = $this->_packageInfo($package, 'filelist', $channel);
708
                $filelist = $this->_packageInfo($package, 'filelist', $channel);
668
                if (!is_array($filelist)) {
709
                if (!is_array($filelist)) {
669
                    continue;
710
                    continue;
670
                }
711
                }
-
 
712
 
671
                foreach ($filelist as $name => $attrs) {
713
                foreach ($filelist as $name => $attrs) {
672
                    if (isset($attrs['attribs'])) {
714
                    if (isset($attrs['attribs'])) {
673
                        $attrs = $attrs['attribs'];
715
                        $attrs = $attrs['attribs'];
674
                    }
716
                    }
-
 
717
 
675
                    // it is possible for conflicting packages in different channels to
718
                    // it is possible for conflicting packages in different channels to
676
                    // conflict with data files/doc files
719
                    // conflict with data files/doc files
677
                    if ($name == 'dirtree') {
720
                    if ($name == 'dirtree') {
678
                        continue;
721
                        continue;
679
                    }
722
                    }
-
 
723
 
680
                    if (isset($attrs['role']) && !in_array($attrs['role'],
724
                    if (isset($attrs['role']) && !in_array($attrs['role'],
681
                          PEAR_Installer_Role::getInstallableRoles())) {
725
                          PEAR_Installer_Role::getInstallableRoles())) {
682
                        // these are not installed
726
                        // these are not installed
683
                        continue;
727
                        continue;
684
                    }
728
                    }
-
 
729
 
685
                    if (isset($attrs['role']) && !in_array($attrs['role'],
730
                    if (isset($attrs['role']) && !in_array($attrs['role'],
686
                          PEAR_Installer_Role::getBaseinstallRoles())) {
731
                          PEAR_Installer_Role::getBaseinstallRoles())) {
687
                        $attrs['baseinstalldir'] = $package;
732
                        $attrs['baseinstalldir'] = $package;
688
                    }
733
                    }
-
 
734
 
689
                    if (isset($attrs['baseinstalldir'])) {
735
                    if (isset($attrs['baseinstalldir'])) {
690
                        $file = $attrs['baseinstalldir'].DIRECTORY_SEPARATOR.$name;
736
                        $file = $attrs['baseinstalldir'].DIRECTORY_SEPARATOR.$name;
691
                    } else {
737
                    } else {
692
                        $file = $name;
738
                        $file = $name;
693
                    }
739
                    }
-
 
740
 
694
                    $file = preg_replace(',^/+,', '', $file);
741
                    $file = preg_replace(',^/+,', '', $file);
695
                    if ($channel != 'pear.php.net') {
742
                    if ($channel != 'pear.php.net') {
-
 
743
                        if (!isset($files[$attrs['role']])) {
-
 
744
                            $files[$attrs['role']] = array();
-
 
745
                        }
696
                        $files[$attrs['role']][$file] = array(strtolower($channel),
746
                        $files[$attrs['role']][$file] = array(strtolower($channel),
697
                            strtolower($package));
747
                            strtolower($package));
698
                    } else {
748
                    } else {
699
                        if (!is_array($files)) {
-
 
700
                            $file = array();
-
 
701
                        }
-
 
702
                        if (!isset($files[$attrs['role']])) {
749
                        if (!isset($files[$attrs['role']])) {
703
                            $files[$attrs['role']] = array();
750
                            $files[$attrs['role']] = array();
704
                        }
751
                        }
705
                        $files[$attrs['role']][$file] = strtolower($package);
752
                        $files[$attrs['role']][$file] = strtolower($package);
706
                    }
753
                    }
707
                }
754
                }
708
            }
755
            }
709
        }
756
        }
-
 
757
 
-
 
758
 
710
        $this->_assertStateDir();
759
        $this->_assertStateDir();
711
        if (!$this->hasWriteAccess()) {
760
        if (!$this->hasWriteAccess()) {
712
            return false;
761
            return false;
713
        }
762
        }
-
 
763
 
714
        $fp = @fopen($this->filemap, 'wb');
764
        $fp = @fopen($this->filemap, 'wb');
715
        if (!$fp) {
765
        if (!$fp) {
716
            return false;
766
            return false;
717
        }
767
        }
-
 
768
 
718
        $this->filemap_cache = $files;
769
        $this->filemap_cache = $files;
719
        fwrite($fp, serialize($files));
770
        fwrite($fp, serialize($files));
720
        fclose($fp);
771
        fclose($fp);
721
        return true;
772
        return true;
722
    }
773
    }
723
 
-
 
724
    // }}}
-
 
725
    // {{{ _readFileMap()
-
 
726
 
774
 
727
    function _readFileMap()
775
    function _readFileMap()
728
    {
776
    {
729
        if (!file_exists($this->filemap)) {
777
        if (!file_exists($this->filemap)) {
730
            return array();
778
            return array();
731
        }
779
        }
-
 
780
 
732
        $fp = @fopen($this->filemap, 'r');
781
        $fp = @fopen($this->filemap, 'r');
733
        if (!$fp) {
782
        if (!$fp) {
734
            return $this->raiseError('PEAR_Registry: could not open filemap "' . $this->filemap . '"', PEAR_REGISTRY_ERROR_FILE, null, null, $php_errormsg);
783
            return $this->raiseError('PEAR_Registry: could not open filemap "' . $this->filemap . '"', PEAR_REGISTRY_ERROR_FILE, null, null, $php_errormsg);
735
        }
784
        }
-
 
785
 
736
        clearstatcache();
786
        clearstatcache();
737
        $rt = get_magic_quotes_runtime();
-
 
738
        set_magic_quotes_runtime(0);
-
 
739
        $fsize = filesize($this->filemap);
787
        $fsize = filesize($this->filemap);
740
        fclose($fp);
788
        fclose($fp);
741
        $data = file_get_contents($this->filemap);
789
        $data = file_get_contents($this->filemap);
742
        set_magic_quotes_runtime($rt);
-
 
743
        $tmp = unserialize($data);
790
        $tmp = unserialize($data);
744
        if (!$tmp && $fsize > 7) {
791
        if (!$tmp && $fsize > 7) {
745
            return $this->raiseError('PEAR_Registry: invalid filemap data', PEAR_REGISTRY_ERROR_FORMAT, null, null, $data);
792
            return $this->raiseError('PEAR_Registry: invalid filemap data', PEAR_REGISTRY_ERROR_FORMAT, null, null, $data);
746
        }
793
        }
-
 
794
 
747
        $this->filemap_cache = $tmp;
795
        $this->filemap_cache = $tmp;
748
        return true;
796
        return true;
749
    }
797
    }
750
 
-
 
751
    // }}}
-
 
752
    // {{{ _lock()
-
 
753
 
798
 
754
    /**
799
    /**
755
     * Lock the registry.
800
     * Lock the registry.
756
     *
801
     *
757
     * @param integer lock mode, one of LOCK_EX, LOCK_SH or LOCK_UN.
802
     * @param integer lock mode, one of LOCK_EX, LOCK_SH or LOCK_UN.
758
     *                See flock manual for more information.
803
     *                See flock manual for more information.
759
     *
804
     *
760
     * @return bool TRUE on success, FALSE if locking failed, or a
805
     * @return bool TRUE on success, FALSE if locking failed, or a
761
     *              PEAR error if some other error occurs (such as the
806
     *              PEAR error if some other error occurs (such as the
762
     *              lock file not being writable).
807
     *              lock file not being writable).
763
     *
808
     *
764
     * @access private
809
     * @access private
765
     */
810
     */
766
    function _lock($mode = LOCK_EX)
811
    function _lock($mode = LOCK_EX)
767
    {
812
    {
768
        if (!eregi('Windows 9', php_uname())) {
813
        if (stristr(php_uname(), 'Windows 9')) {
769
            if ($mode != LOCK_UN && is_resource($this->lock_fp)) {
-
 
770
                // XXX does not check type of lock (LOCK_SH/LOCK_EX)
-
 
771
                return true;
814
            return true;
772
            }
-
 
773
            if (!$this->_assertStateDir()) {
-
 
774
                if ($mode == LOCK_EX) {
-
 
775
                    return $this->raiseError('Registry directory is not writeable by the current user');
-
 
776
                } else {
-
 
777
                    return true;
-
 
778
                }
-
 
779
            }
-
 
780
            $open_mode = 'w';
-
 
781
            // XXX People reported problems with LOCK_SH and 'w'
-
 
782
            if ($mode === LOCK_SH || $mode === LOCK_UN) {
-
 
783
                if (!file_exists($this->lockfile)) {
-
 
784
                    touch($this->lockfile);
-
 
785
                }
-
 
786
                $open_mode = 'r';
-
 
787
            }
815
        }
788
 
816
 
789
            if (!is_resource($this->lock_fp)) {
817
        if ($mode != LOCK_UN && is_resource($this->lock_fp)) {
-
 
818
            // XXX does not check type of lock (LOCK_SH/LOCK_EX)
-
 
819
            return true;
-
 
820
        }
-
 
821
 
-
 
822
        if (!$this->_assertStateDir()) {
-
 
823
            if ($mode == LOCK_EX) {
790
                $this->lock_fp = @fopen($this->lockfile, $open_mode);
824
                return $this->raiseError('Registry directory is not writeable by the current user');
-
 
825
            }
-
 
826
 
-
 
827
            return true;
-
 
828
        }
-
 
829
 
791
            }
830
        $open_mode = 'w';
792
 
831
        // XXX People reported problems with LOCK_SH and 'w'
793
            if (!is_resource($this->lock_fp)) {
832
        if ($mode === LOCK_SH || $mode === LOCK_UN) {
794
                return $this->raiseError("could not create lock file" .
833
            if (!file_exists($this->lockfile)) {
-
 
834
                touch($this->lockfile);
-
 
835
            }
-
 
836
            $open_mode = 'r';
-
 
837
        }
-
 
838
 
-
 
839
        if (!is_resource($this->lock_fp)) {
-
 
840
            $this->lock_fp = @fopen($this->lockfile, $open_mode);
-
 
841
        }
-
 
842
 
-
 
843
        if (!is_resource($this->lock_fp)) {
-
 
844
            $this->lock_fp = null;
-
 
845
            return $this->raiseError("could not create lock file" .
-
 
846
                                     (isset($php_errormsg) ? ": " . $php_errormsg : ""));
795
                                         (isset($php_errormsg) ? ": " . $php_errormsg : ""));
847
        }
796
            }
848
 
797
            if (!(int)flock($this->lock_fp, $mode)) {
849
        if (!(int)flock($this->lock_fp, $mode)) {
798
                switch ($mode) {
850
            switch ($mode) {
799
                    case LOCK_SH: $str = 'shared';    break;
851
                case LOCK_SH: $str = 'shared';    break;
800
                    case LOCK_EX: $str = 'exclusive'; break;
852
                case LOCK_EX: $str = 'exclusive'; break;
801
                    case LOCK_UN: $str = 'unlock';    break;
-
 
802
                    default:      $str = 'unknown';   break;
-
 
803
                }
-
 
804
                return $this->raiseError("could not acquire $str lock ($this->lockfile)",
853
                case LOCK_UN: $str = 'unlock';    break;
-
 
854
                default:      $str = 'unknown';   break;
-
 
855
            }
-
 
856
 
-
 
857
            //is resource at this point, close it on error.
-
 
858
            fclose($this->lock_fp);
-
 
859
            $this->lock_fp = null;
805
                                         PEAR_REGISTRY_ERROR_LOCK);
860
            return $this->raiseError("could not acquire $str lock ($this->lockfile)",
-
 
861
                                     PEAR_REGISTRY_ERROR_LOCK);
806
            }
862
        }
807
        }
863
 
808
        return true;
864
        return true;
809
    }
865
    }
810
 
-
 
811
    // }}}
-
 
812
    // {{{ _unlock()
-
 
813
 
866
 
814
    function _unlock()
867
    function _unlock()
815
    {
868
    {
816
        $ret = $this->_lock(LOCK_UN);
869
        $ret = $this->_lock(LOCK_UN);
817
        if (is_resource($this->lock_fp)) {
870
        if (is_resource($this->lock_fp)) {
818
            fclose($this->lock_fp);
871
            fclose($this->lock_fp);
819
        }
872
        }
-
 
873
 
820
        $this->lock_fp = null;
874
        $this->lock_fp = null;
821
        return $ret;
875
        return $ret;
822
    }
876
    }
823
 
-
 
824
    // }}}
-
 
825
    // {{{ _packageExists()
-
 
826
 
877
 
827
    function _packageExists($package, $channel = false)
878
    function _packageExists($package, $channel = false)
828
    {
879
    {
829
        return file_exists($this->_packageFileName($package, $channel));
880
        return file_exists($this->_packageFileName($package, $channel));
830
    }
881
    }
831
 
-
 
832
    // }}}
-
 
833
    // {{{ _channelExists()
-
 
834
 
882
 
835
    /**
883
    /**
-
 
884
     * Determine whether a channel exists in the registry
836
     * Determine whether a channel exists in the registry
885
     *
837
     * @param string Channel name
886
     * @param string Channel name
838
     * @param bool if true, then aliases will be ignored
887
     * @param bool if true, then aliases will be ignored
839
     * @return boolean
888
     * @return boolean
840
     */
889
     */
841
    function _channelExists($channel, $noaliases = false)
890
    function _channelExists($channel, $noaliases = false)
842
    {
891
    {
843
        $a = file_exists($this->_channelFileName($channel, $noaliases));
892
        $a = file_exists($this->_channelFileName($channel, $noaliases));
844
        if (!$a && $channel == 'pear.php.net') {
893
        if (!$a && $channel == 'pear.php.net') {
845
            return true;
894
            return true;
846
        }
895
        }
-
 
896
 
847
        if (!$a && $channel == 'pecl.php.net') {
897
        if (!$a && $channel == 'pecl.php.net') {
848
            return true;
898
            return true;
849
        }
899
        }
-
 
900
 
-
 
901
        if (!$a && $channel == 'doc.php.net') {
-
 
902
            return true;
-
 
903
        }
-
 
904
 
850
        return $a;
905
        return $a;
851
    }
906
    }
-
 
907
 
-
 
908
    /**
-
 
909
     * Determine whether a mirror exists within the deafult channel in the registry
-
 
910
     *
-
 
911
     * @param string Channel name
-
 
912
     * @param string Mirror name
-
 
913
     *
-
 
914
     * @return boolean
-
 
915
     */
-
 
916
    function _mirrorExists($channel, $mirror)
-
 
917
    {
-
 
918
        $data = $this->_channelInfo($channel);
-
 
919
        if (!isset($data['servers']['mirror'])) {
852
 
920
            return false;
-
 
921
        }
-
 
922
 
-
 
923
        foreach ($data['servers']['mirror'] as $m) {
-
 
924
            if ($m['attribs']['host'] == $mirror) {
-
 
925
                return true;
-
 
926
            }
-
 
927
        }
853
    // }}}
928
 
-
 
929
        return false;
854
    // {{{ _addChannel()
930
    }
855
 
931
 
856
    /**
932
    /**
857
     * @param PEAR_ChannelFile Channel object
933
     * @param PEAR_ChannelFile Channel object
858
     * @param donotuse
934
     * @param donotuse
859
     * @param string Last-Modified HTTP tag from remote request
935
     * @param string Last-Modified HTTP tag from remote request
860
     * @return boolean|PEAR_Error True on creation, false if it already exists
936
     * @return boolean|PEAR_Error True on creation, false if it already exists
861
     */
937
     */
862
    function _addChannel($channel, $update = false, $lastmodified = false)
938
    function _addChannel($channel, $update = false, $lastmodified = false)
863
    {
939
    {
864
        if (!is_a($channel, 'PEAR_ChannelFile')) {
940
        if (!is_a($channel, 'PEAR_ChannelFile')) {
865
            return false;
941
            return false;
866
        }
942
        }
-
 
943
 
867
        if (!$channel->validate()) {
944
        if (!$channel->validate()) {
868
            return false;
945
            return false;
869
        }
946
        }
-
 
947
 
870
        if (file_exists($this->_channelFileName($channel->getName()))) {
948
        if (file_exists($this->_channelFileName($channel->getName()))) {
871
            if (!$update) {
949
            if (!$update) {
872
                return false;
950
                return false;
873
            }
951
            }
-
 
952
 
874
            $checker = $this->_getChannel($channel->getName());
953
            $checker = $this->_getChannel($channel->getName());
875
            if (PEAR::isError($checker)) {
954
            if (PEAR::isError($checker)) {
876
                return $checker;
955
                return $checker;
877
            }
956
            }
-
 
957
 
878
            if ($channel->getAlias() != $checker->getAlias()) {
958
            if ($channel->getAlias() != $checker->getAlias()) {
879
                if (file_exists($this->_getChannelAliasFileName($checker->getAlias()))) {
959
                if (file_exists($this->_getChannelAliasFileName($checker->getAlias()))) {
880
                    @unlink($this->_getChannelAliasFileName($checker->getAlias()));
960
                    @unlink($this->_getChannelAliasFileName($checker->getAlias()));
881
                }
961
                }
882
            }
962
            }
883
        } else {
963
        } else {
884
            if ($update && !in_array($channel->getName(), array('pear.php.net', 'pecl.php.net'))) {
964
            if ($update && !in_array($channel->getName(), array('pear.php.net', 'pecl.php.net', 'doc.php.net'))) {
885
                return false;
965
                return false;
886
            }
966
            }
887
        }
967
        }
-
 
968
 
888
        $ret = $this->_assertChannelDir();
969
        $ret = $this->_assertChannelDir();
889
        if (PEAR::isError($ret)) {
970
        if (PEAR::isError($ret)) {
890
            return $ret;
971
            return $ret;
891
        }
972
        }
-
 
973
 
892
        $ret = $this->_assertChannelStateDir($channel->getName());
974
        $ret = $this->_assertChannelStateDir($channel->getName());
893
        if (PEAR::isError($ret)) {
975
        if (PEAR::isError($ret)) {
894
            return $ret;
976
            return $ret;
895
        }
977
        }
-
 
978
 
896
        if ($channel->getAlias() != $channel->getName()) {
979
        if ($channel->getAlias() != $channel->getName()) {
897
            if (file_exists($this->_getChannelAliasFileName($channel->getAlias())) &&
980
            if (file_exists($this->_getChannelAliasFileName($channel->getAlias())) &&
898
                  $this->_getChannelFromAlias($channel->getAlias()) != $channel->getName()) {
981
                  $this->_getChannelFromAlias($channel->getAlias()) != $channel->getName()) {
899
                $channel->setAlias($channel->getName());
982
                $channel->setAlias($channel->getName());
900
            }
983
            }
-
 
984
 
901
            if (!$this->hasWriteAccess()) {
985
            if (!$this->hasWriteAccess()) {
902
                return false;
986
                return false;
903
            }
987
            }
-
 
988
 
904
            $fp = @fopen($this->_getChannelAliasFileName($channel->getAlias()), 'w');
989
            $fp = @fopen($this->_getChannelAliasFileName($channel->getAlias()), 'w');
905
            if (!$fp) {
990
            if (!$fp) {
906
                return false;
991
                return false;
907
            }
992
            }
-
 
993
 
908
            fwrite($fp, $channel->getName());
994
            fwrite($fp, $channel->getName());
909
            fclose($fp);
995
            fclose($fp);
910
        }
996
        }
-
 
997
 
911
        if (!$this->hasWriteAccess()) {
998
        if (!$this->hasWriteAccess()) {
912
            return false;
999
            return false;
913
        }
1000
        }
-
 
1001
 
914
        $fp = @fopen($this->_channelFileName($channel->getName()), 'wb');
1002
        $fp = @fopen($this->_channelFileName($channel->getName()), 'wb');
915
        if (!$fp) {
1003
        if (!$fp) {
916
            return false;
1004
            return false;
917
        }
1005
        }
-
 
1006
 
918
        $info = $channel->toArray();
1007
        $info = $channel->toArray();
919
        if ($lastmodified) {
1008
        if ($lastmodified) {
920
            $info['_lastmodified'] = $lastmodified;
1009
            $info['_lastmodified'] = $lastmodified;
921
        } else {
1010
        } else {
922
            $info['_lastmodified'] = date('r');
1011
            $info['_lastmodified'] = date('r');
923
        }
1012
        }
-
 
1013
 
924
        fwrite($fp, serialize($info));
1014
        fwrite($fp, serialize($info));
925
        fclose($fp);
1015
        fclose($fp);
926
        return true;
1016
        return true;
927
    }
1017
    }
928
 
-
 
929
    // }}}
-
 
930
    // {{{ _deleteChannel()
-
 
931
 
1018
 
932
    /**
1019
    /**
933
     * Deletion fails if there are any packages installed from the channel
1020
     * Deletion fails if there are any packages installed from the channel
934
     * @param string|PEAR_ChannelFile channel name
1021
     * @param string|PEAR_ChannelFile channel name
935
     * @return boolean|PEAR_Error True on deletion, false if it doesn't exist
1022
     * @return boolean|PEAR_Error True on deletion, false if it doesn't exist
936
     */
1023
     */
937
    function _deleteChannel($channel)
1024
    function _deleteChannel($channel)
938
    {
1025
    {
939
        if (!is_string($channel)) {
1026
        if (!is_string($channel)) {
940
            if (is_a($channel, 'PEAR_ChannelFile')) {
1027
            if (!is_a($channel, 'PEAR_ChannelFile')) {
941
                if (!$channel->validate()) {
-
 
942
                    return false;
-
 
943
                }
-
 
944
                $channel = $channel->getName();
-
 
945
            } else {
-
 
946
                return false;
1028
                return false;
947
            }
1029
            }
-
 
1030
 
-
 
1031
            if (!$channel->validate()) {
-
 
1032
                return false;
-
 
1033
            }
-
 
1034
            $channel = $channel->getName();
948
        }
1035
        }
-
 
1036
 
949
        if ($this->_getChannelFromAlias($channel) == '__uri') {
1037
        if ($this->_getChannelFromAlias($channel) == '__uri') {
950
            return false;
1038
            return false;
951
        }
1039
        }
-
 
1040
 
952
        if ($this->_getChannelFromAlias($channel) == 'pecl.php.net') {
1041
        if ($this->_getChannelFromAlias($channel) == 'pecl.php.net') {
953
            return false;
1042
            return false;
954
        }
1043
        }
-
 
1044
 
-
 
1045
        if ($this->_getChannelFromAlias($channel) == 'doc.php.net') {
-
 
1046
            return false;
-
 
1047
        }
-
 
1048
 
955
        if (!$this->_channelExists($channel)) {
1049
        if (!$this->_channelExists($channel)) {
956
            return false;
1050
            return false;
957
        }
1051
        }
-
 
1052
 
958
        if (!$channel || $this->_getChannelFromAlias($channel) == 'pear.php.net') {
1053
        if (!$channel || $this->_getChannelFromAlias($channel) == 'pear.php.net') {
959
            return false;
1054
            return false;
960
        }
1055
        }
-
 
1056
 
961
        $channel = $this->_getChannelFromAlias($channel);
1057
        $channel = $this->_getChannelFromAlias($channel);
962
        if ($channel == 'pear.php.net') {
1058
        if ($channel == 'pear.php.net') {
963
            return false;
1059
            return false;
964
        }
1060
        }
-
 
1061
 
965
        $test = $this->_listChannelPackages($channel);
1062
        $test = $this->_listChannelPackages($channel);
966
        if (count($test)) {
1063
        if (count($test)) {
967
            return false;
1064
            return false;
968
        }
1065
        }
-
 
1066
 
969
        $test = @rmdir($this->_channelDirectoryName($channel));
1067
        $test = @rmdir($this->_channelDirectoryName($channel));
970
        if (!$test) {
1068
        if (!$test) {
971
            return false;
1069
            return false;
972
        }
1070
        }
-
 
1071
 
973
        $file = $this->_getChannelAliasFileName($this->_getAlias($channel));
1072
        $file = $this->_getChannelAliasFileName($this->_getAlias($channel));
974
        if (file_exists($file)) {
1073
        if (file_exists($file)) {
975
            $test = @unlink($file);
1074
            $test = @unlink($file);
976
            if (!$test) {
1075
            if (!$test) {
977
                return false;
1076
                return false;
978
            }
1077
            }
979
        }
1078
        }
-
 
1079
 
980
        $file = $this->_channelFileName($channel);
1080
        $file = $this->_channelFileName($channel);
981
        $ret = true;
1081
        $ret = true;
982
        if (file_exists($file)) {
1082
        if (file_exists($file)) {
983
            $ret = @unlink($file);
1083
            $ret = @unlink($file);
984
        }
1084
        }
-
 
1085
 
985
        return $ret;
1086
        return $ret;
986
    }
1087
    }
987
 
-
 
988
    // }}}
-
 
989
    // {{{ _isChannelAlias()
-
 
990
 
1088
 
991
    /**
1089
    /**
992
     * Determine whether a channel exists in the registry
1090
     * Determine whether a channel exists in the registry
993
     * @param string Channel Alias
1091
     * @param string Channel Alias
994
     * @return boolean
1092
     * @return boolean
995
     */
1093
     */
996
    function _isChannelAlias($alias)
1094
    function _isChannelAlias($alias)
997
    {
1095
    {
998
        return file_exists($this->_getChannelAliasFileName($alias));
1096
        return file_exists($this->_getChannelAliasFileName($alias));
999
    }
1097
    }
1000
 
-
 
1001
    // }}}
-
 
1002
    // {{{ _packageInfo()
-
 
1003
 
1098
 
1004
    /**
1099
    /**
1005
     * @param string|null
1100
     * @param string|null
1006
     * @param string|null
1101
     * @param string|null
1007
     * @param string|null
1102
     * @param string|null
1008
     * @return array|null
1103
     * @return array|null
1009
     * @access private
1104
     * @access private
1010
     */
1105
     */
1011
    function _packageInfo($package = null, $key = null, $channel = 'pear.php.net')
1106
    function _packageInfo($package = null, $key = null, $channel = 'pear.php.net')
1012
    {
1107
    {
1013
        if ($package === null) {
1108
        if ($package === null) {
1014
            if ($channel === null) {
1109
            if ($channel === null) {
1015
                $channels = $this->_listChannels();
1110
                $channels = $this->_listChannels();
1016
                $ret = array();
1111
                $ret = array();
1017
                foreach ($channels as $channel) {
1112
                foreach ($channels as $channel) {
1018
                    $channel = strtolower($channel);
1113
                    $channel = strtolower($channel);
1019
                    $ret[$channel] = array();
1114
                    $ret[$channel] = array();
1020
                    $packages = $this->_listPackages($channel);
1115
                    $packages = $this->_listPackages($channel);
1021
                    foreach ($packages as $package) {
1116
                    foreach ($packages as $package) {
1022
                        $ret[$channel][] = $this->_packageInfo($package, null, $channel);
1117
                        $ret[$channel][] = $this->_packageInfo($package, null, $channel);
1023
                    }
1118
                    }
1024
                }
1119
                }
-
 
1120
 
1025
                return $ret;
1121
                return $ret;
1026
            }
1122
            }
-
 
1123
 
1027
            $ps = $this->_listPackages($channel);
1124
            $ps = $this->_listPackages($channel);
1028
            if (!count($ps)) {
1125
            if (!count($ps)) {
1029
                return array();
1126
                return array();
1030
            }
1127
            }
1031
            return array_map(array(&$this, '_packageInfo'),
1128
            return array_map(array(&$this, '_packageInfo'),
1032
                             $ps, array_fill(0, count($ps), null),
1129
                             $ps, array_fill(0, count($ps), null),
1033
                             array_fill(0, count($ps), $channel));
1130
                             array_fill(0, count($ps), $channel));
1034
        }
1131
        }
-
 
1132
 
1035
        $fp = $this->_openPackageFile($package, 'r', $channel);
1133
        $fp = $this->_openPackageFile($package, 'r', $channel);
1036
        if ($fp === null) {
1134
        if ($fp === null) {
1037
            return null;
1135
            return null;
1038
        }
1136
        }
1039
        $rt = get_magic_quotes_runtime();
-
 
1040
        set_magic_quotes_runtime(0);
-
 
-
 
1137
 
1041
        clearstatcache();
1138
        clearstatcache();
1042
        $this->_closePackageFile($fp);
1139
        $this->_closePackageFile($fp);
1043
        $data = file_get_contents($this->_packageFileName($package, $channel));
1140
        $data = file_get_contents($this->_packageFileName($package, $channel));
1044
        set_magic_quotes_runtime($rt);
-
 
1045
        $data = unserialize($data);
1141
        $data = unserialize($data);
1046
        if ($key === null) {
1142
        if ($key === null) {
1047
            return $data;
1143
            return $data;
1048
        }
1144
        }
-
 
1145
 
1049
        // compatibility for package.xml version 2.0
1146
        // compatibility for package.xml version 2.0
1050
        if (isset($data['old'][$key])) {
1147
        if (isset($data['old'][$key])) {
1051
            return $data['old'][$key];
1148
            return $data['old'][$key];
1052
        }
1149
        }
-
 
1150
 
1053
        if (isset($data[$key])) {
1151
        if (isset($data[$key])) {
1054
            return $data[$key];
1152
            return $data[$key];
1055
        }
1153
        }
-
 
1154
 
1056
        return null;
1155
        return null;
1057
    }
1156
    }
1058
 
-
 
1059
    // }}}
-
 
1060
    // {{{ _channelInfo()
-
 
1061
 
1157
 
1062
    /**
1158
    /**
1063
     * @param string Channel name
1159
     * @param string Channel name
1064
     * @param bool whether to strictly retrieve info of channels, not just aliases
1160
     * @param bool whether to strictly retrieve info of channels, not just aliases
1065
     * @return array|null
1161
     * @return array|null
1066
     */
1162
     */
1067
    function _channelInfo($channel, $noaliases = false)
1163
    function _channelInfo($channel, $noaliases = false)
1068
    {
1164
    {
1069
        if (!$this->_channelExists($channel, $noaliases)) {
1165
        if (!$this->_channelExists($channel, $noaliases)) {
1070
            return null;
1166
            return null;
1071
        }
1167
        }
-
 
1168
 
1072
        $fp = $this->_openChannelFile($channel, 'r');
1169
        $fp = $this->_openChannelFile($channel, 'r');
1073
        if ($fp === null) {
1170
        if ($fp === null) {
1074
            return null;
1171
            return null;
1075
        }
1172
        }
1076
        $rt = get_magic_quotes_runtime();
-
 
1077
        set_magic_quotes_runtime(0);
-
 
-
 
1173
 
1078
        clearstatcache();
1174
        clearstatcache();
1079
        $this->_closeChannelFile($fp);
1175
        $this->_closeChannelFile($fp);
1080
        $data = file_get_contents($this->_channelFileName($channel));
1176
        $data = file_get_contents($this->_channelFileName($channel));
1081
        set_magic_quotes_runtime($rt);
-
 
1082
        $data = unserialize($data);
1177
        $data = unserialize($data);
1083
        return $data;
1178
        return $data;
1084
    }
1179
    }
1085
 
-
 
1086
    // }}}
-
 
1087
    // {{{ _listChannels()
-
 
1088
 
1180
 
1089
    function _listChannels()
1181
    function _listChannels()
1090
    {
1182
    {
1091
        $channellist = array();
1183
        $channellist = array();
1092
        if (!file_exists($this->channelsdir) || !is_dir($this->channelsdir)) {
1184
        if (!file_exists($this->channelsdir) || !is_dir($this->channelsdir)) {
1093
            return array('pear.php.net', 'pecl.php.net', '__uri');
1185
            return array('pear.php.net', 'pecl.php.net', 'doc.php.net', '__uri');
1094
        }
1186
        }
-
 
1187
 
1095
        $dp = opendir($this->channelsdir);
1188
        $dp = opendir($this->channelsdir);
1096
        while ($ent = readdir($dp)) {
1189
        while ($ent = readdir($dp)) {
1097
            if ($ent{0} == '.' || substr($ent, -4) != '.reg') {
1190
            if ($ent{0} == '.' || substr($ent, -4) != '.reg') {
1098
                continue;
1191
                continue;
1099
            }
1192
            }
-
 
1193
 
1100
            if ($ent == '__uri.reg') {
1194
            if ($ent == '__uri.reg') {
1101
                $channellist[] = '__uri';
1195
                $channellist[] = '__uri';
1102
                continue;
1196
                continue;
1103
            }
1197
            }
-
 
1198
 
1104
            $channellist[] = str_replace('_', '/', substr($ent, 0, -4));
1199
            $channellist[] = str_replace('_', '/', substr($ent, 0, -4));
1105
        }
1200
        }
-
 
1201
 
1106
        closedir($dp);
1202
        closedir($dp);
1107
        if (!in_array('pear.php.net', $channellist)) {
1203
        if (!in_array('pear.php.net', $channellist)) {
1108
            $channellist[] = 'pear.php.net';
1204
            $channellist[] = 'pear.php.net';
1109
        }
1205
        }
-
 
1206
 
1110
        if (!in_array('pecl.php.net', $channellist)) {
1207
        if (!in_array('pecl.php.net', $channellist)) {
1111
            $channellist[] = 'pecl.php.net';
1208
            $channellist[] = 'pecl.php.net';
1112
        }
1209
        }
-
 
1210
 
-
 
1211
        if (!in_array('doc.php.net', $channellist)) {
-
 
1212
            $channellist[] = 'doc.php.net';
-
 
1213
        }
-
 
1214
 
-
 
1215
 
1113
        if (!in_array('__uri', $channellist)) {
1216
        if (!in_array('__uri', $channellist)) {
1114
            $channellist[] = '__uri';
1217
            $channellist[] = '__uri';
1115
        }
1218
        }
-
 
1219
 
-
 
1220
        natsort($channellist);
1116
        return $channellist;
1221
        return $channellist;
1117
    }
1222
    }
1118
 
-
 
1119
    // }}}
-
 
1120
    // {{{ _listPackages()
-
 
1121
 
1223
 
1122
    function _listPackages($channel = false)
1224
    function _listPackages($channel = false)
1123
    {
1225
    {
1124
        if ($channel && $this->_getChannelFromAlias($channel) != 'pear.php.net') {
1226
        if ($channel && $this->_getChannelFromAlias($channel) != 'pear.php.net') {
1125
            return $this->_listChannelPackages($channel);
1227
            return $this->_listChannelPackages($channel);
1126
        }
1228
        }
-
 
1229
 
1127
        if (!file_exists($this->statedir) || !is_dir($this->statedir)) {
1230
        if (!file_exists($this->statedir) || !is_dir($this->statedir)) {
1128
            return array();
1231
            return array();
1129
        }
1232
        }
-
 
1233
 
1130
        $pkglist = array();
1234
        $pkglist = array();
1131
        $dp = opendir($this->statedir);
1235
        $dp = opendir($this->statedir);
1132
        if (!$dp) {
1236
        if (!$dp) {
1133
            return $pkglist;
1237
            return $pkglist;
1134
        }
1238
        }
-
 
1239
 
1135
        while ($ent = readdir($dp)) {
1240
        while ($ent = readdir($dp)) {
1136
            if ($ent{0} == '.' || substr($ent, -4) != '.reg') {
1241
            if ($ent{0} == '.' || substr($ent, -4) != '.reg') {
1137
                continue;
1242
                continue;
1138
            }
1243
            }
-
 
1244
 
1139
            $pkglist[] = substr($ent, 0, -4);
1245
            $pkglist[] = substr($ent, 0, -4);
1140
        }
1246
        }
1141
        closedir($dp);
1247
        closedir($dp);
1142
        return $pkglist;
1248
        return $pkglist;
1143
    }
1249
    }
1144
 
-
 
1145
    // }}}
-
 
1146
    // {{{ _listChannelPackages()
-
 
1147
 
1250
 
1148
    function _listChannelPackages($channel)
1251
    function _listChannelPackages($channel)
1149
    {
1252
    {
1150
        $pkglist = array();
1253
        $pkglist = array();
1151
        if (!file_exists($this->_channelDirectoryName($channel)) ||
1254
        if (!file_exists($this->_channelDirectoryName($channel)) ||
1152
              !is_dir($this->_channelDirectoryName($channel))) {
1255
              !is_dir($this->_channelDirectoryName($channel))) {
1153
            return array();
1256
            return array();
1154
        }
1257
        }
-
 
1258
 
1155
        $dp = opendir($this->_channelDirectoryName($channel));
1259
        $dp = opendir($this->_channelDirectoryName($channel));
1156
        if (!$dp) {
1260
        if (!$dp) {
1157
            return $pkglist;
1261
            return $pkglist;
1158
        }
1262
        }
-
 
1263
 
1159
        while ($ent = readdir($dp)) {
1264
        while ($ent = readdir($dp)) {
1160
            if ($ent{0} == '.' || substr($ent, -4) != '.reg') {
1265
            if ($ent{0} == '.' || substr($ent, -4) != '.reg') {
1161
                continue;
1266
                continue;
1162
            }
1267
            }
1163
            $pkglist[] = substr($ent, 0, -4);
1268
            $pkglist[] = substr($ent, 0, -4);
1164
        }
1269
        }
-
 
1270
 
1165
        closedir($dp);
1271
        closedir($dp);
1166
        return $pkglist;
1272
        return $pkglist;
1167
    }
1273
    }
1168
 
-
 
1169
    // }}}
-
 
1170
    
1274
 
1171
    function _listAllPackages()
1275
    function _listAllPackages()
1172
    {
1276
    {
1173
        $ret = array();
1277
        $ret = array();
1174
        foreach ($this->_listChannels() as $channel) {
1278
        foreach ($this->_listChannels() as $channel) {
1175
            $ret[$channel] = $this->_listPackages($channel);
1279
            $ret[$channel] = $this->_listPackages($channel);
1176
        }
1280
        }
-
 
1281
 
1177
        return $ret;
1282
        return $ret;
1178
    }
1283
    }
1179
 
1284
 
1180
    /**
1285
    /**
1181
     * Add an installed package to the registry
1286
     * Add an installed package to the registry
1182
     * @param string package name
1287
     * @param string package name
1183
     * @param array package info (parsed by PEAR_Common::infoFrom*() methods)
1288
     * @param array package info (parsed by PEAR_Common::infoFrom*() methods)
1184
     * @return bool success of saving
1289
     * @return bool success of saving
1185
     * @access private
1290
     * @access private
1186
     */
1291
     */
1187
    function _addPackage($package, $info)
1292
    function _addPackage($package, $info)
1188
    {
1293
    {
1189
        if ($this->_packageExists($package)) {
1294
        if ($this->_packageExists($package)) {
1190
            return false;
1295
            return false;
1191
        }
1296
        }
-
 
1297
 
1192
        $fp = $this->_openPackageFile($package, 'wb');
1298
        $fp = $this->_openPackageFile($package, 'wb');
1193
        if ($fp === null) {
1299
        if ($fp === null) {
1194
            return false;
1300
            return false;
1195
        }
1301
        }
-
 
1302
 
1196
        $info['_lastmodified'] = time();
1303
        $info['_lastmodified'] = time();
1197
        fwrite($fp, serialize($info));
1304
        fwrite($fp, serialize($info));
1198
        $this->_closePackageFile($fp);
1305
        $this->_closePackageFile($fp);
1199
        if (isset($info['filelist'])) {
1306
        if (isset($info['filelist'])) {
1200
            $this->_rebuildFileMap();
1307
            $this->_rebuildFileMap();
1201
        }
1308
        }
-
 
1309
 
1202
        return true;
1310
        return true;
1203
    }
1311
    }
1204
 
1312
 
1205
    /**
1313
    /**
1206
     * @param PEAR_PackageFile_v1|PEAR_PackageFile_v2
1314
     * @param PEAR_PackageFile_v1|PEAR_PackageFile_v2
1207
     * @return bool
1315
     * @return bool
1208
     * @access private
1316
     * @access private
1209
     */
1317
     */
1210
    function _addPackage2($info)
1318
    function _addPackage2($info)
1211
    {
1319
    {
-
 
1320
        if (!is_a($info, 'PEAR_PackageFile_v1') && !is_a($info, 'PEAR_PackageFile_v2')) {
-
 
1321
            return false;
-
 
1322
        }
-
 
1323
 
1212
        if (!$info->validate()) {
1324
        if (!$info->validate()) {
1213
            if (class_exists('PEAR_Common')) {
1325
            if (class_exists('PEAR_Common')) {
1214
                $ui = PEAR_Frontend::singleton();
1326
                $ui = PEAR_Frontend::singleton();
1215
                if ($ui) {
1327
                if ($ui) {
1216
                    foreach ($info->getValidationWarnings() as $err) {
1328
                    foreach ($info->getValidationWarnings() as $err) {
1217
                        $ui->log($err['message'], true);
1329
                        $ui->log($err['message'], true);
1218
                    }
1330
                    }
1219
                }
1331
                }
1220
            }
1332
            }
1221
            return false;
1333
            return false;
1222
        }
1334
        }
-
 
1335
 
1223
        $channel = $info->getChannel();
1336
        $channel = $info->getChannel();
1224
        $package = $info->getPackage();
1337
        $package = $info->getPackage();
1225
        $save = $info;
1338
        $save = $info;
1226
        if ($this->_packageExists($package, $channel)) {
1339
        if ($this->_packageExists($package, $channel)) {
1227
            return false;
1340
            return false;
1228
        }
1341
        }
-
 
1342
 
1229
        if (!$this->_channelExists($channel, true)) {
1343
        if (!$this->_channelExists($channel, true)) {
1230
            return false;
1344
            return false;
1231
        }
1345
        }
-
 
1346
 
1232
        $info = $info->toArray(true);
1347
        $info = $info->toArray(true);
1233
        if (!$info) {
1348
        if (!$info) {
1234
            return false;
1349
            return false;
1235
        }
1350
        }
-
 
1351
 
1236
        $fp = $this->_openPackageFile($package, 'wb', $channel);
1352
        $fp = $this->_openPackageFile($package, 'wb', $channel);
1237
        if ($fp === null) {
1353
        if ($fp === null) {
1238
            return false;
1354
            return false;
1239
        }
1355
        }
-
 
1356
 
1240
        $info['_lastmodified'] = time();
1357
        $info['_lastmodified'] = time();
1241
        fwrite($fp, serialize($info));
1358
        fwrite($fp, serialize($info));
1242
        $this->_closePackageFile($fp);
1359
        $this->_closePackageFile($fp);
1243
        $this->_rebuildFileMap();
1360
        $this->_rebuildFileMap();
1244
        return true;
1361
        return true;
1245
    }
1362
    }
1246
 
1363
 
1247
    /**
1364
    /**
1248
     * @param string Package name
1365
     * @param string Package name
1249
     * @param array parsed package.xml 1.0
1366
     * @param array parsed package.xml 1.0
1250
     * @param bool this parameter is only here for BC.  Don't use it.
1367
     * @param bool this parameter is only here for BC.  Don't use it.
1251
     * @access private
1368
     * @access private
1252
     */
1369
     */
1253
    function _updatePackage($package, $info, $merge = true)
1370
    function _updatePackage($package, $info, $merge = true)
1254
    {
1371
    {
1255
        $oldinfo = $this->_packageInfo($package);
1372
        $oldinfo = $this->_packageInfo($package);
1256
        if (empty($oldinfo)) {
1373
        if (empty($oldinfo)) {
1257
            return false;
1374
            return false;
1258
        }
1375
        }
-
 
1376
 
1259
        $fp = $this->_openPackageFile($package, 'w');
1377
        $fp = $this->_openPackageFile($package, 'w');
1260
        if ($fp === null) {
1378
        if ($fp === null) {
1261
            return false;
1379
            return false;
1262
        }
1380
        }
-
 
1381
 
1263
        if (is_object($info)) {
1382
        if (is_object($info)) {
1264
            $info = $info->toArray();
1383
            $info = $info->toArray();
1265
        }
1384
        }
1266
        $info['_lastmodified'] = time();
1385
        $info['_lastmodified'] = time();
-
 
1386
 
1267
        $newinfo = $info;
1387
        $newinfo = $info;
1268
        if ($merge) {
1388
        if ($merge) {
1269
            $info = array_merge($oldinfo, $info);
1389
            $info = array_merge($oldinfo, $info);
1270
        } else {
1390
        } else {
1271
            $diff = $info;
1391
            $diff = $info;
1272
        }
1392
        }
-
 
1393
 
1273
        fwrite($fp, serialize($info));
1394
        fwrite($fp, serialize($info));
1274
        $this->_closePackageFile($fp);
1395
        $this->_closePackageFile($fp);
1275
        if (isset($newinfo['filelist'])) {
1396
        if (isset($newinfo['filelist'])) {
1276
            $this->_rebuildFileMap();
1397
            $this->_rebuildFileMap();
1277
        }
1398
        }
-
 
1399
 
1278
        return true;
1400
        return true;
1279
    }
1401
    }
1280
 
1402
 
1281
    /**
1403
    /**
1282
     * @param PEAR_PackageFile_v1|PEAR_PackageFile_v2
1404
     * @param PEAR_PackageFile_v1|PEAR_PackageFile_v2
1283
     * @return bool
1405
     * @return bool
1284
     * @access private
1406
     * @access private
1285
     */
1407
     */
1286
    function _updatePackage2($info)
1408
    function _updatePackage2($info)
1287
    {
1409
    {
1288
        if (!$this->_packageExists($info->getPackage(), $info->getChannel())) {
1410
        if (!$this->_packageExists($info->getPackage(), $info->getChannel())) {
1289
            return false;
1411
            return false;
1290
        }
1412
        }
-
 
1413
 
1291
        $fp = $this->_openPackageFile($info->getPackage(), 'w', $info->getChannel());
1414
        $fp = $this->_openPackageFile($info->getPackage(), 'w', $info->getChannel());
1292
        if ($fp === null) {
1415
        if ($fp === null) {
1293
            return false;
1416
            return false;
1294
        }
1417
        }
-
 
1418
 
1295
        $save = $info;
1419
        $save = $info;
1296
        $info = $save->getArray(true);
1420
        $info = $save->getArray(true);
1297
        $info['_lastmodified'] = time();
1421
        $info['_lastmodified'] = time();
1298
        fwrite($fp, serialize($info));
1422
        fwrite($fp, serialize($info));
1299
        $this->_closePackageFile($fp);
1423
        $this->_closePackageFile($fp);
1300
        $this->_rebuildFileMap();
1424
        $this->_rebuildFileMap();
1301
        return true;
1425
        return true;
1302
    }
1426
    }
1303
 
1427
 
1304
    /**
1428
    /**
1305
     * @param string Package name
1429
     * @param string Package name
1306
     * @param string Channel name
1430
     * @param string Channel name
1307
     * @return PEAR_PackageFile_v1|PEAR_PackageFile_v2|null
1431
     * @return PEAR_PackageFile_v1|PEAR_PackageFile_v2|null
1308
     * @access private
1432
     * @access private
1309
     */
1433
     */
1310
    function &_getPackage($package, $channel = 'pear.php.net')
1434
    function &_getPackage($package, $channel = 'pear.php.net')
1311
    {
1435
    {
1312
        $info = $this->_packageInfo($package, null, $channel);
1436
        $info = $this->_packageInfo($package, null, $channel);
1313
        if ($info === null) {
1437
        if ($info === null) {
1314
            return $info;
1438
            return $info;
1315
        }
1439
        }
-
 
1440
 
1316
        $a = $this->_config;
1441
        $a = $this->_config;
1317
        if (!$a) {
1442
        if (!$a) {
1318
            $this->_config = &new PEAR_Config;
1443
            $this->_config = new PEAR_Config;
1319
            $this->_config->set('php_dir', $this->statedir);
1444
            $this->_config->set('php_dir', $this->statedir);
1320
        }
1445
        }
-
 
1446
 
1321
        if (!class_exists('PEAR_PackageFile')) {
1447
        if (!class_exists('PEAR_PackageFile')) {
1322
            require_once 'PEAR/PackageFile.php';
1448
            require_once 'PEAR/PackageFile.php';
1323
        }
1449
        }
-
 
1450
 
1324
        $pkg = &new PEAR_PackageFile($this->_config);
1451
        $pkg = new PEAR_PackageFile($this->_config);
1325
        $pf = &$pkg->fromArray($info);
1452
        $pf = &$pkg->fromArray($info);
1326
        return $pf;
1453
        return $pf;
1327
    }
1454
    }
1328
 
1455
 
1329
    /**
1456
    /**
1330
     * @param string channel name
1457
     * @param string channel name
1331
     * @param bool whether to strictly retrieve channel names
1458
     * @param bool whether to strictly retrieve channel names
1332
     * @return PEAR_ChannelFile|PEAR_Error
1459
     * @return PEAR_ChannelFile|PEAR_Error
1333
     * @access private
1460
     * @access private
1334
     */
1461
     */
1335
    function &_getChannel($channel, $noaliases = false)
1462
    function &_getChannel($channel, $noaliases = false)
1336
    {
1463
    {
1337
        $ch = false;
1464
        $ch = false;
1338
        if ($this->_channelExists($channel, $noaliases)) {
1465
        if ($this->_channelExists($channel, $noaliases)) {
1339
            $chinfo = $this->_channelInfo($channel, $noaliases);
1466
            $chinfo = $this->_channelInfo($channel, $noaliases);
1340
            if ($chinfo) {
1467
            if ($chinfo) {
1341
                if (!class_exists('PEAR_ChannelFile')) {
1468
                if (!class_exists('PEAR_ChannelFile')) {
1342
                    require_once 'PEAR/ChannelFile.php';
1469
                    require_once 'PEAR/ChannelFile.php';
1343
                }
1470
                }
-
 
1471
 
1344
                $ch = &PEAR_ChannelFile::fromArrayWithErrors($chinfo);
1472
                $ch = &PEAR_ChannelFile::fromArrayWithErrors($chinfo);
1345
            }
1473
            }
1346
        }
1474
        }
-
 
1475
 
1347
        if ($ch) {
1476
        if ($ch) {
1348
            if ($ch->validate()) {
1477
            if ($ch->validate()) {
1349
                return $ch;
1478
                return $ch;
1350
            }
1479
            }
-
 
1480
 
1351
            foreach ($ch->getErrors(true) as $err) {
1481
            foreach ($ch->getErrors(true) as $err) {
1352
                $message = $err['message'] . "\n";
1482
                $message = $err['message'] . "\n";
1353
            }
1483
            }
-
 
1484
 
1354
            $ch = PEAR::raiseError($message);
1485
            $ch = PEAR::raiseError($message);
1355
            return $ch;
1486
            return $ch;
1356
        }
1487
        }
-
 
1488
 
1357
        if ($this->_getChannelFromAlias($channel) == 'pear.php.net') {
1489
        if ($this->_getChannelFromAlias($channel) == 'pear.php.net') {
1358
            // the registry is not properly set up, so use defaults
1490
            // the registry is not properly set up, so use defaults
1359
            if (!class_exists('PEAR_ChannelFile')) {
1491
            if (!class_exists('PEAR_ChannelFile')) {
1360
                require_once 'PEAR/ChannelFile.php';
1492
                require_once 'PEAR/ChannelFile.php';
1361
            }
1493
            }
-
 
1494
 
1362
            $pear_channel = new PEAR_ChannelFile;
1495
            $pear_channel = new PEAR_ChannelFile;
1363
            $pear_channel->setName('pear.php.net');
1496
            $pear_channel->setServer('pear.php.net');
1364
            $pear_channel->setAlias('pear');
1497
            $pear_channel->setAlias('pear');
1365
            $pear_channel->setSummary('PHP Extension and Application Repository');
1498
            $pear_channel->setSummary('PHP Extension and Application Repository');
1366
            $pear_channel->setDefaultPEARProtocols();
1499
            $pear_channel->setDefaultPEARProtocols();
1367
            $pear_channel->setBaseURL('REST1.0', 'http://pear.php.net/rest/');
1500
            $pear_channel->setBaseURL('REST1.0', 'http://pear.php.net/rest/');
1368
            $pear_channel->setBaseURL('REST1.1', 'http://pear.php.net/rest/');
1501
            $pear_channel->setBaseURL('REST1.1', 'http://pear.php.net/rest/');
-
 
1502
            $pear_channel->setBaseURL('REST1.3', 'http://pear.php.net/rest/');
1369
            return $pear_channel;
1503
            return $pear_channel;
1370
        }
1504
        }
-
 
1505
 
1371
        if ($this->_getChannelFromAlias($channel) == 'pecl.php.net') {
1506
        if ($this->_getChannelFromAlias($channel) == 'pecl.php.net') {
1372
            // the registry is not properly set up, so use defaults
1507
            // the registry is not properly set up, so use defaults
1373
            if (!class_exists('PEAR_ChannelFile')) {
1508
            if (!class_exists('PEAR_ChannelFile')) {
1374
                require_once 'PEAR/ChannelFile.php';
1509
                require_once 'PEAR/ChannelFile.php';
1375
            }
1510
            }
1376
            $pear_channel = new PEAR_ChannelFile;
1511
            $pear_channel = new PEAR_ChannelFile;
1377
            $pear_channel->setName('pecl.php.net');
1512
            $pear_channel->setServer('pecl.php.net');
1378
            $pear_channel->setAlias('pecl');
1513
            $pear_channel->setAlias('pecl');
1379
            $pear_channel->setSummary('PHP Extension Community Library');
1514
            $pear_channel->setSummary('PHP Extension Community Library');
1380
            $pear_channel->setDefaultPEARProtocols();
1515
            $pear_channel->setDefaultPEARProtocols();
1381
            $pear_channel->setBaseURL('REST1.0', 'http://pecl.php.net/rest/');
1516
            $pear_channel->setBaseURL('REST1.0', 'http://pecl.php.net/rest/');
1382
            $pear_channel->setBaseURL('REST1.1', 'http://pecl.php.net/rest/');
1517
            $pear_channel->setBaseURL('REST1.1', 'http://pecl.php.net/rest/');
1383
            $pear_channel->setValidationPackage('PEAR_Validator_PECL', '1.0');
1518
            $pear_channel->setValidationPackage('PEAR_Validator_PECL', '1.0');
1384
            return $pear_channel;
1519
            return $pear_channel;
1385
        }
1520
        }
-
 
1521
 
-
 
1522
        if ($this->_getChannelFromAlias($channel) == 'doc.php.net') {
-
 
1523
            // the registry is not properly set up, so use defaults
-
 
1524
            if (!class_exists('PEAR_ChannelFile')) {
-
 
1525
                require_once 'PEAR/ChannelFile.php';
-
 
1526
            }
-
 
1527
 
-
 
1528
            $doc_channel = new PEAR_ChannelFile;
-
 
1529
            $doc_channel->setServer('doc.php.net');
-
 
1530
            $doc_channel->setAlias('phpdocs');
-
 
1531
            $doc_channel->setSummary('PHP Documentation Team');
-
 
1532
            $doc_channel->setDefaultPEARProtocols();
-
 
1533
            $doc_channel->setBaseURL('REST1.0', 'http://doc.php.net/rest/');
-
 
1534
            $doc_channel->setBaseURL('REST1.1', 'http://doc.php.net/rest/');
-
 
1535
            $doc_channel->setBaseURL('REST1.3', 'http://doc.php.net/rest/');
-
 
1536
            return $doc_channel;
-
 
1537
        }
-
 
1538
 
-
 
1539
 
1386
        if ($this->_getChannelFromAlias($channel) == '__uri') {
1540
        if ($this->_getChannelFromAlias($channel) == '__uri') {
1387
            // the registry is not properly set up, so use defaults
1541
            // the registry is not properly set up, so use defaults
1388
            if (!class_exists('PEAR_ChannelFile')) {
1542
            if (!class_exists('PEAR_ChannelFile')) {
1389
                require_once 'PEAR/ChannelFile.php';
1543
                require_once 'PEAR/ChannelFile.php';
1390
            }
1544
            }
-
 
1545
 
1391
            $private = new PEAR_ChannelFile;
1546
            $private = new PEAR_ChannelFile;
1392
            $private->setName('__uri');
1547
            $private->setName('__uri');
-
 
1548
            $private->setDefaultPEARProtocols();
1393
            $private->addFunction('xmlrpc', '1.0', '****');
1549
            $private->setBaseURL('REST1.0', '****');
1394
            $private->setSummary('Pseudo-channel for static packages');
1550
            $private->setSummary('Pseudo-channel for static packages');
1395
            return $private;
1551
            return $private;
1396
        }
1552
        }
-
 
1553
 
1397
        return $ch;
1554
        return $ch;
1398
    }
1555
    }
1399
 
-
 
1400
    // {{{ packageExists()
-
 
1401
 
1556
 
1402
    /**
1557
    /**
1403
     * @param string Package name
1558
     * @param string Package name
1404
     * @param string Channel name
1559
     * @param string Channel name
1405
     * @return bool
1560
     * @return bool
1406
     */
1561
     */
1407
    function packageExists($package, $channel = 'pear.php.net')
1562
    function packageExists($package, $channel = 'pear.php.net')
1408
    {
1563
    {
1409
        if (PEAR::isError($e = $this->_lock(LOCK_SH))) {
1564
        if (PEAR::isError($e = $this->_lock(LOCK_SH))) {
1410
            return $e;
1565
            return $e;
1411
        }
1566
        }
1412
        $ret = $this->_packageExists($package, $channel);
1567
        $ret = $this->_packageExists($package, $channel);
1413
        $this->_unlock();
1568
        $this->_unlock();
1414
        return $ret;
1569
        return $ret;
1415
    }
1570
    }
1416
 
1571
 
1417
    // }}}
1572
    // }}}
1418
 
1573
 
1419
    // {{{ channelExists()
1574
    // {{{ channelExists()
1420
 
1575
 
1421
    /**
1576
    /**
1422
     * @param string channel name
1577
     * @param string channel name
1423
     * @param bool if true, then aliases will be ignored
1578
     * @param bool if true, then aliases will be ignored
1424
     * @return bool
1579
     * @return bool
1425
     */
1580
     */
1426
    function channelExists($channel, $noaliases = false)
1581
    function channelExists($channel, $noaliases = false)
1427
    {
1582
    {
1428
        if (PEAR::isError($e = $this->_lock(LOCK_SH))) {
1583
        if (PEAR::isError($e = $this->_lock(LOCK_SH))) {
1429
            return $e;
1584
            return $e;
1430
        }
1585
        }
1431
        $ret = $this->_channelExists($channel, $noaliases);
1586
        $ret = $this->_channelExists($channel, $noaliases);
1432
        $this->_unlock();
1587
        $this->_unlock();
1433
        return $ret;
1588
        return $ret;
1434
    }
1589
    }
1435
 
1590
 
1436
    // }}}
1591
    // }}}
-
 
1592
 
-
 
1593
    /**
-
 
1594
     * @param string channel name mirror is in
-
 
1595
     * @param string mirror name
-
 
1596
     *
-
 
1597
     * @return bool
-
 
1598
     */
-
 
1599
    function mirrorExists($channel, $mirror)
-
 
1600
    {
-
 
1601
        if (PEAR::isError($e = $this->_lock(LOCK_SH))) {
-
 
1602
            return $e;
-
 
1603
        }
-
 
1604
 
-
 
1605
        $ret = $this->_mirrorExists($channel, $mirror);
-
 
1606
        $this->_unlock();
-
 
1607
        return $ret;
-
 
1608
    }
1437
 
1609
 
1438
    // {{{ isAlias()
1610
    // {{{ isAlias()
1439
 
1611
 
1440
    /**
1612
    /**
1441
     * Determines whether the parameter is an alias of a channel
1613
     * Determines whether the parameter is an alias of a channel
1442
     * @param string
1614
     * @param string
1443
     * @return bool
1615
     * @return bool
1444
     */
1616
     */
1445
    function isAlias($alias)
1617
    function isAlias($alias)
1446
    {
1618
    {
1447
        if (PEAR::isError($e = $this->_lock(LOCK_SH))) {
1619
        if (PEAR::isError($e = $this->_lock(LOCK_SH))) {
1448
            return $e;
1620
            return $e;
1449
        }
1621
        }
1450
        $ret = $this->_isChannelAlias($alias);
1622
        $ret = $this->_isChannelAlias($alias);
1451
        $this->_unlock();
1623
        $this->_unlock();
1452
        return $ret;
1624
        return $ret;
1453
    }
1625
    }
1454
 
1626
 
1455
    // }}}
1627
    // }}}
1456
    // {{{ packageInfo()
1628
    // {{{ packageInfo()
1457
 
1629
 
1458
    /**
1630
    /**
1459
     * @param string|null
1631
     * @param string|null
1460
     * @param string|null
1632
     * @param string|null
1461
     * @param string
1633
     * @param string
1462
     * @return array|null
1634
     * @return array|null
1463
     */
1635
     */
1464
    function packageInfo($package = null, $key = null, $channel = 'pear.php.net')
1636
    function packageInfo($package = null, $key = null, $channel = 'pear.php.net')
1465
    {
1637
    {
1466
        if (PEAR::isError($e = $this->_lock(LOCK_SH))) {
1638
        if (PEAR::isError($e = $this->_lock(LOCK_SH))) {
1467
            return $e;
1639
            return $e;
1468
        }
1640
        }
1469
        $ret = $this->_packageInfo($package, $key, $channel);
1641
        $ret = $this->_packageInfo($package, $key, $channel);
1470
        $this->_unlock();
1642
        $this->_unlock();
1471
        return $ret;
1643
        return $ret;
1472
    }
1644
    }
1473
 
1645
 
1474
    // }}}
1646
    // }}}
1475
    // {{{ channelInfo()
1647
    // {{{ channelInfo()
1476
 
1648
 
1477
    /**
1649
    /**
1478
     * Retrieve a raw array of channel data.
1650
     * Retrieve a raw array of channel data.
1479
     *
1651
     *
1480
     * Do not use this, instead use {@link getChannel()} for normal
1652
     * Do not use this, instead use {@link getChannel()} for normal
1481
     * operations.  Array structure is undefined in this method
1653
     * operations.  Array structure is undefined in this method
1482
     * @param string channel name
1654
     * @param string channel name
1483
     * @param bool whether to strictly retrieve information only on non-aliases
1655
     * @param bool whether to strictly retrieve information only on non-aliases
1484
     * @return array|null|PEAR_Error
1656
     * @return array|null|PEAR_Error
1485
     */
1657
     */
1486
    function channelInfo($channel = null, $noaliases = false)
1658
    function channelInfo($channel = null, $noaliases = false)
1487
    {
1659
    {
1488
        if (PEAR::isError($e = $this->_lock(LOCK_SH))) {
1660
        if (PEAR::isError($e = $this->_lock(LOCK_SH))) {
1489
            return $e;
1661
            return $e;
1490
        }
1662
        }
1491
        $ret = $this->_channelInfo($channel, $noaliases);
1663
        $ret = $this->_channelInfo($channel, $noaliases);
1492
        $this->_unlock();
1664
        $this->_unlock();
1493
        return $ret;
1665
        return $ret;
1494
    }
1666
    }
1495
 
1667
 
1496
    // }}}
1668
    // }}}
1497
 
1669
 
1498
    /**
1670
    /**
1499
     * @param string
1671
     * @param string
1500
     */
1672
     */
1501
    function channelName($channel)
1673
    function channelName($channel)
1502
    {
1674
    {
1503
        if (PEAR::isError($e = $this->_lock(LOCK_SH))) {
1675
        if (PEAR::isError($e = $this->_lock(LOCK_SH))) {
1504
            return $e;
1676
            return $e;
1505
        }
1677
        }
1506
        $ret = $this->_getChannelFromAlias($channel);
1678
        $ret = $this->_getChannelFromAlias($channel);
1507
        $this->_unlock();
1679
        $this->_unlock();
1508
        return $ret;
1680
        return $ret;
1509
    }
1681
    }
1510
 
1682
 
1511
    /**
1683
    /**
1512
     * @param string
1684
     * @param string
1513
     */
1685
     */
1514
    function channelAlias($channel)
1686
    function channelAlias($channel)
1515
    {
1687
    {
1516
        if (PEAR::isError($e = $this->_lock(LOCK_SH))) {
1688
        if (PEAR::isError($e = $this->_lock(LOCK_SH))) {
1517
            return $e;
1689
            return $e;
1518
        }
1690
        }
1519
        $ret = $this->_getAlias($channel);
1691
        $ret = $this->_getAlias($channel);
1520
        $this->_unlock();
1692
        $this->_unlock();
1521
        return $ret;
1693
        return $ret;
1522
    }
1694
    }
1523
    // {{{ listPackages()
1695
    // {{{ listPackages()
1524
 
1696
 
1525
    function listPackages($channel = false)
1697
    function listPackages($channel = false)
1526
    {
1698
    {
1527
        if (PEAR::isError($e = $this->_lock(LOCK_SH))) {
1699
        if (PEAR::isError($e = $this->_lock(LOCK_SH))) {
1528
            return $e;
1700
            return $e;
1529
        }
1701
        }
1530
        $ret = $this->_listPackages($channel);
1702
        $ret = $this->_listPackages($channel);
1531
        $this->_unlock();
1703
        $this->_unlock();
1532
        return $ret;
1704
        return $ret;
1533
    }
1705
    }
1534
 
1706
 
1535
    // }}}
1707
    // }}}
1536
    // {{{ listAllPackages()
1708
    // {{{ listAllPackages()
1537
 
1709
 
1538
    function listAllPackages()
1710
    function listAllPackages()
1539
    {
1711
    {
1540
        if (PEAR::isError($e = $this->_lock(LOCK_SH))) {
1712
        if (PEAR::isError($e = $this->_lock(LOCK_SH))) {
1541
            return $e;
1713
            return $e;
1542
        }
1714
        }
1543
        $ret = $this->_listAllPackages();
1715
        $ret = $this->_listAllPackages();
1544
        $this->_unlock();
1716
        $this->_unlock();
1545
        return $ret;
1717
        return $ret;
1546
    }
1718
    }
1547
 
1719
 
1548
    // }}}
1720
    // }}}
1549
    // {{{ listChannel()
1721
    // {{{ listChannel()
1550
 
1722
 
1551
    function listChannels()
1723
    function listChannels()
1552
    {
1724
    {
1553
        if (PEAR::isError($e = $this->_lock(LOCK_SH))) {
1725
        if (PEAR::isError($e = $this->_lock(LOCK_SH))) {
1554
            return $e;
1726
            return $e;
1555
        }
1727
        }
1556
        $ret = $this->_listChannels();
1728
        $ret = $this->_listChannels();
1557
        $this->_unlock();
1729
        $this->_unlock();
1558
        return $ret;
1730
        return $ret;
1559
    }
1731
    }
1560
 
1732
 
1561
    // }}}
1733
    // }}}
1562
    // {{{ addPackage()
1734
    // {{{ addPackage()
1563
 
1735
 
1564
    /**
1736
    /**
1565
     * Add an installed package to the registry
1737
     * Add an installed package to the registry
1566
     * @param string|PEAR_PackageFile_v1|PEAR_PackageFile_v2 package name or object
1738
     * @param string|PEAR_PackageFile_v1|PEAR_PackageFile_v2 package name or object
1567
     *               that will be passed to {@link addPackage2()}
1739
     *               that will be passed to {@link addPackage2()}
1568
     * @param array package info (parsed by PEAR_Common::infoFrom*() methods)
1740
     * @param array package info (parsed by PEAR_Common::infoFrom*() methods)
1569
     * @return bool success of saving
1741
     * @return bool success of saving
1570
     */
1742
     */
1571
    function addPackage($package, $info)
1743
    function addPackage($package, $info)
1572
    {
1744
    {
1573
        if (is_object($info)) {
1745
        if (is_object($info)) {
1574
            return $this->addPackage2($info);
1746
            return $this->addPackage2($info);
1575
        }
1747
        }
1576
        if (PEAR::isError($e = $this->_lock(LOCK_EX))) {
1748
        if (PEAR::isError($e = $this->_lock(LOCK_EX))) {
1577
            return $e;
1749
            return $e;
1578
        }
1750
        }
1579
        $ret = $this->_addPackage($package, $info);
1751
        $ret = $this->_addPackage($package, $info);
1580
        $this->_unlock();
1752
        $this->_unlock();
1581
        if ($ret) {
1753
        if ($ret) {
1582
            if (!class_exists('PEAR_PackageFile_v1')) {
1754
            if (!class_exists('PEAR_PackageFile_v1')) {
1583
                require_once 'PEAR/PackageFile/v1.php';
1755
                require_once 'PEAR/PackageFile/v1.php';
1584
            }
1756
            }
1585
            $pf = new PEAR_PackageFile_v1;
1757
            $pf = new PEAR_PackageFile_v1;
1586
            $pf->setConfig($this->_config);
1758
            $pf->setConfig($this->_config);
1587
            $pf->fromArray($info);
1759
            $pf->fromArray($info);
1588
            $this->_dependencyDB->uninstallPackage($pf);
1760
            $this->_dependencyDB->uninstallPackage($pf);
1589
            $this->_dependencyDB->installPackage($pf);
1761
            $this->_dependencyDB->installPackage($pf);
1590
        }
1762
        }
1591
        return $ret;
1763
        return $ret;
1592
    }
1764
    }
1593
 
1765
 
1594
    // }}}
1766
    // }}}
1595
    // {{{ addPackage2()
1767
    // {{{ addPackage2()
1596
 
1768
 
1597
    function addPackage2($info)
1769
    function addPackage2($info)
1598
    {
1770
    {
1599
        if (!is_object($info)) {
1771
        if (!is_object($info)) {
1600
            return $this->addPackage($info['package'], $info);
1772
            return $this->addPackage($info['package'], $info);
1601
        }
1773
        }
1602
        if (PEAR::isError($e = $this->_lock(LOCK_EX))) {
1774
        if (PEAR::isError($e = $this->_lock(LOCK_EX))) {
1603
            return $e;
1775
            return $e;
1604
        }
1776
        }
1605
        $ret = $this->_addPackage2($info);
1777
        $ret = $this->_addPackage2($info);
1606
        $this->_unlock();
1778
        $this->_unlock();
1607
        if ($ret) {
1779
        if ($ret) {
1608
            $this->_dependencyDB->uninstallPackage($info);
1780
            $this->_dependencyDB->uninstallPackage($info);
1609
            $this->_dependencyDB->installPackage($info);
1781
            $this->_dependencyDB->installPackage($info);
1610
        }
1782
        }
1611
        return $ret;
1783
        return $ret;
1612
    }
1784
    }
1613
 
1785
 
1614
    // }}}
1786
    // }}}
1615
    // {{{ updateChannel()
1787
    // {{{ updateChannel()
1616
 
1788
 
1617
    /**
1789
    /**
1618
     * For future expandibility purposes, separate this
1790
     * For future expandibility purposes, separate this
1619
     * @param PEAR_ChannelFile
1791
     * @param PEAR_ChannelFile
1620
     */
1792
     */
1621
    function updateChannel($channel, $lastmodified = null)
1793
    function updateChannel($channel, $lastmodified = null)
1622
    {
1794
    {
1623
        if ($channel->getName() == '__uri') {
1795
        if ($channel->getName() == '__uri') {
1624
            return false;
1796
            return false;
1625
        }
1797
        }
1626
        return $this->addChannel($channel, $lastmodified, true);
1798
        return $this->addChannel($channel, $lastmodified, true);
1627
    }
1799
    }
1628
 
1800
 
1629
    // }}}
1801
    // }}}
1630
    // {{{ deleteChannel()
1802
    // {{{ deleteChannel()
1631
 
1803
 
1632
    /**
1804
    /**
1633
     * Deletion fails if there are any packages installed from the channel
1805
     * Deletion fails if there are any packages installed from the channel
1634
     * @param string|PEAR_ChannelFile channel name
1806
     * @param string|PEAR_ChannelFile channel name
1635
     * @return boolean|PEAR_Error True on deletion, false if it doesn't exist
1807
     * @return boolean|PEAR_Error True on deletion, false if it doesn't exist
1636
     */
1808
     */
1637
    function deleteChannel($channel)
1809
    function deleteChannel($channel)
1638
    {
1810
    {
1639
        if (PEAR::isError($e = $this->_lock(LOCK_EX))) {
1811
        if (PEAR::isError($e = $this->_lock(LOCK_EX))) {
1640
            return $e;
1812
            return $e;
1641
        }
1813
        }
-
 
1814
 
1642
        $ret = $this->_deleteChannel($channel);
1815
        $ret = $this->_deleteChannel($channel);
1643
        $this->_unlock();
1816
        $this->_unlock();
1644
        if ($ret && is_a($this->_config, 'PEAR_Config')) {
1817
        if ($ret && is_a($this->_config, 'PEAR_Config')) {
1645
            $this->_config->setChannels($this->listChannels());
1818
            $this->_config->setChannels($this->listChannels());
1646
        }
1819
        }
-
 
1820
 
1647
        return $ret;
1821
        return $ret;
1648
    }
1822
    }
1649
 
1823
 
1650
    // }}}
1824
    // }}}
1651
    // {{{ addChannel()
1825
    // {{{ addChannel()
1652
 
1826
 
1653
    /**
1827
    /**
1654
     * @param PEAR_ChannelFile Channel object
1828
     * @param PEAR_ChannelFile Channel object
1655
     * @param string Last-Modified header from HTTP for caching
1829
     * @param string Last-Modified header from HTTP for caching
1656
     * @return boolean|PEAR_Error True on creation, false if it already exists
1830
     * @return boolean|PEAR_Error True on creation, false if it already exists
1657
     */
1831
     */
1658
    function addChannel($channel, $lastmodified = false, $update = false)
1832
    function addChannel($channel, $lastmodified = false, $update = false)
1659
    {
1833
    {
1660
        if (!is_a($channel, 'PEAR_ChannelFile')) {
1834
        if (!is_a($channel, 'PEAR_ChannelFile') || !$channel->validate()) {
1661
            return false;
-
 
1662
        }
-
 
1663
        if (!$channel->validate()) {
-
 
1664
            return false;
1835
            return false;
1665
        }
1836
        }
-
 
1837
 
1666
        if (PEAR::isError($e = $this->_lock(LOCK_EX))) {
1838
        if (PEAR::isError($e = $this->_lock(LOCK_EX))) {
1667
            return $e;
1839
            return $e;
1668
        }
1840
        }
-
 
1841
 
1669
        $ret = $this->_addChannel($channel, $update, $lastmodified);
1842
        $ret = $this->_addChannel($channel, $update, $lastmodified);
1670
        $this->_unlock();
1843
        $this->_unlock();
1671
        if (!$update && $ret && is_a($this->_config, 'PEAR_Config')) {
1844
        if (!$update && $ret && is_a($this->_config, 'PEAR_Config')) {
1672
            $this->_config->setChannels($this->listChannels());
1845
            $this->_config->setChannels($this->listChannels());
1673
        }
1846
        }
-
 
1847
 
1674
        return $ret;
1848
        return $ret;
1675
    }
1849
    }
1676
 
1850
 
1677
    // }}}
1851
    // }}}
1678
    // {{{ deletePackage()
1852
    // {{{ deletePackage()
1679
 
1853
 
1680
    function deletePackage($package, $channel = 'pear.php.net')
1854
    function deletePackage($package, $channel = 'pear.php.net')
1681
    {
1855
    {
1682
        if (PEAR::isError($e = $this->_lock(LOCK_EX))) {
1856
        if (PEAR::isError($e = $this->_lock(LOCK_EX))) {
1683
            return $e;
1857
            return $e;
1684
        }
1858
        }
-
 
1859
 
1685
        $file = $this->_packageFileName($package, $channel);
1860
        $file = $this->_packageFileName($package, $channel);
1686
        if (file_exists($file)) {
-
 
1687
            $ret = @unlink($file);
1861
        $ret  = file_exists($file) ? @unlink($file) : false;
1688
        } else {
-
 
1689
            $ret = false;
-
 
1690
        }
-
 
1691
        $this->_rebuildFileMap();
1862
        $this->_rebuildFileMap();
1692
        $this->_unlock();
1863
        $this->_unlock();
1693
        $p = array('channel' => $channel, 'package' => $package);
1864
        $p = array('channel' => $channel, 'package' => $package);
1694
        $this->_dependencyDB->uninstallPackage($p);
1865
        $this->_dependencyDB->uninstallPackage($p);
1695
        return $ret;
1866
        return $ret;
1696
    }
1867
    }
1697
 
1868
 
1698
    // }}}
1869
    // }}}
1699
    // {{{ updatePackage()
1870
    // {{{ updatePackage()
1700
 
1871
 
1701
    function updatePackage($package, $info, $merge = true)
1872
    function updatePackage($package, $info, $merge = true)
1702
    {
1873
    {
1703
        if (is_object($info)) {
1874
        if (is_object($info)) {
1704
            return $this->updatePackage2($info, $merge);
1875
            return $this->updatePackage2($info, $merge);
1705
        }
1876
        }
1706
        if (PEAR::isError($e = $this->_lock(LOCK_EX))) {
1877
        if (PEAR::isError($e = $this->_lock(LOCK_EX))) {
1707
            return $e;
1878
            return $e;
1708
        }
1879
        }
1709
        $ret = $this->_updatePackage($package, $info, $merge);
1880
        $ret = $this->_updatePackage($package, $info, $merge);
1710
        $this->_unlock();
1881
        $this->_unlock();
1711
        if ($ret) {
1882
        if ($ret) {
1712
            if (!class_exists('PEAR_PackageFile_v1')) {
1883
            if (!class_exists('PEAR_PackageFile_v1')) {
1713
                require_once 'PEAR/PackageFile/v1.php';
1884
                require_once 'PEAR/PackageFile/v1.php';
1714
            }
1885
            }
1715
            $pf = new PEAR_PackageFile_v1;
1886
            $pf = new PEAR_PackageFile_v1;
1716
            $pf->setConfig($this->_config);
1887
            $pf->setConfig($this->_config);
1717
            $pf->fromArray($this->packageInfo($package));
1888
            $pf->fromArray($this->packageInfo($package));
1718
            $this->_dependencyDB->uninstallPackage($pf);
1889
            $this->_dependencyDB->uninstallPackage($pf);
1719
            $this->_dependencyDB->installPackage($pf);
1890
            $this->_dependencyDB->installPackage($pf);
1720
        }
1891
        }
1721
        return $ret;
1892
        return $ret;
1722
    }
1893
    }
1723
 
1894
 
1724
    // }}}
1895
    // }}}
1725
    // {{{ updatePackage2()
1896
    // {{{ updatePackage2()
1726
 
1897
 
1727
    function updatePackage2($info)
1898
    function updatePackage2($info)
1728
    {
1899
    {
-
 
1900
 
1729
        if (!is_object($info)) {
1901
        if (!is_object($info)) {
1730
            return $this->updatePackage($info['package'], $info, $merge);
1902
            return $this->updatePackage($info['package'], $info, $merge);
1731
        }
1903
        }
-
 
1904
 
1732
        if (!$info->validate(PEAR_VALIDATE_DOWNLOADING)) {
1905
        if (!$info->validate(PEAR_VALIDATE_DOWNLOADING)) {
1733
            return false;
1906
            return false;
1734
        }
1907
        }
-
 
1908
 
1735
        if (PEAR::isError($e = $this->_lock(LOCK_EX))) {
1909
        if (PEAR::isError($e = $this->_lock(LOCK_EX))) {
1736
            return $e;
1910
            return $e;
1737
        }
1911
        }
-
 
1912
 
1738
        $ret = $this->_updatePackage2($info);
1913
        $ret = $this->_updatePackage2($info);
1739
        $this->_unlock();
1914
        $this->_unlock();
1740
        if ($ret) {
1915
        if ($ret) {
1741
            $this->_dependencyDB->uninstallPackage($info);
1916
            $this->_dependencyDB->uninstallPackage($info);
1742
            $this->_dependencyDB->installPackage($info);
1917
            $this->_dependencyDB->installPackage($info);
1743
        }
1918
        }
-
 
1919
 
1744
        return $ret;
1920
        return $ret;
1745
    }
1921
    }
1746
 
1922
 
1747
    // }}}
1923
    // }}}
1748
    // {{{ getChannel()
1924
    // {{{ getChannel()
1749
    /**
1925
    /**
1750
     * @param string channel name
1926
     * @param string channel name
1751
     * @param bool whether to strictly return raw channels (no aliases)
1927
     * @param bool whether to strictly return raw channels (no aliases)
1752
     * @return PEAR_ChannelFile|PEAR_Error
1928
     * @return PEAR_ChannelFile|PEAR_Error
1753
     */
1929
     */
1754
    function &getChannel($channel, $noaliases = false)
1930
    function getChannel($channel, $noaliases = false)
1755
    {
1931
    {
1756
        if (PEAR::isError($e = $this->_lock(LOCK_SH))) {
1932
        if (PEAR::isError($e = $this->_lock(LOCK_SH))) {
1757
            return $e;
1933
            return $e;
1758
        }
1934
        }
1759
        $ret = &$this->_getChannel($channel, $noaliases);
1935
        $ret = $this->_getChannel($channel, $noaliases);
-
 
1936
        $this->_unlock();
1760
        if (!$ret) {
1937
        if (!$ret) {
1761
            return PEAR::raiseError('Unknown channel: ' . $channel);
1938
            return PEAR::raiseError('Unknown channel: ' . $channel);
1762
        }
1939
        }
1763
        $this->_unlock();
-
 
1764
        return $ret;
1940
        return $ret;
1765
    }
1941
    }
1766
 
1942
 
1767
    // }}}
1943
    // }}}
1768
    // {{{ getPackage()
1944
    // {{{ getPackage()
1769
    /**
1945
    /**
1770
     * @param string package name
1946
     * @param string package name
1771
     * @param string channel name
1947
     * @param string channel name
1772
     * @return PEAR_PackageFile_v1|PEAR_PackageFile_v2|null
1948
     * @return PEAR_PackageFile_v1|PEAR_PackageFile_v2|null
1773
     */
1949
     */
1774
    function &getPackage($package, $channel = 'pear.php.net')
1950
    function &getPackage($package, $channel = 'pear.php.net')
1775
    {
1951
    {
1776
        if (PEAR::isError($e = $this->_lock(LOCK_SH))) {
1952
        if (PEAR::isError($e = $this->_lock(LOCK_SH))) {
1777
            return $e;
1953
            return $e;
1778
        }
1954
        }
1779
        $pf = &$this->_getPackage($package, $channel);
1955
        $pf = &$this->_getPackage($package, $channel);
1780
        $this->_unlock();
1956
        $this->_unlock();
1781
        return $pf;
1957
        return $pf;
1782
    }
1958
    }
1783
 
1959
 
1784
    // }}}
1960
    // }}}
1785
 
1961
 
1786
    /**
1962
    /**
1787
     * Get PEAR_PackageFile_v[1/2] objects representing the contents of
1963
     * Get PEAR_PackageFile_v[1/2] objects representing the contents of
1788
     * a dependency group that are installed.
1964
     * a dependency group that are installed.
1789
     *
1965
     *
1790
     * This is used at uninstall-time
1966
     * This is used at uninstall-time
1791
     * @param array
1967
     * @param array
1792
     * @return array|false
1968
     * @return array|false
1793
     */
1969
     */
1794
    function getInstalledGroup($group)
1970
    function getInstalledGroup($group)
1795
    {
1971
    {
1796
        $ret = array();
1972
        $ret = array();
1797
        if (isset($group['package'])) {
1973
        if (isset($group['package'])) {
1798
            if (!isset($group['package'][0])) {
1974
            if (!isset($group['package'][0])) {
1799
                $group['package'] = array($group['package']);
1975
                $group['package'] = array($group['package']);
1800
            }
1976
            }
1801
            foreach ($group['package'] as $package) {
1977
            foreach ($group['package'] as $package) {
1802
                $depchannel = isset($package['channel']) ? $package['channel'] : '__uri';
1978
                $depchannel = isset($package['channel']) ? $package['channel'] : '__uri';
1803
                $p = &$this->getPackage($package['name'], $depchannel);
1979
                $p = &$this->getPackage($package['name'], $depchannel);
1804
                if ($p) {
1980
                if ($p) {
1805
                    $save = &$p;
1981
                    $save = &$p;
1806
                    $ret[] = &$save;
1982
                    $ret[] = &$save;
1807
                }
1983
                }
1808
            }
1984
            }
1809
        }
1985
        }
1810
        if (isset($group['subpackage'])) {
1986
        if (isset($group['subpackage'])) {
1811
            if (!isset($group['subpackage'][0])) {
1987
            if (!isset($group['subpackage'][0])) {
1812
                $group['subpackage'] = array($group['subpackage']);
1988
                $group['subpackage'] = array($group['subpackage']);
1813
            }
1989
            }
1814
            foreach ($group['subpackage'] as $package) {
1990
            foreach ($group['subpackage'] as $package) {
1815
                $depchannel = isset($package['channel']) ? $package['channel'] : '__uri';
1991
                $depchannel = isset($package['channel']) ? $package['channel'] : '__uri';
1816
                $p = &$this->getPackage($package['name'], $depchannel);
1992
                $p = &$this->getPackage($package['name'], $depchannel);
1817
                if ($p) {
1993
                if ($p) {
1818
                    $save = &$p;
1994
                    $save = &$p;
1819
                    $ret[] = &$save;
1995
                    $ret[] = &$save;
1820
                }
1996
                }
1821
            }
1997
            }
1822
        }
1998
        }
1823
        if (!count($ret)) {
1999
        if (!count($ret)) {
1824
            return false;
2000
            return false;
1825
        }
2001
        }
1826
        return $ret;
2002
        return $ret;
1827
    }
2003
    }
1828
 
2004
 
1829
    // {{{ getChannelValidator()
2005
    // {{{ getChannelValidator()
1830
    /**
2006
    /**
1831
     * @param string channel name
2007
     * @param string channel name
1832
     * @return PEAR_Validate|false
2008
     * @return PEAR_Validate|false
1833
     */
2009
     */
1834
    function &getChannelValidator($channel)
2010
    function &getChannelValidator($channel)
1835
    {
2011
    {
1836
        $chan = $this->getChannel($channel);
2012
        $chan = $this->getChannel($channel);
1837
        if (PEAR::isError($chan)) {
2013
        if (PEAR::isError($chan)) {
1838
            return $chan;
2014
            return $chan;
1839
        }
2015
        }
1840
        $val = $chan->getValidationObject();
2016
        $val = $chan->getValidationObject();
1841
        return $val;
2017
        return $val;
1842
    }
2018
    }
1843
    // }}}
2019
    // }}}
1844
    // {{{ getChannels()
2020
    // {{{ getChannels()
1845
    /**
2021
    /**
1846
     * @param string channel name
2022
     * @param string channel name
1847
     * @return array an array of PEAR_ChannelFile objects representing every installed channel
2023
     * @return array an array of PEAR_ChannelFile objects representing every installed channel
1848
     */
2024
     */
1849
    function &getChannels()
2025
    function &getChannels()
1850
    {
2026
    {
1851
        $ret = array();
2027
        $ret = array();
1852
        if (PEAR::isError($e = $this->_lock(LOCK_SH))) {
2028
        if (PEAR::isError($e = $this->_lock(LOCK_SH))) {
1853
            return $e;
2029
            return $e;
1854
        }
2030
        }
1855
        foreach ($this->_listChannels() as $channel) {
2031
        foreach ($this->_listChannels() as $channel) {
1856
            $e = &$this->_getChannel($channel);
2032
            $e = &$this->_getChannel($channel);
1857
            if (!$e || PEAR::isError($e)) {
2033
            if (!$e || PEAR::isError($e)) {
1858
                continue;
2034
                continue;
1859
            }
2035
            }
1860
            $ret[] = $e;
2036
            $ret[] = $e;
1861
        }
2037
        }
1862
        $this->_unlock();
2038
        $this->_unlock();
1863
        return $ret;
2039
        return $ret;
1864
    }
2040
    }
1865
 
2041
 
1866
    // }}}
2042
    // }}}
1867
    // {{{ checkFileMap()
2043
    // {{{ checkFileMap()
1868
 
2044
 
1869
    /**
2045
    /**
1870
     * Test whether a file or set of files belongs to a package.
2046
     * Test whether a file or set of files belongs to a package.
1871
     *
2047
     *
1872
     * If an array is passed in
2048
     * If an array is passed in
1873
     * @param string|array file path, absolute or relative to the pear
2049
     * @param string|array file path, absolute or relative to the pear
1874
     *                     install dir
2050
     *                     install dir
1875
     * @param string|array name of PEAR package or array('package' => name, 'channel' =>
2051
     * @param string|array name of PEAR package or array('package' => name, 'channel' =>
1876
     *                     channel) of a package that will be ignored
2052
     *                     channel) of a package that will be ignored
1877
     * @param string API version - 1.1 will exclude any files belonging to a package
2053
     * @param string API version - 1.1 will exclude any files belonging to a package
1878
     * @param array private recursion variable
2054
     * @param array private recursion variable
1879
     * @return array|false which package and channel the file belongs to, or an empty
2055
     * @return array|false which package and channel the file belongs to, or an empty
1880
     *                     string if the file does not belong to an installed package,
2056
     *                     string if the file does not belong to an installed package,
1881
     *                     or belongs to the second parameter's package
2057
     *                     or belongs to the second parameter's package
1882
     */
2058
     */
1883
    function checkFileMap($path, $package = false, $api = '1.0', $attrs = false)
2059
    function checkFileMap($path, $package = false, $api = '1.0', $attrs = false)
1884
    {
2060
    {
1885
        if (is_array($path)) {
2061
        if (is_array($path)) {
1886
            static $notempty;
2062
            static $notempty;
1887
            if (empty($notempty)) {
2063
            if (empty($notempty)) {
1888
                if (!class_exists('PEAR_Installer_Role')) {
2064
                if (!class_exists('PEAR_Installer_Role')) {
1889
                    require_once 'PEAR/Installer/Role.php';
2065
                    require_once 'PEAR/Installer/Role.php';
1890
                }
2066
                }
1891
                $notempty = create_function('$a','return !empty($a);');
2067
                $notempty = create_function('$a','return !empty($a);');
1892
            }
2068
            }
1893
            $package = is_array($package) ? array(strtolower($package[0]), strtolower($package[1]))
2069
            $package = is_array($package) ? array(strtolower($package[0]), strtolower($package[1]))
1894
                : strtolower($package);
2070
                : strtolower($package);
1895
            $pkgs = array();
2071
            $pkgs = array();
1896
            foreach ($path as $name => $attrs) {
2072
            foreach ($path as $name => $attrs) {
1897
                if (is_array($attrs)) {
2073
                if (is_array($attrs)) {
1898
                    if (isset($attrs['install-as'])) {
2074
                    if (isset($attrs['install-as'])) {
1899
                        $name = $attrs['install-as'];
2075
                        $name = $attrs['install-as'];
1900
                    }
2076
                    }
1901
                    if (!in_array($attrs['role'], PEAR_Installer_Role::getInstallableRoles())) {
2077
                    if (!in_array($attrs['role'], PEAR_Installer_Role::getInstallableRoles())) {
1902
                        // these are not installed
2078
                        // these are not installed
1903
                        continue;
2079
                        continue;
1904
                    }
2080
                    }
1905
                    if (!in_array($attrs['role'], PEAR_Installer_Role::getBaseinstallRoles())) {
2081
                    if (!in_array($attrs['role'], PEAR_Installer_Role::getBaseinstallRoles())) {
1906
                        $attrs['baseinstalldir'] = is_array($package) ? $package[1] : $package;
2082
                        $attrs['baseinstalldir'] = is_array($package) ? $package[1] : $package;
1907
                    }
2083
                    }
1908
                    if (isset($attrs['baseinstalldir'])) {
2084
                    if (isset($attrs['baseinstalldir'])) {
1909
                        $name = $attrs['baseinstalldir'] . DIRECTORY_SEPARATOR . $name;
2085
                        $name = $attrs['baseinstalldir'] . DIRECTORY_SEPARATOR . $name;
1910
                    }
2086
                    }
1911
                }
2087
                }
1912
                $pkgs[$name] = $this->checkFileMap($name, $package, $api, $attrs);
2088
                $pkgs[$name] = $this->checkFileMap($name, $package, $api, $attrs);
1913
                if (PEAR::isError($pkgs[$name])) {
2089
                if (PEAR::isError($pkgs[$name])) {
1914
                    return $pkgs[$name];
2090
                    return $pkgs[$name];
1915
                }
2091
                }
1916
            }
2092
            }
1917
            return array_filter($pkgs, $notempty);
2093
            return array_filter($pkgs, $notempty);
1918
        }
2094
        }
1919
        if (empty($this->filemap_cache)) {
2095
        if (empty($this->filemap_cache)) {
1920
            if (PEAR::isError($e = $this->_lock(LOCK_SH))) {
2096
            if (PEAR::isError($e = $this->_lock(LOCK_SH))) {
1921
                return $e;
2097
                return $e;
1922
            }
2098
            }
1923
            $err = $this->_readFileMap();
2099
            $err = $this->_readFileMap();
1924
            $this->_unlock();
2100
            $this->_unlock();
1925
            if (PEAR::isError($err)) {
2101
            if (PEAR::isError($err)) {
1926
                return $err;
2102
                return $err;
1927
            }
2103
            }
1928
        }
2104
        }
1929
        if (!$attrs) {
2105
        if (!$attrs) {
1930
            $attrs = array('role' => 'php'); // any old call would be for PHP role only
2106
            $attrs = array('role' => 'php'); // any old call would be for PHP role only
1931
        }
2107
        }
1932
        if (isset($this->filemap_cache[$attrs['role']][$path])) {
2108
        if (isset($this->filemap_cache[$attrs['role']][$path])) {
1933
            if ($api >= '1.1' && $this->filemap_cache[$attrs['role']][$path] == $package) {
2109
            if ($api >= '1.1' && $this->filemap_cache[$attrs['role']][$path] == $package) {
1934
                return false;
2110
                return false;
1935
            }
2111
            }
1936
            return $this->filemap_cache[$attrs['role']][$path];
2112
            return $this->filemap_cache[$attrs['role']][$path];
1937
        }
2113
        }
1938
        $l = strlen($this->install_dir);
2114
        $l = strlen($this->install_dir);
1939
        if (substr($path, 0, $l) == $this->install_dir) {
2115
        if (substr($path, 0, $l) == $this->install_dir) {
1940
            $path = preg_replace('!^'.DIRECTORY_SEPARATOR.'+!', '', substr($path, $l));
2116
            $path = preg_replace('!^'.DIRECTORY_SEPARATOR.'+!', '', substr($path, $l));
1941
        }
2117
        }
1942
        if (isset($this->filemap_cache[$attrs['role']][$path])) {
2118
        if (isset($this->filemap_cache[$attrs['role']][$path])) {
1943
            if ($api >= '1.1' && $this->filemap_cache[$attrs['role']][$path] == $package) {
2119
            if ($api >= '1.1' && $this->filemap_cache[$attrs['role']][$path] == $package) {
1944
                return false;
2120
                return false;
1945
            }
2121
            }
1946
            return $this->filemap_cache[$attrs['role']][$path];
2122
            return $this->filemap_cache[$attrs['role']][$path];
1947
        }
2123
        }
1948
        return false;
2124
        return false;
1949
    }
2125
    }
1950
 
2126
 
1951
    // }}}
2127
    // }}}
1952
    // {{{ flush()
2128
    // {{{ flush()
1953
    /**
2129
    /**
1954
     * Force a reload of the filemap
2130
     * Force a reload of the filemap
1955
     * @since 1.5.0RC3
2131
     * @since 1.5.0RC3
1956
     */
2132
     */
1957
    function flushFileMap()
2133
    function flushFileMap()
1958
    {
2134
    {
1959
        $this->filemap_cache = null;
2135
        $this->filemap_cache = null;
1960
        clearstatcache(); // ensure that the next read gets the full, current filemap
2136
        clearstatcache(); // ensure that the next read gets the full, current filemap
1961
    }
2137
    }
1962
 
2138
 
1963
    // }}}
2139
    // }}}
1964
    // {{{ apiVersion()
2140
    // {{{ apiVersion()
1965
    /**
2141
    /**
1966
     * Get the expected API version.  Channels API is version 1.1, as it is backwards
2142
     * Get the expected API version.  Channels API is version 1.1, as it is backwards
1967
     * compatible with 1.0
2143
     * compatible with 1.0
1968
     * @return string
2144
     * @return string
1969
     */
2145
     */
1970
    function apiVersion()
2146
    function apiVersion()
1971
    {
2147
    {
1972
        return '1.1';
2148
        return '1.1';
1973
    }
2149
    }
1974
    // }}}
2150
    // }}}
1975
 
2151
 
1976
 
2152
 
1977
    /**
2153
    /**
1978
     * Parse a package name, or validate a parsed package name array
2154
     * Parse a package name, or validate a parsed package name array
1979
     * @param string|array pass in an array of format
2155
     * @param string|array pass in an array of format
1980
     *                     array(
2156
     *                     array(
1981
     *                      'package' => 'pname',
2157
     *                      'package' => 'pname',
1982
     *                     ['channel' => 'channame',]
2158
     *                     ['channel' => 'channame',]
1983
     *                     ['version' => 'version',]
2159
     *                     ['version' => 'version',]
1984
     *                     ['state' => 'state',]
2160
     *                     ['state' => 'state',]
1985
     *                     ['group' => 'groupname'])
2161
     *                     ['group' => 'groupname'])
1986
     *                     or a string of format
2162
     *                     or a string of format
1987
     *                     [channel://][channame/]pname[-version|-state][/group=groupname]
2163
     *                     [channel://][channame/]pname[-version|-state][/group=groupname]
1988
     * @return array|PEAR_Error
2164
     * @return array|PEAR_Error
1989
     */
2165
     */
1990
    function parsePackageName($param, $defaultchannel = 'pear.php.net')
2166
    function parsePackageName($param, $defaultchannel = 'pear.php.net')
1991
    {
2167
    {
1992
        $saveparam = $param;
2168
        $saveparam = $param;
1993
        if (is_array($param)) {
2169
        if (is_array($param)) {
1994
            // convert to string for error messages
2170
            // convert to string for error messages
1995
            $saveparam = $this->parsedPackageNameToString($param);
2171
            $saveparam = $this->parsedPackageNameToString($param);
1996
            // process the array
2172
            // process the array
1997
            if (!isset($param['package'])) {
2173
            if (!isset($param['package'])) {
1998
                return PEAR::raiseError('parsePackageName(): array $param ' .
2174
                return PEAR::raiseError('parsePackageName(): array $param ' .
1999
                    'must contain a valid package name in index "param"',
2175
                    'must contain a valid package name in index "param"',
2000
                    'package', null, null, $param);
2176
                    'package', null, null, $param);
2001
            }
2177
            }
2002
            if (!isset($param['uri'])) {
2178
            if (!isset($param['uri'])) {
2003
                if (!isset($param['channel'])) {
2179
                if (!isset($param['channel'])) {
2004
                    $param['channel'] = $defaultchannel;
2180
                    $param['channel'] = $defaultchannel;
2005
                }
2181
                }
2006
            } else {
2182
            } else {
2007
                $param['channel'] = '__uri';
2183
                $param['channel'] = '__uri';
2008
            }
2184
            }
2009
        } else {
2185
        } else {
2010
            $components = @parse_url((string) $param);
2186
            $components = @parse_url((string) $param);
2011
            if (isset($components['scheme'])) {
2187
            if (isset($components['scheme'])) {
2012
                if ($components['scheme'] == 'http') {
2188
                if ($components['scheme'] == 'http') {
2013
                    // uri package
2189
                    // uri package
2014
                    $param = array('uri' => $param, 'channel' => '__uri');
2190
                    $param = array('uri' => $param, 'channel' => '__uri');
2015
                } elseif($components['scheme'] != 'channel') {
2191
                } elseif($components['scheme'] != 'channel') {
2016
                    return PEAR::raiseError('parsePackageName(): only channel:// uris may ' .
2192
                    return PEAR::raiseError('parsePackageName(): only channel:// uris may ' .
2017
                        'be downloaded, not "' . $param . '"', 'invalid', null, null, $param);
2193
                        'be downloaded, not "' . $param . '"', 'invalid', null, null, $param);
2018
                }
2194
                }
2019
            }
2195
            }
2020
            if (!isset($components['path'])) {
2196
            if (!isset($components['path'])) {
2021
                return PEAR::raiseError('parsePackageName(): array $param ' .
2197
                return PEAR::raiseError('parsePackageName(): array $param ' .
2022
                    'must contain a valid package name in "' . $param . '"',
2198
                    'must contain a valid package name in "' . $param . '"',
2023
                    'package', null, null, $param);
2199
                    'package', null, null, $param);
2024
            }
2200
            }
2025
            if (isset($components['host'])) {
2201
            if (isset($components['host'])) {
2026
                // remove the leading "/"
2202
                // remove the leading "/"
2027
                $components['path'] = substr($components['path'], 1);
2203
                $components['path'] = substr($components['path'], 1);
2028
            }
2204
            }
2029
            if (!isset($components['scheme'])) {
2205
            if (!isset($components['scheme'])) {
2030
                if (strpos($components['path'], '/') !== false) {
2206
                if (strpos($components['path'], '/') !== false) {
2031
                    if ($components['path']{0} == '/') {
2207
                    if ($components['path']{0} == '/') {
2032
                        return PEAR::raiseError('parsePackageName(): this is not ' .
2208
                        return PEAR::raiseError('parsePackageName(): this is not ' .
2033
                            'a package name, it begins with "/" in "' . $param . '"',
2209
                            'a package name, it begins with "/" in "' . $param . '"',
2034
                            'invalid', null, null, $param);
2210
                            'invalid', null, null, $param);
2035
                    }
2211
                    }
2036
                    $parts = explode('/', $components['path']);
2212
                    $parts = explode('/', $components['path']);
2037
                    $components['host'] = array_shift($parts);
2213
                    $components['host'] = array_shift($parts);
2038
                    if (count($parts) > 1) {
2214
                    if (count($parts) > 1) {
2039
                        $components['path'] = array_pop($parts);
2215
                        $components['path'] = array_pop($parts);
2040
                        $components['host'] .= '/' . implode('/', $parts);
2216
                        $components['host'] .= '/' . implode('/', $parts);
2041
                    } else {
2217
                    } else {
2042
                        $components['path'] = implode('/', $parts);
2218
                        $components['path'] = implode('/', $parts);
2043
                    }
2219
                    }
2044
                } else {
2220
                } else {
2045
                    $components['host'] = $defaultchannel;
2221
                    $components['host'] = $defaultchannel;
2046
                }
2222
                }
2047
            } else {
2223
            } else {
2048
                if (strpos($components['path'], '/')) {
2224
                if (strpos($components['path'], '/')) {
2049
                    $parts = explode('/', $components['path']);
2225
                    $parts = explode('/', $components['path']);
2050
                    $components['path'] = array_pop($parts);
2226
                    $components['path'] = array_pop($parts);
2051
                    $components['host'] .= '/' . implode('/', $parts);
2227
                    $components['host'] .= '/' . implode('/', $parts);
2052
                }
2228
                }
2053
            }
2229
            }
2054
 
2230
 
2055
            if (is_array($param)) {
2231
            if (is_array($param)) {
2056
                $param['package'] = $components['path'];
2232
                $param['package'] = $components['path'];
2057
            } else {
2233
            } else {
2058
                $param = array(
2234
                $param = array(
2059
                    'package' => $components['path']
2235
                    'package' => $components['path']
2060
                    );
2236
                    );
2061
                if (isset($components['host'])) {
2237
                if (isset($components['host'])) {
2062
                    $param['channel'] = $components['host'];
2238
                    $param['channel'] = $components['host'];
2063
                }
2239
                }
2064
            }
2240
            }
2065
            if (isset($components['fragment'])) {
2241
            if (isset($components['fragment'])) {
2066
                $param['group'] = $components['fragment'];
2242
                $param['group'] = $components['fragment'];
2067
            }
2243
            }
2068
            if (isset($components['user'])) {
2244
            if (isset($components['user'])) {
2069
                $param['user'] = $components['user'];
2245
                $param['user'] = $components['user'];
2070
            }
2246
            }
2071
            if (isset($components['pass'])) {
2247
            if (isset($components['pass'])) {
2072
                $param['pass'] = $components['pass'];
2248
                $param['pass'] = $components['pass'];
2073
            }
2249
            }
2074
            if (isset($components['query'])) {
2250
            if (isset($components['query'])) {
2075
                parse_str($components['query'], $param['opts']);
2251
                parse_str($components['query'], $param['opts']);
2076
            }
2252
            }
2077
            // check for extension
2253
            // check for extension
2078
            $pathinfo = pathinfo($param['package']);
2254
            $pathinfo = pathinfo($param['package']);
2079
            if (isset($pathinfo['extension']) &&
2255
            if (isset($pathinfo['extension']) &&
2080
                  in_array(strtolower($pathinfo['extension']), array('tgz', 'tar'))) {
2256
                  in_array(strtolower($pathinfo['extension']), array('tgz', 'tar'))) {
2081
                $param['extension'] = $pathinfo['extension'];
2257
                $param['extension'] = $pathinfo['extension'];
2082
                $param['package'] = substr($pathinfo['basename'], 0,
2258
                $param['package'] = substr($pathinfo['basename'], 0,
2083
                    strlen($pathinfo['basename']) - 4);
2259
                    strlen($pathinfo['basename']) - 4);
2084
            }
2260
            }
2085
            // check for version
2261
            // check for version
2086
            if (strpos($param['package'], '-')) {
2262
            if (strpos($param['package'], '-')) {
2087
                $test = explode('-', $param['package']);
2263
                $test = explode('-', $param['package']);
2088
                if (count($test) != 2) {
2264
                if (count($test) != 2) {
2089
                    return PEAR::raiseError('parsePackageName(): only one version/state ' .
2265
                    return PEAR::raiseError('parsePackageName(): only one version/state ' .
2090
                        'delimiter "-" is allowed in "' . $saveparam . '"',
2266
                        'delimiter "-" is allowed in "' . $saveparam . '"',
2091
                        'version', null, null, $param);
2267
                        'version', null, null, $param);
2092
                }
2268
                }
2093
                list($param['package'], $param['version']) = $test;
2269
                list($param['package'], $param['version']) = $test;
2094
            }
2270
            }
2095
        }
2271
        }
2096
        // validation
2272
        // validation
2097
        $info = $this->channelExists($param['channel']);
2273
        $info = $this->channelExists($param['channel']);
2098
        if (PEAR::isError($info)) {
2274
        if (PEAR::isError($info)) {
2099
            return $info;
2275
            return $info;
2100
        }
2276
        }
2101
        if (!$info) {
2277
        if (!$info) {
2102
            return PEAR::raiseError('unknown channel "' . $param['channel'] .
2278
            return PEAR::raiseError('unknown channel "' . $param['channel'] .
2103
                '" in "' . $saveparam . '"', 'channel', null, null, $param);
2279
                '" in "' . $saveparam . '"', 'channel', null, null, $param);
2104
        }
2280
        }
2105
        $chan = $this->getChannel($param['channel']);
2281
        $chan = $this->getChannel($param['channel']);
2106
        if (PEAR::isError($chan)) {
2282
        if (PEAR::isError($chan)) {
2107
            return $chan;
2283
            return $chan;
2108
        }
2284
        }
2109
        if (!$chan) {
2285
        if (!$chan) {
2110
            return PEAR::raiseError("Exception: corrupt registry, could not " .
2286
            return PEAR::raiseError("Exception: corrupt registry, could not " .
2111
                "retrieve channel " . $param['channel'] . " information",
2287
                "retrieve channel " . $param['channel'] . " information",
2112
                'registry', null, null, $param);
2288
                'registry', null, null, $param);
2113
        }
2289
        }
2114
        $param['channel'] = $chan->getName();
2290
        $param['channel'] = $chan->getName();
2115
        $validate = $chan->getValidationObject();
2291
        $validate = $chan->getValidationObject();
2116
        $vpackage = $chan->getValidationPackage();
2292
        $vpackage = $chan->getValidationPackage();
2117
        // validate package name
2293
        // validate package name
2118
        if (!$validate->validPackageName($param['package'], $vpackage['_content'])) {
2294
        if (!$validate->validPackageName($param['package'], $vpackage['_content'])) {
2119
            return PEAR::raiseError('parsePackageName(): invalid package name "' .
2295
            return PEAR::raiseError('parsePackageName(): invalid package name "' .
2120
                $param['package'] . '" in "' . $saveparam . '"',
2296
                $param['package'] . '" in "' . $saveparam . '"',
2121
                'package', null, null, $param);
2297
                'package', null, null, $param);
2122
        }
2298
        }
2123
        if (isset($param['group'])) {
2299
        if (isset($param['group'])) {
2124
            if (!PEAR_Validate::validGroupName($param['group'])) {
2300
            if (!PEAR_Validate::validGroupName($param['group'])) {
2125
                return PEAR::raiseError('parsePackageName(): dependency group "' . $param['group'] .
2301
                return PEAR::raiseError('parsePackageName(): dependency group "' . $param['group'] .
2126
                    '" is not a valid group name in "' . $saveparam . '"', 'group', null, null,
2302
                    '" is not a valid group name in "' . $saveparam . '"', 'group', null, null,
2127
                    $param);
2303
                    $param);
2128
            }
2304
            }
2129
        }
2305
        }
2130
        if (isset($param['state'])) {
2306
        if (isset($param['state'])) {
2131
            if (!in_array(strtolower($param['state']), $validate->getValidStates())) {
2307
            if (!in_array(strtolower($param['state']), $validate->getValidStates())) {
2132
                return PEAR::raiseError('parsePackageName(): state "' . $param['state']
2308
                return PEAR::raiseError('parsePackageName(): state "' . $param['state']
2133
                    . '" is not a valid state in "' . $saveparam . '"',
2309
                    . '" is not a valid state in "' . $saveparam . '"',
2134
                    'state', null, null, $param);
2310
                    'state', null, null, $param);
2135
            }
2311
            }
2136
        }
2312
        }
2137
        if (isset($param['version'])) {
2313
        if (isset($param['version'])) {
2138
            if (isset($param['state'])) {
2314
            if (isset($param['state'])) {
2139
                return PEAR::raiseError('parsePackageName(): cannot contain both ' .
2315
                return PEAR::raiseError('parsePackageName(): cannot contain both ' .
2140
                    'a version and a stability (state) in "' . $saveparam . '"',
2316
                    'a version and a stability (state) in "' . $saveparam . '"',
2141
                    'version/state', null, null, $param);
2317
                    'version/state', null, null, $param);
2142
            }
2318
            }
2143
            // check whether version is actually a state
2319
            // check whether version is actually a state
2144
            if (in_array(strtolower($param['version']), $validate->getValidStates())) {
2320
            if (in_array(strtolower($param['version']), $validate->getValidStates())) {
2145
                $param['state'] = strtolower($param['version']);
2321
                $param['state'] = strtolower($param['version']);
2146
                unset($param['version']);
2322
                unset($param['version']);
2147
            } else {
2323
            } else {
2148
                if (!$validate->validVersion($param['version'])) {
2324
                if (!$validate->validVersion($param['version'])) {
2149
                    return PEAR::raiseError('parsePackageName(): "' . $param['version'] .
2325
                    return PEAR::raiseError('parsePackageName(): "' . $param['version'] .
2150
                        '" is neither a valid version nor a valid state in "' .
2326
                        '" is neither a valid version nor a valid state in "' .
2151
                        $saveparam . '"', 'version/state', null, null, $param);
2327
                        $saveparam . '"', 'version/state', null, null, $param);
2152
                }                    
2328
                }
2153
            }
2329
            }
2154
        }
2330
        }
2155
        return $param;
2331
        return $param;
2156
    }
2332
    }
2157
 
2333
 
2158
    /**
2334
    /**
2159
     * @param array
2335
     * @param array
2160
     * @return string
2336
     * @return string
2161
     */
2337
     */
2162
    function parsedPackageNameToString($parsed, $brief = false)
2338
    function parsedPackageNameToString($parsed, $brief = false)
2163
    {
2339
    {
2164
        if (is_string($parsed)) {
2340
        if (is_string($parsed)) {
2165
            return $parsed;
2341
            return $parsed;
2166
        }
2342
        }
2167
        if (is_object($parsed)) {
2343
        if (is_object($parsed)) {
2168
            $p = $parsed;
2344
            $p = $parsed;
2169
            $parsed = array(
2345
            $parsed = array(
2170
                'package' => $p->getPackage(),
2346
                'package' => $p->getPackage(),
2171
                'channel' => $p->getChannel(),
2347
                'channel' => $p->getChannel(),
2172
                'version' => $p->getVersion(),
2348
                'version' => $p->getVersion(),
2173
            );
2349
            );
2174
        }
2350
        }
2175
        if (isset($parsed['uri'])) {
2351
        if (isset($parsed['uri'])) {
2176
            return $parsed['uri'];
2352
            return $parsed['uri'];
2177
        }
2353
        }
2178
        if ($brief) {
2354
        if ($brief) {
2179
            if ($channel = $this->channelAlias($parsed['channel'])) {
2355
            if ($channel = $this->channelAlias($parsed['channel'])) {
2180
                return $channel . '/' . $parsed['package'];
2356
                return $channel . '/' . $parsed['package'];
2181
            }
2357
            }
2182
        }
2358
        }
2183
        $upass = '';
2359
        $upass = '';
2184
        if (isset($parsed['user'])) {
2360
        if (isset($parsed['user'])) {
2185
            $upass = $parsed['user'];
2361
            $upass = $parsed['user'];
2186
            if (isset($parsed['pass'])) {
2362
            if (isset($parsed['pass'])) {
2187
                $upass .= ':' . $parsed['pass'];
2363
                $upass .= ':' . $parsed['pass'];
2188
            }
2364
            }
2189
            $upass = "$upass@";
2365
            $upass = "$upass@";
2190
        }
2366
        }
2191
        $ret = 'channel://' . $upass . $parsed['channel'] . '/' . $parsed['package'];
2367
        $ret = 'channel://' . $upass . $parsed['channel'] . '/' . $parsed['package'];
2192
        if (isset($parsed['version']) || isset($parsed['state'])) {
2368
        if (isset($parsed['version']) || isset($parsed['state'])) {
2193
            $ver = isset($parsed['version']) ? $parsed['version'] : '';
2369
            $ver = isset($parsed['version']) ? $parsed['version'] : '';
2194
            $ver .= isset($parsed['state']) ? $parsed['state'] : '';
2370
            $ver .= isset($parsed['state']) ? $parsed['state'] : '';
2195
            $ret .= '-' . $ver;
2371
            $ret .= '-' . $ver;
2196
        }
2372
        }
2197
        if (isset($parsed['extension'])) {
2373
        if (isset($parsed['extension'])) {
2198
            $ret .= '.' . $parsed['extension'];
2374
            $ret .= '.' . $parsed['extension'];
2199
        }
2375
        }
2200
        if (isset($parsed['opts'])) {
2376
        if (isset($parsed['opts'])) {
2201
            $ret .= '?';
2377
            $ret .= '?';
2202
            foreach ($parsed['opts'] as $name => $value) {
2378
            foreach ($parsed['opts'] as $name => $value) {
2203
                $parsed['opts'][$name] = "$name=$value";
2379
                $parsed['opts'][$name] = "$name=$value";
2204
            }
2380
            }
2205
            $ret .= implode('&', $parsed['opts']);
2381
            $ret .= implode('&', $parsed['opts']);
2206
        }
2382
        }
2207
        if (isset($parsed['group'])) {
2383
        if (isset($parsed['group'])) {
2208
            $ret .= '#' . $parsed['group'];
2384
            $ret .= '#' . $parsed['group'];
2209
        }
2385
        }
2210
        return $ret;
2386
        return $ret;
2211
    }
2387
    }
2212
}
2388
}
2213
 
-
 
2214
?>
-