Subversion Repositories Applications.gtt

Rev

Rev 94 | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 94 Rev 187
Line 2... Line 2...
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
 */
Line 24... Line 17...
24
 
17
 
25
/**
18
/**
26
 * for PEAR_Error
19
 * for PEAR_Error
27
 */
20
 */
28
require_once 'PEAR.php';
21
require_once 'PEAR.php';
Line 29... Line 22...
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);
Line 34... Line 27...
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
 */
-
 
50
class PEAR_Registry extends PEAR
-
 
51
{
42
 */
52
    // {{{ properties
43
class PEAR_Registry extends PEAR
53
 
44
{
54
    /**
45
    /**
55
     * File containing all channel information.
46
     * File containing all channel information.
Line 110... Line 101...
110
     * @var false|PEAR_ChannelFile
101
     * @var false|PEAR_ChannelFile
111
     */
102
     */
112
    var $_peclChannel;
103
    var $_peclChannel;
Line 113... Line 104...
113
 
104
 
-
 
105
    /**
-
 
106
     * @var false|PEAR_ChannelFile
-
 
107
     */
-
 
108
    var $_docChannel;
-
 
109
 
114
    /**
110
    /**
115
     * @var PEAR_DependencyDB
111
     * @var PEAR_DependencyDB
116
     */
112
     */
Line 117... Line 113...
117
    var $_dependencyDB;
113
    var $_dependencyDB;
118
 
114
 
119
    /**
115
    /**
120
     * @var PEAR_Config
116
     * @var PEAR_Config
121
     */
-
 
122
    var $_config;
-
 
123
    // }}}
-
 
Line 124... Line 117...
124
 
117
     */
125
    // {{{ constructor
118
    var $_config;
126
 
119
 
127
    /**
120
    /**
Line 135... Line 128...
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
    }
Line 154... Line 155...
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;
-
 
160
            while ($dir && $dir != '.') {
159
            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;
-
 
164
                    } else {
-
 
165
                        return false;
165
                        return true;
-
 
166
                    }
-
 
167
 
-
 
168
                    return false;
-
 
169
                }
-
 
170
 
-
 
171
                if ($dir == $olddir) { // this can happen in safe mode
166
                    }
172
                    return @is_writable($dir);
167
                }
173
                }
-
 
174
            }
168
            }
175
 
169
            return false;
176
            return false;
-
 
177
        }
170
        }
178
 
171
        return is_writeable($this->install_dir);
179
        return is_writeable($this->install_dir);
Line 172... Line 180...
172
    }
180
    }
173
 
181
 
174
    function setConfig(&$config)
182
    function setConfig(&$config, $resetInstallDir = true)
-
 
183
    {
-
 
184
        $this->_config = &$config;
-
 
185
        if ($resetInstallDir) {
175
    {
186
            $this->setInstallDir($config->get('php_dir'), $config->get('metadata_dir'));
Line 176... Line 187...
176
        $this->_config = &$config;
187
        }
177
    }
188
    }
178
 
189
 
Line 183... Line 194...
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
    }
Line 247... Line 292...
247
 
292
 
Line 252... Line 297...
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();
Line 272... Line 318...
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
-
 
Line 308... Line 351...
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
     *
Line 317... Line 360...
317
        if (is_resource($this->lock_fp)) {
360
        if (is_resource($this->lock_fp)) {
318
            $this->_unlock();
361
            $this->_unlock();
319
        }
362
        }
320
    }
363
    }
Line 321... Line -...
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
Line 334... Line 373...
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();
Line 370... Line 414...
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
    }
Line 377... Line -...
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
Line 394... Line 436...
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
    }
Line 419... Line -...
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
Line 432... Line 475...
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
    }
Line 461... Line -...
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
Line 476... Line 518...
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
    }
Line 483... Line -...
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
Line 498... Line 538...
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
    }
Line 502... Line -...
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';
Line 514... Line -...
514
    }
-
 
515
 
-
 
516
    // }}}
-
 
517
    // {{{ _getChannelFromAlias()
551
    }
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') {
-
 
560
                return 'pear.php.net';
526
                return 'pear.php.net';
561
            }
527
            }
562
 
528
            if ($channel == 'pecl.php.net') {
563
            if ($channel == 'pecl.php.net') {
-
 
564
                return 'pecl.php.net';
-
 
565
            }
-
 
566
 
-
 
567
            if ($channel == 'doc.php.net') {
-
 
568
                return 'doc.php.net';
529
                return 'pecl.php.net';
569
            }
530
            }
570
 
531
            if ($channel == '__uri') {
571
            if ($channel == '__uri') {
-
 
572
                return '__uri';
532
                return '__uri';
573
            }
533
            }
574
 
-
 
575
            return false;
534
            return false;
576
        }
535
        }
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
-
 
539
            return implode('', file($this->_getChannelAliasFileName($channel)));
-
 
540
        } else {
580
            // translate an alias to an actual channel
-
 
581
            return implode('', file($this->_getChannelAliasFileName($channel)));
-
 
582
        }
541
            return $channel;
583
 
542
        }
-
 
543
    }    
-
 
Line 544... Line 584...
544
    // }}}
584
        return $channel;
545
    // {{{ _getChannelFromAlias()
585
    }
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)) {
-
 
593
            if ($channel == 'pear.php.net') {
553
            if ($channel == 'pear.php.net') {
594
                return 'pear';
554
                return 'pear';
595
            }
555
            }
596
 
-
 
597
            if ($channel == 'pecl.php.net') {
-
 
598
                return 'pecl';
-
 
599
            }
-
 
600
 
-
 
601
            if ($channel == 'doc.php.net') {
556
            if ($channel == 'pecl.php.net') {
602
                return 'phpdocs';
557
                return 'pecl';
603
            }
-
 
604
 
558
            }
605
            return false;
559
            return false;
606
        }
560
        }
607
 
561
        $channel = $this->_getChannel($channel);
608
        $channel = $this->_getChannel($channel);
-
 
609
        if (PEAR::isError($channel)) {
562
        if (PEAR::isError($channel)) {
610
            return $channel;
563
            return $channel;
611
        }
564
        }
-
 
565
        return $channel->getAlias();
-
 
Line 566... Line 612...
566
    }    
612
 
567
    // }}}
613
        return $channel->getAlias();
568
    // {{{ _channelDirectoryName()
614
    }
569
 
615
 
Line 579... Line 625...
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
    }
-
 
Line -... Line 631...
-
 
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));
Line 595... Line 639...
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)) {
-
 
644
            return null;
600
            return null;
645
        }
601
        }
646
 
602
        if (!in_array($mode, array('r', 'rb')) && !$this->hasWriteAccess()) {
647
        if (!in_array($mode, array('r', 'rb')) && !$this->hasWriteAccess()) {
-
 
648
            return null;
603
            return null;
649
        }
604
        }
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') {
-
 
653
            return null;
607
            return null;
654
        }
608
        }
655
 
609
        $fp = @fopen($file, $mode);
656
        $fp = @fopen($file, $mode);
610
        if (!$fp) {
657
        if (!$fp) {
-
 
658
            return null;
611
            return null;
659
        }
612
        }
660
 
Line 613... Line -...
613
        return $fp;
-
 
614
    }
-
 
615
 
-
 
616
    // }}}
661
        return $fp;
617
    // {{{ _closePackageFile()
662
    }
618
 
663
 
619
    function _closePackageFile($fp)
664
    function _closePackageFile($fp)
Line 620... Line -...
620
    {
-
 
621
        fclose($fp);
-
 
622
    }
-
 
623
 
665
    {
624
    // }}}
666
        fclose($fp);
625
    // {{{ _openChannelFile()
667
    }
626
 
668
 
627
    function _openChannelFile($channel, $mode)
669
    function _openChannelFile($channel, $mode)
-
 
670
    {
628
    {
671
        if (!$this->_assertChannelDir()) {
629
        if (!$this->_assertChannelDir()) {
672
            return null;
630
            return null;
673
        }
-
 
674
 
631
        }
675
        if (!in_array($mode, array('r', 'rb')) && !$this->hasWriteAccess()) {
632
        if (!in_array($mode, array('r', 'rb')) && !$this->hasWriteAccess()) {
676
            return null;
633
            return null;
677
        }
634
        }
678
 
-
 
679
        $file = $this->_channelFileName($channel);
635
        $file = $this->_channelFileName($channel);
680
        if (!file_exists($file) && $mode == 'r' || $mode == 'rb') {
636
        if (!file_exists($file) && $mode == 'r' || $mode == 'rb') {
681
            return null;
637
            return null;
682
        }
638
        }
683
 
-
 
684
        $fp = @fopen($file, $mode);
639
        $fp = @fopen($file, $mode);
685
        if (!$fp) {
640
        if (!$fp) {
686
            return null;
Line 641... Line -...
641
            return null;
-
 
642
        }
-
 
643
        return $fp;
-
 
644
    }
687
        }
645
 
688
 
646
    // }}}
689
        return $fp;
647
    // {{{ _closePackageFile()
690
    }
Line 648... Line -...
648
 
-
 
649
    function _closeChannelFile($fp)
-
 
650
    {
-
 
651
        fclose($fp);
691
 
652
    }
692
    function _closeChannelFile($fp)
653
 
693
    {
654
    // }}}
694
        fclose($fp);
655
    // {{{ _rebuildFileMap()
695
    }
-
 
696
 
656
 
697
    function _rebuildFileMap()
657
    function _rebuildFileMap()
698
    {
658
    {
699
        if (!class_exists('PEAR_Installer_Role')) {
659
        if (!class_exists('PEAR_Installer_Role')) {
700
            require_once 'PEAR/Installer/Role.php';
660
            require_once 'PEAR/Installer/Role.php';
701
        }
661
        }
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) {
-
 
706
            foreach ($packages as $package) {
665
            foreach ($packages as $package) {
707
                $version = $this->_packageInfo($package, 'version', $channel);
666
                $version = $this->_packageInfo($package, 'version', $channel);
708
                $filelist = $this->_packageInfo($package, 'filelist', $channel);
667
                $filelist = $this->_packageInfo($package, 'filelist', $channel);
709
                if (!is_array($filelist)) {
668
                if (!is_array($filelist)) {
710
                    continue;
-
 
711
                }
669
                    continue;
712
 
670
                }
713
                foreach ($filelist as $name => $attrs) {
671
                foreach ($filelist as $name => $attrs) {
714
                    if (isset($attrs['attribs'])) {
672
                    if (isset($attrs['attribs'])) {
715
                        $attrs = $attrs['attribs'];
673
                        $attrs = $attrs['attribs'];
716
                    }
-
 
717
 
674
                    }
718
                    // it is possible for conflicting packages in different channels to
675
                    // it is possible for conflicting packages in different channels to
719
                    // conflict with data files/doc files
676
                    // conflict with data files/doc files
720
                    if ($name == 'dirtree') {
677
                    if ($name == 'dirtree') {
721
                        continue;
678
                        continue;
722
                    }
-
 
723
 
679
                    }
724
                    if (isset($attrs['role']) && !in_array($attrs['role'],
680
                    if (isset($attrs['role']) && !in_array($attrs['role'],
725
                          PEAR_Installer_Role::getInstallableRoles())) {
681
                          PEAR_Installer_Role::getInstallableRoles())) {
726
                        // these are not installed
682
                        // these are not installed
727
                        continue;
-
 
728
                    }
683
                        continue;
729
 
684
                    }
730
                    if (isset($attrs['role']) && !in_array($attrs['role'],
685
                    if (isset($attrs['role']) && !in_array($attrs['role'],
731
                          PEAR_Installer_Role::getBaseinstallRoles())) {
686
                          PEAR_Installer_Role::getBaseinstallRoles())) {
732
                        $attrs['baseinstalldir'] = $package;
687
                        $attrs['baseinstalldir'] = $package;
733
                    }
-
 
734
 
688
                    }
735
                    if (isset($attrs['baseinstalldir'])) {
689
                    if (isset($attrs['baseinstalldir'])) {
736
                        $file = $attrs['baseinstalldir'].DIRECTORY_SEPARATOR.$name;
-
 
737
                    } else {
-
 
738
                        $file = $name;
-
 
739
                    }
690
                        $file = $attrs['baseinstalldir'].DIRECTORY_SEPARATOR.$name;
740
 
691
                    } else {
741
                    $file = preg_replace(',^/+,', '', $file);
692
                        $file = $name;
742
                    if ($channel != 'pear.php.net') {
693
                    }
-
 
694
                    $file = preg_replace(',^/+,', '', $file);
-
 
695
                    if ($channel != 'pear.php.net') {
-
 
696
                        $files[$attrs['role']][$file] = array(strtolower($channel),
743
                        if (!isset($files[$attrs['role']])) {
697
                            strtolower($package));
744
                            $files[$attrs['role']] = array();
698
                    } else {
745
                        }
699
                        if (!is_array($files)) {
746
                        $files[$attrs['role']][$file] = array(strtolower($channel),
700
                            $file = array();
747
                            strtolower($package));
701
                        }
748
                    } else {
702
                        if (!isset($files[$attrs['role']])) {
749
                        if (!isset($files[$attrs['role']])) {
703
                            $files[$attrs['role']] = array();
750
                            $files[$attrs['role']] = array();
-
 
751
                        }
-
 
752
                        $files[$attrs['role']][$file] = strtolower($package);
704
                        }
753
                    }
705
                        $files[$attrs['role']][$file] = strtolower($package);
754
                }
706
                    }
755
            }
707
                }
756
        }
-
 
757
 
708
            }
758
 
709
        }
759
        $this->_assertStateDir();
710
        $this->_assertStateDir();
760
        if (!$this->hasWriteAccess()) {
711
        if (!$this->hasWriteAccess()) {
761
            return false;
-
 
762
        }
712
            return false;
763
 
713
        }
764
        $fp = @fopen($this->filemap, 'wb');
714
        $fp = @fopen($this->filemap, 'wb');
765
        if (!$fp) {
715
        if (!$fp) {
766
            return false;
716
            return false;
767
        }
Line 717... Line -...
717
        }
-
 
718
        $this->filemap_cache = $files;
-
 
719
        fwrite($fp, serialize($files));
-
 
720
        fclose($fp);
768
 
721
        return true;
769
        $this->filemap_cache = $files;
722
    }
770
        fwrite($fp, serialize($files));
723
 
771
        fclose($fp);
724
    // }}}
772
        return true;
-
 
773
    }
725
    // {{{ _readFileMap()
774
 
726
 
775
    function _readFileMap()
727
    function _readFileMap()
776
    {
728
    {
777
        if (!file_exists($this->filemap)) {
-
 
778
            return array();
729
        if (!file_exists($this->filemap)) {
779
        }
730
            return array();
-
 
731
        }
-
 
732
        $fp = @fopen($this->filemap, 'r');
780
 
733
        if (!$fp) {
781
        $fp = @fopen($this->filemap, 'r');
734
            return $this->raiseError('PEAR_Registry: could not open filemap "' . $this->filemap . '"', PEAR_REGISTRY_ERROR_FILE, null, null, $php_errormsg);
782
        if (!$fp) {
735
        }
-
 
736
        clearstatcache();
783
            return $this->raiseError('PEAR_Registry: could not open filemap "' . $this->filemap . '"', PEAR_REGISTRY_ERROR_FILE, null, null, $php_errormsg);
737
        $rt = get_magic_quotes_runtime();
784
        }
738
        set_magic_quotes_runtime(0);
785
 
739
        $fsize = filesize($this->filemap);
786
        clearstatcache();
-
 
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);
790
        $tmp = unserialize($data);
Line 743... Line -...
743
        $tmp = unserialize($data);
-
 
744
        if (!$tmp && $fsize > 7) {
-
 
745
            return $this->raiseError('PEAR_Registry: invalid filemap data', PEAR_REGISTRY_ERROR_FORMAT, null, null, $data);
-
 
746
        }
791
        if (!$tmp && $fsize > 7) {
747
        $this->filemap_cache = $tmp;
792
            return $this->raiseError('PEAR_Registry: invalid filemap data', PEAR_REGISTRY_ERROR_FORMAT, null, null, $data);
748
        return true;
793
        }
749
    }
794
 
750
 
795
        $this->filemap_cache = $tmp;
Line 763... Line 808...
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
        }
Line 788... Line 816...
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');
Line -... Line 825...
-
 
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
 
Line 808... Line -...
808
        return true;
-
 
809
    }
-
 
810
 
-
 
811
    // }}}
864
        return true;
812
    // {{{ _unlock()
865
    }
813
 
866
 
814
    function _unlock()
867
    function _unlock()
815
    {
868
    {
816
        $ret = $this->_lock(LOCK_UN);
869
        $ret = $this->_lock(LOCK_UN);
-
 
870
        if (is_resource($this->lock_fp)) {
817
        if (is_resource($this->lock_fp)) {
871
            fclose($this->lock_fp);
818
            fclose($this->lock_fp);
872
        }
819
        }
873
 
Line 820... Line -...
820
        $this->lock_fp = null;
-
 
821
        return $ret;
-
 
822
    }
-
 
823
 
874
        $this->lock_fp = null;
824
    // }}}
875
        return $ret;
825
    // {{{ _packageExists()
876
    }
826
 
877
 
Line 827... Line -...
827
    function _packageExists($package, $channel = false)
-
 
828
    {
-
 
829
        return file_exists($this->_packageFileName($package, $channel));
-
 
830
    }
878
    function _packageExists($package, $channel = false)
831
 
879
    {
-
 
880
        return file_exists($this->_packageFileName($package, $channel));
832
    // }}}
881
    }
833
    // {{{ _channelExists()
882
 
834
 
883
    /**
835
    /**
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)
-
 
891
    {
842
    {
892
        $a = file_exists($this->_channelFileName($channel, $noaliases));
843
        $a = file_exists($this->_channelFileName($channel, $noaliases));
893
        if (!$a && $channel == 'pear.php.net') {
844
        if (!$a && $channel == 'pear.php.net') {
894
            return true;
-
 
895
        }
-
 
896
 
-
 
897
        if (!$a && $channel == 'pecl.php.net') {
-
 
898
            return true;
-
 
899
        }
845
            return true;
900
 
846
        }
901
        if (!$a && $channel == 'doc.php.net') {
Line -... Line 902...
-
 
902
            return true;
-
 
903
        }
-
 
904
 
-
 
905
        return $a;
-
 
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
847
        if (!$a && $channel == 'pecl.php.net') {
915
     */
-
 
916
    function _mirrorExists($channel, $mirror)
-
 
917
    {
-
 
918
        $data = $this->_channelInfo($channel);
-
 
919
        if (!isset($data['servers']['mirror'])) {
-
 
920
            return false;
-
 
921
        }
-
 
922
 
848
            return true;
923
        foreach ($data['servers']['mirror'] as $m) {
-
 
924
            if ($m['attribs']['host'] == $mirror) {
Line 849... Line 925...
849
        }
925
                return true;
850
        return $a;
926
            }
851
    }
927
        }
852
 
928
 
Line 862... Line 938...
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
    }
Line 928... Line -...
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')) {
-
 
941
                if (!$channel->validate()) {
-
 
942
                    return false;
-
 
943
                }
-
 
944
                $channel = $channel->getName();
-
 
945
            } else {
1027
            if (!is_a($channel, 'PEAR_ChannelFile')) {
946
                return false;
1028
                return false;
-
 
1029
            }
-
 
1030
 
-
 
1031
            if (!$channel->validate()) {
-
 
1032
                return false;
-
 
1033
            }
947
            }
1034
            $channel = $channel->getName();
-
 
1035
        }
948
        }
1036
 
949
        if ($this->_getChannelFromAlias($channel) == '__uri') {
1037
        if ($this->_getChannelFromAlias($channel) == '__uri') {
950
            return false;
1038
            return false;
-
 
1039
        }
951
        }
1040
 
952
        if ($this->_getChannelFromAlias($channel) == 'pecl.php.net') {
1041
        if ($this->_getChannelFromAlias($channel) == 'pecl.php.net') {
953
            return false;
1042
            return false;
-
 
1043
        }
-
 
1044
 
-
 
1045
        if ($this->_getChannelFromAlias($channel) == 'doc.php.net') {
-
 
1046
            return false;
-
 
1047
        }
954
        }
1048
 
955
        if (!$this->_channelExists($channel)) {
1049
        if (!$this->_channelExists($channel)) {
956
            return false;
1050
            return false;
-
 
1051
        }
957
        }
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;
-
 
1055
        }
960
        }
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;
-
 
1060
        }
964
        }
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;
-
 
1065
        }
968
        }
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;
-
 
1070
        }
972
        }
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
            }
-
 
1078
        }
979
        }
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);
-
 
1084
        }
984
        }
1085
 
985
        return $ret;
1086
        return $ret;
Line 986... Line -...
986
    }
-
 
987
 
-
 
988
    // }}}
-
 
989
    // {{{ _isChannelAlias()
1087
    }
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
    {
Line 998... Line -...
998
        return file_exists($this->_getChannelAliasFileName($alias));
-
 
999
    }
-
 
1000
 
-
 
1001
    // }}}
1096
        return file_exists($this->_getChannelAliasFileName($alias));
1002
    // {{{ _packageInfo()
1097
    }
1003
 
1098
 
1004
    /**
1099
    /**
1005
     * @param string|null
1100
     * @param string|null
Line 1020... Line 1115...
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
    }
Line 1058... Line -...
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;
-
 
1167
        }
1071
        }
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
        }
-
 
1076
        $rt = get_magic_quotes_runtime();
-
 
-
 
1172
        }
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));
-
 
1081
        set_magic_quotes_runtime($rt);
1176
        $data = file_get_contents($this->_channelFileName($channel));
1082
        $data = unserialize($data);
1177
        $data = unserialize($data);
1083
        return $data;
1178
        return $data;
Line 1084... Line -...
1084
    }
-
 
1085
 
-
 
1086
    // }}}
-
 
1087
    // {{{ _listChannels()
1179
    }
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)) {
-
 
1185
            return array('pear.php.net', 'pecl.php.net', 'doc.php.net', '__uri');
1093
            return array('pear.php.net', 'pecl.php.net', '__uri');
1186
        }
1094
        }
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') {
-
 
1191
                continue;
1098
                continue;
1192
            }
1099
            }
1193
 
1100
            if ($ent == '__uri.reg') {
1194
            if ($ent == '__uri.reg') {
1101
                $channellist[] = '__uri';
1195
                $channellist[] = '__uri';
-
 
1196
                continue;
1102
                continue;
1197
            }
1103
            }
1198
 
-
 
1199
            $channellist[] = str_replace('_', '/', substr($ent, 0, -4));
1104
            $channellist[] = str_replace('_', '/', substr($ent, 0, -4));
1200
        }
1105
        }
1201
 
1106
        closedir($dp);
1202
        closedir($dp);
1107
        if (!in_array('pear.php.net', $channellist)) {
1203
        if (!in_array('pear.php.net', $channellist)) {
-
 
1204
            $channellist[] = 'pear.php.net';
1108
            $channellist[] = 'pear.php.net';
1205
        }
1109
        }
1206
 
1110
        if (!in_array('pecl.php.net', $channellist)) {
1207
        if (!in_array('pecl.php.net', $channellist)) {
-
 
1208
            $channellist[] = 'pecl.php.net';
-
 
1209
        }
-
 
1210
 
-
 
1211
        if (!in_array('doc.php.net', $channellist)) {
-
 
1212
            $channellist[] = 'doc.php.net';
-
 
1213
        }
1111
            $channellist[] = 'pecl.php.net';
1214
 
1112
        }
1215
 
1113
        if (!in_array('__uri', $channellist)) {
1216
        if (!in_array('__uri', $channellist)) {
-
 
1217
            $channellist[] = '__uri';
-
 
1218
        }
1114
            $channellist[] = '__uri';
1219
 
1115
        }
1220
        natsort($channellist);
Line 1116... Line -...
1116
        return $channellist;
-
 
1117
    }
-
 
1118
 
-
 
1119
    // }}}
1221
        return $channellist;
1120
    // {{{ _listPackages()
1222
    }
1121
 
1223
 
1122
    function _listPackages($channel = false)
1224
    function _listPackages($channel = false)
1123
    {
1225
    {
-
 
1226
        if ($channel && $this->_getChannelFromAlias($channel) != 'pear.php.net') {
1124
        if ($channel && $this->_getChannelFromAlias($channel) != 'pear.php.net') {
1227
            return $this->_listChannelPackages($channel);
1125
            return $this->_listChannelPackages($channel);
1228
        }
1126
        }
1229
 
-
 
1230
        if (!file_exists($this->statedir) || !is_dir($this->statedir)) {
1127
        if (!file_exists($this->statedir) || !is_dir($this->statedir)) {
1231
            return array();
1128
            return array();
1232
        }
1129
        }
1233
 
1130
        $pkglist = array();
1234
        $pkglist = array();
1131
        $dp = opendir($this->statedir);
1235
        $dp = opendir($this->statedir);
-
 
1236
        if (!$dp) {
1132
        if (!$dp) {
1237
            return $pkglist;
1133
            return $pkglist;
1238
        }
1134
        }
1239
 
1135
        while ($ent = readdir($dp)) {
1240
        while ($ent = readdir($dp)) {
-
 
1241
            if ($ent{0} == '.' || substr($ent, -4) != '.reg') {
1136
            if ($ent{0} == '.' || substr($ent, -4) != '.reg') {
1242
                continue;
1137
                continue;
1243
            }
1138
            }
1244
 
1139
            $pkglist[] = substr($ent, 0, -4);
1245
            $pkglist[] = substr($ent, 0, -4);
1140
        }
1246
        }
Line 1141... Line -...
1141
        closedir($dp);
-
 
1142
        return $pkglist;
-
 
1143
    }
-
 
1144
 
1247
        closedir($dp);
1145
    // }}}
1248
        return $pkglist;
1146
    // {{{ _listChannelPackages()
1249
    }
1147
 
1250
 
1148
    function _listChannelPackages($channel)
1251
    function _listChannelPackages($channel)
1149
    {
1252
    {
1150
        $pkglist = array();
1253
        $pkglist = array();
-
 
1254
        if (!file_exists($this->_channelDirectoryName($channel)) ||
1151
        if (!file_exists($this->_channelDirectoryName($channel)) ||
1255
              !is_dir($this->_channelDirectoryName($channel))) {
1152
              !is_dir($this->_channelDirectoryName($channel))) {
1256
            return array();
1153
            return array();
1257
        }
1154
        }
1258
 
-
 
1259
        $dp = opendir($this->_channelDirectoryName($channel));
1155
        $dp = opendir($this->_channelDirectoryName($channel));
1260
        if (!$dp) {
1156
        if (!$dp) {
1261
            return $pkglist;
1157
            return $pkglist;
1262
        }
1158
        }
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') {
-
 
1266
                continue;
1161
                continue;
1267
            }
1162
            }
1268
            $pkglist[] = substr($ent, 0, -4);
1163
            $pkglist[] = substr($ent, 0, -4);
1269
        }
Line 1164... Line -...
1164
        }
-
 
1165
        closedir($dp);
-
 
1166
        return $pkglist;
1270
 
1167
    }
1271
        closedir($dp);
1168
 
1272
        return $pkglist;
1169
    // }}}
1273
    }
1170
    
1274
 
1171
    function _listAllPackages()
1275
    function _listAllPackages()
-
 
1276
    {
1172
    {
1277
        $ret = array();
1173
        $ret = array();
1278
        foreach ($this->_listChannels() as $channel) {
Line 1174... Line 1279...
1174
        foreach ($this->_listChannels() as $channel) {
1279
            $ret[$channel] = $this->_listPackages($channel);
1175
            $ret[$channel] = $this->_listPackages($channel);
1280
        }
Line 1187... Line 1292...
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
    }
Line 1204... Line 1312...
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)
-
 
1319
    {
-
 
1320
        if (!is_a($info, 'PEAR_PackageFile_v1') && !is_a($info, 'PEAR_PackageFile_v2')) {
-
 
1321
            return false;
-
 
1322
        }
1211
    {
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) {
Line 1218... Line 1330...
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;
Line 1254... Line 1371...
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
    }
Line 1280... Line 1402...
1280
 
1402
 
1281
    /**
1403
    /**
Line 1286... Line 1408...
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);
Line 1311... Line 1435...
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
    }
Line 1328... Line 1455...
1328
 
1455
 
Line 1339... Line 1466...
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
    }
Line 1399... Line -...
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
Line 1433... Line 1588...
1433
        return $ret;
1588
        return $ret;
1434
    }
1589
    }
Line 1435... Line 1590...
1435
 
1590
 
Line -... Line 1591...
-
 
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;
1436
    // }}}
1608
    }
Line 1437... Line 1609...
1437
 
1609
 
1438
    // {{{ isAlias()
1610
    // {{{ isAlias()
1439
 
1611
 
Line 1637... Line 1809...
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
    }
Line 1649... Line 1823...
1649
 
1823
 
1650
    // }}}
1824
    // }}}
Line 1655... Line 1829...
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
    }
Line 1676... Line 1850...
1676
 
1850
 
1677
    // }}}
1851
    // }}}
Line 1680... Line 1854...
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;
Line 1724... Line 1895...
1724
    // }}}
1895
    // }}}
1725
    // {{{ updatePackage2()
1896
    // {{{ updatePackage2()
Line 1726... Line 1897...
1726
 
1897
 
1727
    function updatePackage2($info)
1898
    function updatePackage2($info)
-
 
1899
    {
1728
    {
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);
-
 
1903
        }
1731
        }
1904
 
1732
        if (!$info->validate(PEAR_VALIDATE_DOWNLOADING)) {
1905
        if (!$info->validate(PEAR_VALIDATE_DOWNLOADING)) {
1733
            return false;
1906
            return false;
-
 
1907
        }
1734
        }
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;
-
 
1911
        }
1737
        }
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);
-
 
1918
        }
1743
        }
1919
 
1744
        return $ret;
1920
        return $ret;
Line 1745... Line 1921...
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;
-
 
1934
        }
1758
        }
1935
        $ret = $this->_getChannel($channel, $noaliases);
1759
        $ret = &$this->_getChannel($channel, $noaliases);
1936
        $this->_unlock();
1760
        if (!$ret) {
1937
        if (!$ret) {
1761
            return PEAR::raiseError('Unknown channel: ' . $channel);
-
 
1762
        }
1938
            return PEAR::raiseError('Unknown channel: ' . $channel);
1763
        $this->_unlock();
1939
        }
Line 1764... Line 1940...
1764
        return $ret;
1940
        return $ret;
1765
    }
1941
    }
Line 2147... Line 2323...
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
    }
Line 2208... Line 2384...
2208
            $ret .= '#' . $parsed['group'];
2384
            $ret .= '#' . $parsed['group'];
2209
        }
2385
        }
2210
        return $ret;
2386
        return $ret;
2211
    }
2387
    }
2212
}
2388
}
2213
 
-
 
2214
?>
-