cvs: pear /PHP_Archive Archive.php package.php package.xml package2.xml /PHP_Archive/Archive Creator.php /PHP_Archive/tests PEAR.phar cachestat.phpt
eof.phpt filenotfound.phpt makepearphar.php.inc normalstat.phpt pearindex.php phar.log require_once.phpt seek.phpt streamstat.phpt
/PHP_Archive/tests/cachestat cachestat.phar makecachestatphar.php.inc /PHP_Archive/tests/filenotfound filenotfound.phar
/PHP_Archive/tests/longfilename longphar.phar /PHP_Archive/tests/opendir opendir.phar /PHP_Archive/tests/require_once require_once.phar
| From: | Greg Beaver | Date: | Wed, 30 Nov 2005 05:25:10 +0000 |
| Subject: | cvs: pear /PHP_Archive Archive.php package.php package.xml package2.xml /PHP_Archive/Archive Creator.php /PHP_Archive/tests PEAR.phar cachestat.phpt eof.phpt filenotfound.phpt makepearphar.php.inc normalstat.phpt pearindex.php phar.log require_once.phpt seek.phpt streamstat.phpt /PHP_Archive/tests/cachestat cachestat.phar makecachestatphar.php.inc /PHP_Archive/tests/filenotfound filenotfound.phar /PHP_Archive/tests/longfilename longphar.phar /PHP_Archive/tests/opendir opendir.phar /PHP_Archive/tests/require_once require_once.phar |
||
| Groups: | php.pear.cvs | ||
| Request: | Send a blank email to pear-cvs+get-36610@lists.php.net to get a copy of this message | ||
cellog Wed Nov 30 00:25:10 2005 EDT
Removed files:
/pear/PHP_Archive/tests cachestat.phpt
/pear/PHP_Archive/tests/cachestat cachestat.phar
makecachestatphar.php.inc
Modified files:
/pear/PHP_Archive Archive.php package.php package.xml package2.xml
/pear/PHP_Archive/Archive Creator.php
/pear/PHP_Archive/tests PEAR.phar eof.phpt filenotfound.phpt
makepearphar.php.inc normalstat.phpt
pearindex.php phar.log require_once.phpt
seek.phpt streamstat.phpt
/pear/PHP_Archive/tests/filenotfound filenotfound.phar
/pear/PHP_Archive/tests/longfilename longphar.phar
/pear/PHP_Archive/tests/opendir opendir.phar
/pear/PHP_Archive/tests/require_once require_once.phar
Log:
completely re-factor the code. Now it is tremendously efficient, smaller, and
will be easier to manage.
http://cvs.php.net/diff.php/pear/PHP_Archive/Archive.php?r1=1.19&r2=1.20&ty=u Index: pear/PHP_Archive/Archive.php diff -u pear/PHP_Archive/Archive.php:1.19 pear/PHP_Archive/Archive.php:1.20 --- pear/PHP_Archive/Archive.php:1.19 Sun Jul 24 11:42:20 2005 +++ pear/PHP_Archive/Archive.php Wed Nov 30 00:24:54 2005 @@ -13,79 +13,93 @@ * URIs to your includes. i.e. require_once 'phar://config.php' will include config.php * from the root of the PHAR file. * - * Tar/Gz code borrowed from the excellent File_Archive package by Vincent Lascaux. + * Gz code borrowed from the excellent File_Archive package by Vincent Lascaux. * * @copyright Copyright © David Shafik and Synaptic Media 2004. All rights reserved. * @author Davey Shafik <davey@synapticmedia.net> * @author Greg Beaver <cellog@php.net> * @link http://www.synapticmedia.net Synaptic Media - * @version $Id: Archive.php,v 1.19 2005/07/24 15:42:20 cellog Exp $ + * @version $Id: Archive.php,v 1.20 2005/11/30 05:24:54 cellog Exp $ * @package PHP_Archive * @category PHP */ class PHP_Archive { + private $_compressed; /** - * @var string Current phar basename (like PEAR.phar) + * @var string Real path to the .phar archive */ - protected $basename; + protected $pharName = null; /** - * @var string Archive filename - */ - protected $archiveName = null; - /** - * Current Stat info of the current file in the tar - */ - protected $currentStat = null; - /** - * Current file name in the tar + * Current file name in the phar * @var string */ protected $currentFilename = null; /** - * Length of the current tar file - * @var int - */ - protected $internalFileLength = 0; - /** - * Length of the current tar file's footer - * @var int + * Length of current file in the phar + * @var string */ - protected $footerLength = 0; + protected $internalFileLength = null; /** - * @var string Content of the file being requested + * Current file statistics (size, creation date, etc.) + * @var string */ - protected $file = null; + protected $currentStat = null; /** * @var resource|null Pointer to open .phar */ protected $fp = null; /** - * @var int length of the current archive - */ - protected $fplen = null; - /** * @var int Current Position of the pointer */ protected $position = 0; - private static $_cache; + private static $_pharMapping = array(); + private static $_manifest = array(); + private static $_fileStart = array(); + private $basename; + /** - * @param string basename of the phar to cache stat from. + * Map a full real file path to an alias used to refer to the .phar + * + * This function can only be called from the initialization of the .phar itself. + * Any attempt to call from outside the .phar or to re-alias the .phar will fail + * as a security measure. + * @param string $file full realpath() filepath, like /path/to/go-pear.phar + * @param string $alias alias used in opening a file within the phar + * like phar://go-pear.phar/file + * @param bool $compressed determines whether to attempt zlib uncompression + * on accessing internal files + * @param int $dataoffset the value of __COMPILER_HALT_OFFSET__ */ - public static function cacheStat($pharname) + public static function mapPhar($file, $alias, $compressed, $dataoffset) { - if (!isset(self::$_cache)) { - self::$_cache = array(); + if ($compressed) { + if (!function_exists('gzinflate')) { + die('Error: zlib extension is not enabled - gzinflate() function needed' . + ' for compressed .phars'); + } } - self::$_cache[$pharname] = array(); + // this ensures that this is safe + if (!in_array($file, get_included_files())) { + die('SECURITY ERROR: PHP_Archive::mapPhar can only be called from within ' . + 'the phar that initiates it'); + } + if (!is_array(self::$_pharMapping)) { + self::$_pharMapping = array(); + } + if (isset(self::$_pharMapping[$alias])) { + die('ERROR: PHP_Archive::mapPhar has already been called for alias "' . + $alias . '" cannot re-alias to "' . $file . '"'); + } + self::$_pharMapping[$alias] = array($file, $compressed, $dataoffset); } /** * @param string */ - protected function processFile($path) + public static function processFile($path) { if ($path == '.') { return ''; @@ -93,6 +107,9 @@ $std = str_replace("\\", "/", $path); while ($std != ($std = ereg_replace("[^\/:?]+/\.\./", "", $std))) ; $std = str_replace("/./", "", $std); + if (strlen($std) > 1 && $std[0] == '/') { + $std = substr($std, 1); + } if (strncmp($std, "./", 2) == 0) { return substr($std, 2); } else { @@ -104,156 +121,43 @@ * Seek in the master archive to a matching file or directory * @param string */ - protected function selectFile($path) + protected function selectFile($path, $allowdirs = true) { - $std = $this->processFile($path); - $this->_index = 0; - while (($error = $this->_nextFile()) === true) { - if (empty($std) || $std == $this->currentFilename || + $std = self::processFile($path); + if (isset(self::$_manifest[$this->basename][$path])) { + $this->_setCurrentFile($path); + return true; + } + if (!$allowdirs) { + return 'Error: "' . $path . '" is not a file in phar "' . $this->basename . '"'; + } + foreach (self::$_manifest[$this->basename] as $file => $info) { + if (empty($std) || //$std is a directory - strncmp($std.'/', $this->currentFilename, strlen($std)+1) == 0) { - if (isset($this->cachedFpos)) { - @fseek($this->fp, $this->cachedFpos); - } + strncmp($std.'/', $path, strlen($std)+1) == 0) { + $this->currentFilename = $this->internalFileLength = $this->currentStat = null; return true; } } - if (@ftell($this->fp) >= $this->fplen) { - return 'Error: "' . $path . '" not found in phar "' . $this->basename . '"'; - } - return $error; + return 'Error: "' . $path . '" not found in phar "' . $this->basename . '"'; } - /** - * Process a raw tar header and extract file name, size, and additional info - * @param string contents of the header - * @uses $footerLength sets the footer length - * @uses $internalFileLength sets the file length, if filename < 100 chars - * @uses $currentStat sets the file statistics - * @return array|string a string is returned on error - */ - private function _processHeader($rawHeader) + private function _setCurrentFile($path) { - if (strlen($rawHeader) < 512 || $rawHeader == pack("a512", "")) { - return 'Error: phar "' . $this->archiveName . '" has corrupted tar header'; - } - - $header = unpack( - "a100filename/a8mode/a8uid/a8gid/a12size/a12mtime/". - "a8checksum/a1type/a100linkname/a6magic/a2version/". - "a32uname/a32gname/a8devmajor/a8devminor/a155path", - $rawHeader); $this->currentStat = array( - 2 => octdec($header['mode']), - 4 => octdec($header['uid']), - 5 => octdec($header['gid']), - 7 => octdec($header['size']), - 9 => octdec($header['mtime']) + 2 => 0100444, // file mode, readable by all, writeable by none + 4 => 0, // uid + 5 => 0, // gid + 7 => self::$_manifest[$this->basename][$path][0], // size + 9 => self::$_manifest[$this->basename][$path][1], // creation time ); - - $this->internalFileLength = $this->currentStat[7]; - if ($this->internalFileLength % 512 == 0) { - $this->footerLength = 0; - } else { - $this->footerLength = 512 - $this->internalFileLength % 512; - } - return $header; - } - - /** - * Seek to the next file, if any, and verify its integrity - * @return boolean|array|string if a cached file is used, true is returned. False is returned - * for a directory entry, and the raw header unpacked is returned - * on seek success. On error, a string is returned - */ - private function _nextFile() - { - if (isset(self::$_cache) && - isset(self::$_cache[$this->basename]) && - isset(self::$_cache[$this->basename][$this->_index])) { - $this->currentFilename = - self::$_cache[$this->basename][$this->_index]['file']; - $this->currentStat = - self::$_cache[$this->basename][$this->_index]['stat']; - $this->internalFileLength = - self::$_cache[$this->basename][$this->_index]['length']; - $this->cachedFpos = self::$_cache[$this->basename][$this->_index]['fpos']; - $this->footerLength = - self::$_cache[$this->basename][$this->_index]['footerlen']; - $this->_index++; - return true; - } - if (isset($this->cachedFpos)) { - @fseek($this->fp, $this->cachedFpos); - } - fseek($this->fp, $this->internalFileLength + $this->footerLength, SEEK_CUR); - $rawHeader = @fread($this->fp, 512); - $header = $this->_processHeader($rawHeader); - if (is_string($header)) { - return $header; - } - if ($header['type'] == '5') { - return false; // directory entry - } - - if ($header['type'] == 'L') { - // filenames longer than 100 characters - // borrowed from Archive_Tar written by Vincent Blavet - $longFilename = ''; - $n = floor($header['size']/512); - for ($i=0; $i < $n; $i++) { - $content = @fread($this->fp, 512); - $longFilename .= $content; - } - if (($header['size'] % 512) != 0) { - $content = @fread($this->fp, 512); - $longFilename .= $content; - } - // ----- Read the next header - $newHeader = @fread($this->fp, 512); - $header = $this->_processHeader($newHeader); - if (is_string($header)) { - return $header; - } - $header['filename'] = trim($longFilename); - $rawHeader = $newHeader; - } - $this->currentFilename = $this->processFile($header['path'] . $header['filename']); - $checksum = 8 * ord(" "); - if (version_compare(phpversion(), '5.0.0', '>=')) { - $c1 = str_split(substr($rawHeader, 0, 512)); - $checkheader = array_merge(array_slice($c1, 0, 148), array_slice($c1, 156)); - if (!function_exists('_PharDoChecksum')) { - function _PharDoChecksum($a, $b) {return $a + ord($b);} - } - $checksum += array_reduce($checkheader, '_PharDoChecksum'); - } else { - for ($i = 0; $i < 148; $i++) { - $checksum += ord($rawHeader{$i}); - } - for ($i = 156; $i < 512; $i++) { - $checksum += ord($rawHeader{$i}); - } - } - - if (octdec($header['checksum']) != $checksum) { - return 'Error: phar "' . - $this->archiveName . '" Checksum error on entry "' . $this->currentFilename . '"'; - } - if (isset(self::$_cache) && - isset(self::$_cache[$this->basename])) { - self::$_cache[$this->basename][] = - array( - 'file' => $this->currentFilename, - 'stat' => $this->currentStat, - 'length' => $this->internalFileLength, - 'fpos' => @ftell($this->fp), - 'footerlen' => $this->footerLength, - ); - $this->cachedFpos = null; + $this->currentFilename = $path; + // actual file length in file includes 8-byte header + $this->internalFileLength = self::$_manifest[$this->basename][$path][3] - 8; + // seek to offset of file header within the .phar + if (is_resource(@$this->fp)) { + fseek($this->fp, self::$_fileStart[$this->basename] + self::$_manifest[$this->basename][$path][2]); } - $this->_index++; - return true; } /** @@ -266,11 +170,11 @@ { $this->fp = @fopen($this->archiveName, "rb"); $stat = fstat($this->fp); - $this->fplen = $stat['size']; if (!$this->fp) { return array('Error: cannot open phar "' . $this->archiveName . '"'); } - if (($e = $this->selectFile($path)) === true) { + if (($e = $this->selectFile($path, false)) === true) { + $temp = unpack("Vcrc32/Visize", fread($this->fp, 8)); $data = ''; $count = $this->internalFileLength; while ($count) { @@ -283,6 +187,19 @@ } } @fclose($this->fp); + if ($this->_compressed) { + $data = gzinflate($data); + } + if (!isset(self::$_manifest[$this->basename][$path]['ok'])) { + if ($temp['isize'] != $this->currentStat[7]) { + return array("Not valid internal .phar file (size error {$size} != " . + $this->currentStat[7] . ")"); + } + if ($temp['crc32'] != crc32($data)) { + return array("Not valid internal .phar file (checksum error)"); + } + self::$_manifest[$this->basename][$path]['ok'] = true; + } return $data; } else { @fclose($this->fp); @@ -303,36 +220,59 @@ */ public function initializeStream($file) { - $aname = get_included_files(); - $this->archiveName = 'phar://'; - if (strpos($file, '.phar')) { - // grab the basename of the phar we want - $test = substr($file, 0, strpos($file, '.phar') + 5); - } else { - $test = false; - } - while (count($aname)) { - $this->archiveName = array_pop($aname); - if (strpos($this->archiveName, 'phar://') === false) { - if ($test) { - if (strpos($this->archiveName, $test)) { - break; - } - } else { - break; - } - } + $info = parse_url($file); + if (!isset($info['host']) || !count(self::$_pharMapping)) { + // malformed internal file + return false; } - if ($test && $this->archiveName != 'phar://') { - $this->basename = $test; - $file = substr($file, strlen($test) + 1); - if (!$file) { - $file = '/'; // this is for opendir requests - } + if (!isset($info['path'])) { + // last opened phar is requested + $info['path'] = $info['host']; + $info['host'] = ''; + } elseif (strlen($info['path']) > 1) { + $info['path'] = substr($info['path'], 1); + } + if (isset(self::$_pharMapping[$info['host']])) { + $this->basename = $info['host']; + $this->archiveName = self::$_pharMapping[$info['host']][0]; + $this->_compressed = self::$_pharMapping[$info['host']][1]; + } else { + // no such phar has been included, or last opened phar is requested + $pharinfo = end(self::$_pharMapping); + $this->basename = key(self::$_pharMapping); + $this->archiveName = $pharinfo[0]; + $this->_compressed = $pharinfo[1]; + } + if (!isset(self::$_manifest[$this->basename])) { + $fp = fopen($this->archiveName, 'rb'); + // seek to __HALT_COMPILER_OFFSET__ + fseek($fp, self::$_pharMapping[$this->basename][2]); + $manifest_length = unpack('Vlen', fread($fp, 4)); + self::$_manifest[$this->basename] = + $this->unserializeManifest(fread($fp, $manifest_length['len'])); + self::$_fileStart[$this->basename] = ftell($fp); + fclose($fp); } + $file = $info['path']; return $file; } + + function unserializeManifest($manifest) + { + $info = unpack('V', substr($manifest, 0, 4)); + $manifest = substr($manifest, 4); + $ret = array(); + for ($i = 0; $i < $info[1]; $i++) { + $len = unpack('V', substr($manifest, 0, 4)); + $savepath = substr($manifest, 4, $len[1]); + $manifest = substr($manifest, $len[1] + 4); + $ret[$savepath] = array_values(unpack('Va/Vb/Vc/Vd', substr($manifest, 0, 16))); + $manifest = substr($manifest, 16); + } + return $ret; + } + /** * Open the requested file - PHP streams API * @@ -354,9 +294,8 @@ */ private function _streamOpen($file, $searchForDir = false) { - $path = substr($file, 7); - $path = $this->initializeStream($path); - if ($this->archiveName == 'phar://') { + $path = $this->initializeStream($file); + if (!$path) { trigger_error('Error: Unknown phar in "' . $file . '"', E_USER_ERROR); } if (is_array($this->file = $this->extractFile($path))) { @@ -372,34 +311,7 @@ return true; } } - $compressed = $this->file ? (int) $this->file{0} : false; - $this->file ? $this->file = substr($this->file, 1) : false; - if ($compressed) { - if (!function_exists('gzinflate')) { - trigger_error('Error: zlib extension is not enabled - gzinflate() function needed' . - ' for compressed .phars'); - return false; - } - $header = substr($this->file, 0, 10); - $temp = unpack("Vcrc32/Visize", substr($this->file, -8)); - - $id = @unpack("H2id1/H2id2/C1tmp/C1flags", substr($header, 0, 4)); - if ($id['id1'] != "1f" || $id['id2'] != "8b") { - trigger_error("Not valid gz file (wrong header)", E_USER_ERROR); - return false; - } - $this->file = gzinflate(substr($this->file, 10, strlen($this->file) - 8)); - if ($temp['isize'] != strlen($this->file)) { - trigger_error("Not valid gz file (size error {$size} != " . - strlen($this->file) . ")", E_USER_ERROR); - return false; - } - if ($temp['crc32'] != crc32($this->file)) { - trigger_error("Not valid gz file (checksum error)", E_USER_ERROR); - return false; - } - } if (!is_null($this->file) && $this->file !== false) { return true; } else { @@ -426,7 +338,7 @@ */ function stream_eof() { - return $this->position >= strlen($this->file); + return $this->position >= $this->currentStat[7]; } /** @@ -445,16 +357,16 @@ $this->position = $pos; break; case SEEK_CUR: - if ($pos + strlen($this->file) < 0) { + if ($pos + $this->currentStat[7] < 0) { return false; } $this->position += $pos; break; case SEEK_END: - if ($pos + strlen($this->file) < 0) { + if ($pos + $this->currentStat[7] < 0) { return false; } - $this->position = $pos + strlen($this->file); + $this->position = $pos + $this->currentStat[7]; default: return false; } @@ -471,7 +383,8 @@ } /** - * The result of an fstat call, returns mod time from tar, and file size - PHP streams API + * The result of an fstat call, returns mod time from creation, and file size - + * PHP streams API * @uses _stream_stat() * @access private */ @@ -487,8 +400,17 @@ */ public function _stream_stat($file = null) { - $std = $file ? $this->processFile($file) : $this->currentFilename; - $isdir = strncmp($std . '/', $this->currentFilename, strlen($std) + 1) == 0; + $std = $file ? self::processFile($file) : $this->currentFilename; + if ($file) { + if (isset(self::$_manifest[$this->basename][$file])) { + $this->_setCurrentFile($file); + $isdir = false; + } else { + $isdir = true; + } + } else { + $isdir = false; // open streams must be files + } $mode = $isdir ? 0040444 : 0100444; // 040000 = dir, 010000 = file // everything is readable, nothing is writeable @@ -497,7 +419,7 @@ 'dev' => 0, 'ino' => 0, 'mode' => $mode, 'nlink' => 0, 'uid' => 0, 'gid' => 0, 'rdev' => 0, 'blksize' => 0, 'blocks' => 0, - 'size' => strlen($this->file), + 'size' => $this->currentStat[7], 'atime' => $this->currentStat[9], 'mtime' => $this->currentStat[9], 'ctime' => $this->currentStat[9], @@ -512,8 +434,6 @@ */ public function url_stat($url, $flags) { - $this->_streamOpen($url, true); - $url = substr($url, 7); $path = $this->initializeStream($url); return $this->_stream_stat($path); } @@ -528,32 +448,33 @@ $info = parse_url($path); $path = !empty($info['path']) ? $info['host'] . $info['path'] : $info['host'] . '/'; - $path = $this->initializeStream($path); - if ($this->archiveName == 'phar://') { + $path = $this->initializeStream('phar://' . $path); + if (isset(self::$_manifest[$this->basename][$path])) { + trigger_error('Error: "' . $path . '" is a file, and cannot be opened with opendir', + E_USER_ERROR); + return false; + } + if ($path == false) { trigger_error('Error: Unknown phar in "' . $file . '"', E_USER_ERROR); return false; } $this->fp = @fopen($this->archiveName, "rb"); - $stat = fstat($this->fp); - $this->fplen = $stat['size']; if (!$this->fp) { - return array('Error: cannot open phar "' . $this->archiveName . '"'); + trigger_error('Error: cannot open phar "' . $this->archiveName . '"'); + return false; } $this->_dirFiles = array(); - while (($error = $this->_nextFile()) === true) { - if (strpos($this->currentFilename, '#PHP_ARCHIVE_HEADER-0.5.0.php')) { - continue; - } + foreach (self::$_manifest[$this->basename] as $file => $info) { if ($path == '/') { - if (strpos($this->currentFilename, '/')) { - $this->_dirFiles[array_shift($a = explode('/', $this->currentFilename))] = true; + if (strpos($file, '/')) { + $this->_dirFiles[array_shift($a = explode('/', $file))] = true; } else { - $this->_dirFiles[$this->currentFilename] = true; + $this->_dirFiles[$file] = true; } - } elseif (strpos($this->currentFilename, $path) === 0) { - $fname = substr($this->currentFilename, strlen($path) + 1); + } elseif (strpos($file, $path) === 0) { + $fname = substr($file, strlen($path) + 1); if (strpos($fname, '/')) { - $this->_dirFiles[array_unshift(explode('/', $fname))] = true; + $this->_dirFiles[array_unshift($a = explode('/', $fname))] = true; } else { $this->_dirFiles[$fname] = true; } http://cvs.php.net/diff.php/pear/PHP_Archive/package.php?r1=1.13&r2=1.14&ty=u Index: pear/PHP_Archive/package.php diff -u pear/PHP_Archive/package.php:1.13 pear/PHP_Archive/package.php:1.14 --- pear/PHP_Archive/package.php:1.13 Mon Sep 5 16:02:51 2005 +++ pear/PHP_Archive/package.php Wed Nov 30 00:24:55 2005 @@ -2,20 +2,21 @@ require_once 'PEAR/PackageFileManager.php'; require_once 'PEAR/PackageFileManager2.php'; PEAR::setErrorHAndling(PEAR_ERROR_DIE); -$version = '0.6.1'; -$apiversion = '0.6'; +$version = '0.7.0'; +$apiversion = '0.7'; $notes = <<<EOT -Bugfix release - * fix faulty dependency on unreleased Archive_Tar - * fix version_compare()'s bungling of versioning ending with -dev +major refactoring - .tar file format is no longer used +DRAMATIC improvement in efficiency of disk use, memory usage, +and processing speed. EOT; $package = PEAR_PackageFileManager2::importFromPackageFile1(dirname(__FILE__) . DIRECTORY_SEPARATOR . 'package.xml', $options = array( 'ignore' => array('package.php', 'package.xml', 'package2.xml', '*.bak', '*src*', - '*.tgz', '*pear_media*', 'index.htm', 'PEAR.phar', 'docs/', 'phar_unpack.php', 'info.phar'), - 'filelistgenerator' => 'cvs', // other option is 'file' + '*.tgz', '*pear_media*', 'index.htm', 'PEAR.phar', 'docs/', 'phar_unpack.php', 'info.phar', + '*CVS*'), + 'filelistgenerator' => 'file', // other option is 'file' 'changelogoldtonew' => false, 'baseinstalldir' => 'PHP', 'packagedirectory' => dirname(__FILE__), @@ -28,14 +29,17 @@ $package->setAPIStability('alpha'); $package->setNotes($notes); $package->clearDeps(); -$package->addPackageDepWithChannel('required', 'Archive_Tar', 'pear.php.net', '1.3.1'); -$package->addPackageDepWithChannel('required', 'PEAR', 'pear.php.net', '1.3.5'); +$package->addPackageDepWithChannel('required', 'PEAR', 'pear.php.net', '1.4.3'); $package->setPhpDep('5.1.0b1'); -$package->setPearinstallerDep('1.4.0b1'); -$package->generateContents(); +$package->setPearinstallerDep('1.4.3'); $package->addReplacement('Archive.php', 'package-info', '@API-VER@', 'api-version'); $package->addReplacement('Archive/Creator.php', 'package-info', '@API-VER@', 'api-version'); +$package->generateContents(); + +$package->setPackageType('php'); +$package->addRelease(); + $pf1 = $package->exportCompatiblePackageFile1($options); if (isset($_SERVER['argv'][1]) && $_SERVER['argv'][1] == 'commit') { $package->writePackageFile(); http://cvs.php.net/diff.php/pear/PHP_Archive/package.xml?r1=1.13&r2=1.14&ty=u Index: pear/PHP_Archive/package.xml diff -u pear/PHP_Archive/package.xml:1.13 pear/PHP_Archive/package.xml:1.14 --- pear/PHP_Archive/package.xml:1.13 Mon Sep 5 16:02:51 2005 +++ pear/PHP_Archive/package.xml Wed Nov 30 00:24:55 2005 @@ -1,6 +1,6 @@ -<?xml version="1.0" encoding="ISO-8859-1" ?> +<?xml version="1.0" encoding="UTF-8" ?> <!DOCTYPE package SYSTEM "http://pear.php.net/dtd/package-1.0"> -<package version="1.0" packagerversion="1.4.0b1"> +<package version="1.0" packagerversion="1.4.5"> <name>PHP_Archive</name> <summary>Create and Use PHP Archive files</summary> <description>PHP_Archive allows you to create a single .phar file containing an entire application. @@ -20,18 +20,17 @@ </maintainer> </maintainers> <release> - <version>0.6.1</version> - <date>2005-09-05</date> + <version>0.7.0</version> + <date>2005-11-25</date> <license>PHP License</license> <state>alpha</state> - <notes>Bugfix release - * fix faulty dependency on unreleased Archive_Tar - * fix version_compare()'s bungling of versioning ending with -dev + <notes>major refactoring - .tar file format is no longer used +DRAMATIC improvement in efficiency of disk use, memory usage, +and processing speed. </notes> <deps> <dep type="php" rel="ge" version="5.1.0b1" optional="no"/> - <dep type="pkg" rel="ge" version="1.3.1" optional="no">Archive_Tar</dep> - <dep type="pkg" rel="ge" version="1.3.5" optional="no">PEAR</dep> + <dep type="pkg" rel="ge" version="1.4.3" optional="no">PEAR</dep> </deps> <filelist> <dir name="/" baseinstalldir="PHP"> @@ -39,6 +38,9 @@ <file role="php" name="Creator.php"> <replace from="@API-VER@" to="api-version" type="package-info"/> </file> + <file role="php" name="Creator2.php"> + <replace from="@API-VER@" to="api-version" type="package-info"/> + </file> </dir> <!-- /Archive --> <dir name="tests"> <dir name="cachestat"> @@ -93,18 +95,31 @@ <file role="php" name="Archive.php"> <replace from="@API-VER@" to="api-version" type="package-info"/> </file> + <file role="php" name="Archive2.php"> + <replace from="@API-VER@" to="api-version" type="package-info"/> + </file> </dir> <!-- / --> </filelist> </release> <changelog> <release> + <version>0.7.0</version> + <date>2005-11-25</date> + <license>PHP License</license> + <state>alpha</state> + <notes>major refactoring - .tar file format is no longer used +DRAMATIC improvement in efficiency of disk use, memory usage, +and processing speed. + </notes> + </release> + <release> <version>0.6.1</version> <date>2005-09-05</date> <license>PHP License</license> <state>alpha</state> <notes>Bugfix release * fix faulty dependency on unreleased Archive_Tar - * fix version_compare()'s bungling of versioning ending with -dev + * fix version_compare()'s bungling of versioning ending with -dev </notes> </release> <release> http://cvs.php.net/diff.php/pear/PHP_Archive/package2.xml?r1=1.5&r2=1.6&ty=u Index: pear/PHP_Archive/package2.xml diff -u pear/PHP_Archive/package2.xml:1.5 pear/PHP_Archive/package2.xml:1.6 --- pear/PHP_Archive/package2.xml:1.5 Mon Sep 5 16:02:51 2005 +++ pear/PHP_Archive/package2.xml Wed Nov 30 00:24:55 2005 @@ -1,5 +1,5 @@ -<?xml version="1.0"?> -<package packagerversion="1.4.0b1" version="2.0" xmlns="http://pear.php.net/dtd/package-2.0" xmlns:tasks="http://pear.php.net/dtd/tasks-1.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://pear.php.net/dtd/tasks-1.0 +<?xml version="1.0" encoding="UTF-8"?> +<package packagerversion="1.4.5" version="2.0" xmlns="http://pear.php.net/dtd/package-2.0" xmlns:tasks="http://pear.php.net/dtd/tasks-1.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://pear.php.net/dtd/tasks-1.0 http://pear.php.net/dtd/tasks-1.0.xsd http://pear.php.net/dtd/package-2.0 http://pear.php.net/dtd/package-2.0.xsd"> @@ -21,76 +21,86 @@ <email>cellog@php.net</email> <active>yes</active> </lead> - <date>2005-09-05</date> - <time>15:02:17</time> + <date>2005-11-25</date> + <time>02:05:03</time> <version> - <release>0.6.1</release> - <api>0.6</api> + <release>0.7.0</release> + <api>0.7</api> </version> <stability> <release>alpha</release> <api>alpha</api> </stability> <license uri="http://www.php.net/license">PHP License</license> - <notes>Bugfix release - * fix faulty dependency on unreleased Archive_Tar - * fix version_compare()'s bungling of versioning ending with -dev</notes> + <notes>major refactoring - .tar file format is no longer used +DRAMATIC improvement in efficiency of disk use, memory usage, +and processing speed.</notes> <contents> <dir baseinstalldir="PHP" name="/"> <dir name="Archive"> - <file name="Creator.php" role="php" /> + <file baseinstalldir="PHP" name="Creator.php" role="php"> + <tasks:replace from="@API-VER@" to="api-version" type="package-info" /> + </file> + <file baseinstalldir="PHP" name="Creator2.php" role="php"> + <tasks:replace from="@API-VER@" to="api-version" type="package-info" /> + </file> </dir> <!-- /Archive --> <dir name="tests"> <dir name="cachestat"> - <file name="cachestat.phar" role="test" /> - <file name="makecachestatphar.php.inc" role="test" /> + <file baseinstalldir="PHP" name="cachestat.phar" role="test" /> + <file baseinstalldir="PHP" name="makecachestatphar.php.inc" role="test" /> </dir> <!-- /tests/cachestat --> <dir name="filenotfound"> - <file name="filenotfound.phar" role="test" /> - <file name="makefilenotfoundphar.php.inc" role="test" /> + <file baseinstalldir="PHP" name="filenotfound.phar" role="test" /> + <file baseinstalldir="PHP" name="makefilenotfoundphar.php.inc" role="test" /> </dir> <!-- /tests/filenotfound --> <dir name="longfilename"> - <file name="longphar.phar" role="test" /> - <file name="makelongphar.php.inc" role="test" /> + <file baseinstalldir="PHP" name="longphar.phar" role="test" /> + <file baseinstalldir="PHP" name="makelongphar.php.inc" role="test" /> </dir> <!-- /tests/longfilename --> <dir name="opendir"> - <file name="makeopendirphar.php.inc" role="test" /> - <file name="opendir.phar" role="test" /> + <file baseinstalldir="PHP" name="makeopendirphar.php.inc" role="test" /> + <file baseinstalldir="PHP" name="opendir.phar" role="test" /> </dir> <!-- /tests/opendir --> <dir name="planet_php"> - <file name="default_phar.php" role="test" /> + <file baseinstalldir="PHP" name="default_phar.php" role="test" /> </dir> <!-- /tests/planet_php --> <dir name="require_once"> - <file name="makerequire_oncephar.php.inc" role="test" /> - <file name="require_once.phar" role="test" /> + <file baseinstalldir="PHP" name="makerequire_oncephar.php.inc" role="test" /> + <file baseinstalldir="PHP" name="require_once.phar" role="test" /> </dir> <!-- /tests/require_once --> - <file name="cachestat.phpt" role="test" /> - <file name="cachestattest.php" role="test" /> - <file name="eof.phpt" role="test" /> - <file name="filenotfound.phpt" role="test" /> - <file name="filenotfoundtest.php" role="test" /> - <file name="gopearphar.php.inc" role="test" /> - <file name="longfilename.phpt" role="test" /> - <file name="makepearphar.php.inc" role="test" /> - <file name="new_phar.phar" role="test" /> - <file name="normalstat.phpt" role="test" /> - <file name="opendir.phpt" role="test" /> - <file name="pearindex.php" role="test" /> - <file name="phar.log" role="test" /> - <file name="phpt_test.php.inc" role="test" /> - <file name="require_once.phpt" role="test" /> - <file name="savetest.php" role="test" /> - <file name="seek.phpt" role="test" /> - <file name="streamstat.phpt" role="test" /> - <file name="test.php" role="test" /> - <file name="test1.php" role="test" /> - <file name="test_path.php" role="test" /> - <file name="test_phar.phar" role="test" /> - <file name="test_phar2.phar" role="test" /> - <file name="test_require.php" role="test" /> - <file name="test_tar.tar" role="test" /> + <file baseinstalldir="PHP" name="cachestat.phpt" role="test" /> + <file baseinstalldir="PHP" name="cachestattest.php" role="test" /> + <file baseinstalldir="PHP" name="eof.phpt" role="test" /> + <file baseinstalldir="PHP" name="filenotfound.phpt" role="test" /> + <file baseinstalldir="PHP" name="filenotfoundtest.php" role="test" /> + <file baseinstalldir="PHP" name="gopearphar.php.inc" role="test" /> + <file baseinstalldir="PHP" name="longfilename.phpt" role="test" /> + <file baseinstalldir="PHP" name="makepearphar.php.inc" role="test" /> + <file baseinstalldir="PHP" name="new_phar.phar" role="test" /> + <file baseinstalldir="PHP" name="normalstat.phpt" role="test" /> + <file baseinstalldir="PHP" name="opendir.phpt" role="test" /> + <file baseinstalldir="PHP" name="pearindex.php" role="test" /> + <file baseinstalldir="PHP" name="phar.log" role="test" /> + <file baseinstalldir="PHP" name="phpt_test.php.inc" role="test" /> + <file baseinstalldir="PHP" name="require_once.phpt" role="test" /> + <file baseinstalldir="PHP" name="savetest.php" role="test" /> + <file baseinstalldir="PHP" name="seek.phpt" role="test" /> + <file baseinstalldir="PHP" name="streamstat.phpt" role="test" /> + <file baseinstalldir="PHP" name="test.php" role="test" /> + <file baseinstalldir="PHP" name="test1.php" role="test" /> + <file baseinstalldir="PHP" name="test_path.php" role="test" /> + <file baseinstalldir="PHP" name="test_phar.phar" role="test" /> + <file baseinstalldir="PHP" name="test_phar2.phar" role="test" /> + <file baseinstalldir="PHP" name="test_require.php" role="test" /> + <file baseinstalldir="PHP" name="test_tar.tar" role="test" /> </dir> <!-- /tests --> - <file name="Archive.php" role="php" /> + <file baseinstalldir="PHP" name="Archive.php" role="php"> + <tasks:replace from="@API-VER@" to="api-version" type="package-info" /> + </file> + <file baseinstalldir="PHP" name="Archive2.php" role="php"> + <tasks:replace from="@API-VER@" to="api-version" type="package-info" /> + </file> </dir> <!-- / --> </contents> <dependencies> @@ -99,24 +109,58 @@ <min>5.1.0b1</min> </php> <pearinstaller> - <min>1.4.0b1</min> + <min>1.4.3</min> </pearinstaller> <package> - <name>Archive_Tar</name> - <channel>pear.php.net</channel> - <min>1.3.1</min> - </package> - <package> <name>PEAR</name> <channel>pear.php.net</channel> - <min>1.3.5</min> + <min>1.4.3</min> </package> </required> </dependencies> - <phprelease /> + <phprelease> + <filelist> + <install as="Archive.php" name="Archive2.php" /> + <install as="Archive/Creator.php" name="Archive/Creator2.php" /> + <ignore name="Archive.php" /> + <ignore name="Archive/Creator.php" /> + </filelist> + </phprelease> <changelog> <release> <version> + <release>0.7.0</release> + <api>0.7</api> + </version> + <stability> + <release>alpha</release> + <api>alpha</api> + </stability> + <date>2005-11-25</date> + <license>PHP License</license> + <notes>major refactoring - .tar file format is no longer used +DRAMATIC improvement in efficiency of disk use, memory usage, +and processing speed.</notes> + </release> + <release> + <version> + <release>0.6.1</release> + <api>0.6.1</api> + </version> + <stability> + <release>alpha</release> + <api>alpha</api> + </stability> + <date>2005-09-05</date> + <license uri="http://www.php.net/license">PHP License</license> + <notes>Bugfix release + * fix faulty dependency on unreleased Archive_Tar + * fix version_compare()'s bungling of versioning ending with -dev + + </notes> + </release> + <release> + <version> <release>0.6.0</release> <api>0.6.0</api> </version> @@ -220,20 +264,5 @@ </notes> </release> - <release> - <version> - <release>0.6.1</release> - <api>0.6</api> - </version> - <stability> - <release>alpha</release> - <api>alpha</api> - </stability> - <date>2005-09-05</date> - <license>PHP License</license> - <notes>Bugfix release - * fix faulty dependency on unreleased Archive_Tar - * fix version_compare()'s bungling of versioning ending with -dev</notes> - </release> </changelog> </package> http://cvs.php.net/diff.php/pear/PHP_Archive/Archive/Creator.php?r1=1.17&r2=1.18&ty=u Index: pear/PHP_Archive/Archive/Creator.php diff -u pear/PHP_Archive/Archive/Creator.php:1.17 pear/PHP_Archive/Archive/Creator.php:1.18 --- pear/PHP_Archive/Archive/Creator.php:1.17 Mon Sep 5 15:58:32 2005 +++ pear/PHP_Archive/Archive/Creator.php Wed Nov 30 00:24:59 2005 @@ -1,84 +1,48 @@ <?php -/** - * PHP_Archive Creator Class - * - * @package PHP_Archive - * @category PHP - */ - -/** - * Require PHP_Archive - */ - -require_once 'PHP/Archive.php'; - -/** - * Require System, for temporary dir functions - */ require_once 'System.php'; - -/** - * Require Archive_Tar - */ - -require_once 'Archive/Tar.php'; - -/** - * PHP_Archive Creator Class - * - * This class allows you to easily, programatically create PHP Archives (PHAR files) - * - * @copyright Copyright © David Shafik and Synaptic Media 2004. All rights reserved. - * @author Davey Shafik <davey@synapticmedia.net> - * @link http://www.synapticmedia.net Synaptic Media - * @version $Id: Creator.php,v 1.17 2005/09/05 19:58:32 cellog Exp $ - * @package PHP_Archive - * @category PHP - * @example c:\web\php-cvs\pear\PHP_Archive\docs\examples\PHP_Archive_Creator_Example_1.php Example PHP_Archive_Creator usage - * @todo Implement PHP_Archive_Creator::addDir(); - */ - -class PHP_Archive_Creator { - +require_once 'PHP/Archive.php'; +class PHP_Archive_Creator +{ /** * @var string The Archive Filename */ - protected $archive_name; - - /** - * @var object An instance of Archive_Tar - */ - - protected $tar; - + /** * @var string The temporary path to the TAR archive */ - protected $temp_path; - + /** * @var string Where the TAR archive will be saved */ - protected $save_path; + + /** + * @var string The phar alias + */ + protected $alias; /** * @var boolean Whether or not the archive should be compressed */ - protected $compress = false; - + /** * @var boolean Whether or not a file has been added to the archive */ - protected $modified = false; - + + /** + * Used to construct the internal manifest, or listing of files/directories + * + * @var array + */ + protected $manifest = array(); + /** * PHP_Archive Constructor - * + * * @param string $init_file Init file (file called by default upon PHAR execution) * @param boolean $compress Whether to compress the files or not (will cause slowdown!) * @param mixed $allow_direct_access The file extension to prepend to requests for files @@ -87,31 +51,26 @@ * any file but the init file (you should handle other * pages in your init file code). If you set it to True, * then the exact PATH_INFO is used - * @return void + * @param string $alias alias name like "go-pear.phar" to be used for opening + * files from this phar */ public function __construct($init_file = 'index.php', $compress = false, - $allow_direct_access = false) + $allow_direct_access = false, $alias = null) { $this->compress = $compress; - $this->temp_path = System::mktemp('phr'); - $tar = new Archive_Tar($this->temp_path); + $this->temp_path = System::mktemp(array('-d', 'phr')); $contents = trim(str_replace(array('<?php', '?>'), array('', ''), file_get_contents(dirname(dirname(__FILE__)) . DIRECTORY_SEPARATOR . 'Archive.php'))); // make sure .phars added to CVS don't get checksum errors because of CVS tags $contents = str_replace('* @version $Id', '* @version Id', $contents); $unpack_code = <<<PHP - - - - - - - - - +<?php #PHP_ARCHIVE_HEADER-@API-VER@ error_reporting(E_ALL); if (version_compare(str_replace('-dev', '', phpversion()), '5.1.0b1', '<')) { -die('Error: .phar files require PHP 5.1 or newer'); +die('Error: .phar files require PHP 5.1.0b1 or newer'); +} +if (function_exists('mb_internal_encoding')) { + mb_internal_encoding('ASCII'); } if (!class_exists('PHP_Archive')) { $contents @@ -126,6 +85,11 @@ } PHP; + $this->alias = $alias; + $alias = $this->alias ? $this->alias : '@ALIAS@'; + $unpack_code .= 'PHP_Archive::mapPhar(__FILE__, "' . addslashes($alias) . '", ' . + ($compress ? 'true' : 'false') . ", __COMPILER_HALT_OFFSET__ + strlen(' ?> +'));"; if (!$allow_direct_access) { $unpack_code .= <<<PHP @@ -154,11 +118,7 @@ <?php __HALT_COMPILER(); ?> PHP; - $tar->addString('<?php #PHP_ARCHIVE_HEADER-0.5.0.php', $unpack_code); - - $this->code = $unpack_code; - - $this->tar = $tar; + file_put_contents($this->temp_path . DIRECTORY_SEPARATOR . 'loader.php', $unpack_code); } /** @@ -184,22 +144,35 @@ public function addString($file_contents, $save_path, $magicrequire = false) { + $save_path = PHP_Archive::processFile($save_path); if ($magicrequire) { $file_contents = str_replace("require_once '", "require_once 'phar://$magicrequire/", $file_contents); $file_contents = str_replace("include_once '", "include_once 'phar://$magicrequire/", $file_contents); } - if ($this->compress) { - $file_contents = '1' . - pack("C1C1C1C1VC1C1", 0x1f, 0x8b, 8, 0, time(), 2, 0xFF) . - gzdeflate($file_contents, 9) . - pack("VV",crc32($file_contents),strlen($file_contents)); - } else { - $file_contents = '0' . $file_contents; + if (!file_exists($this->temp_path . DIRECTORY_SEPARATOR . 'contents')) { + mkdir($this->temp_path . DIRECTORY_SEPARATOR . 'contents'); } - clearstatcache(); // a newly created archive could be erased if this is not performed - return $this->tar->addString($save_path, $file_contents); + $size = strlen($file_contents); + // always use gz header/footer to help ensure validity of file + $file_contents = + pack("VV",crc32($file_contents),strlen($file_contents)) . + ($this->compress ? gzdeflate($file_contents, 9) : $file_contents); + System::mkdir(array('-p', dirname($this->temp_path . DIRECTORY_SEPARATOR . 'contents' . + DIRECTORY_SEPARATOR . $save_path))); + if (file_exists($this->temp_path . DIRECTORY_SEPARATOR . 'contents' . + DIRECTORY_SEPARATOR . $save_path)) { + die('ERROR: path "' . $save_path . '" already exists'); + } + file_put_contents($this->temp_path . DIRECTORY_SEPARATOR . 'contents' . + DIRECTORY_SEPARATOR . $save_path, $file_contents); + $this->manifest[$save_path] = + array( + 'tempfile' => $this->temp_path . DIRECTORY_SEPARATOR . 'contents' . + DIRECTORY_SEPARATOR . $save_path, + 'originalsize' => $size, + 'actualsize' => strlen($file_contents)); } /** @@ -406,15 +379,16 @@ $list = $this->dirList($dir); return $this->addArray($list, $magicrequire); } - + /** - * Add an array of files to the archive + * add an array of files to the archive * - * @param array $files This is an associative array of the format - * 'file_to_archive' => 'save_path_in_archive' - * @return boolean + * @param unknown_type $files + * @param bool $magicrequire determines whether to attempt to replace all + * calls to require or include with internal + * phar includes + * @return unknown */ - public function addArray($files, $magicrequire = false) { if (!is_array($files) || empty($files)) { @@ -425,19 +399,77 @@ } return !in_array(false, $returns); } - + /** - * Save the PHAR Archive + * Construct the .phar and save it * - * @param string $file_path The file path of where to save the file - * @return void + * @param string $file_path + * @return bool success of operation */ - - public function savePhar($file_path = null) + public function savePhar($file_path) { - @unlink($file_path); - copy($this->temp_path, $file_path); + uksort($this->manifest, 'strnatcasecmp'); + $newfile = fopen($file_path, 'wb'); + if (!$newfile) { + return false; + } + $loader = fopen($this->temp_path . DIRECTORY_SEPARATOR . 'loader.php', 'rb'); + if (isset($this->alias)) { + stream_copy_to_stream($loader, $newfile); + fclose($loader); + } else { + fclose($loader); + $loader = file_get_contents($this->temp_path . DIRECTORY_SEPARATOR . 'loader.php'); + $loader = str_replace('@ALIAS@', addslashes(basename($file_path)), $loader); + fwrite($newfile, $loader); + } + // relative offset from end of manifest + $offset = 0; + $manifest = array(); + // create the manifest + foreach ($this->manifest as $savepath => $info) { + $size = $info['originalsize']; + $manifest[$savepath] = array( + $size, // original size = 0 + time(), // save time = 1 + $offset, // offset from start of files = 2 + $info['actualsize']); // actual size in the .phar = 3 + $offset += $info['actualsize']; + } + $manifest = $this->serializeManifest($manifest); + fwrite($newfile, $manifest); + // save each file + foreach ($this->manifest as $savepath => $info) { + $file = fopen($info['tempfile'], 'rb'); + stream_copy_to_stream($file, $newfile); + fclose($file); + } + fclose($newfile); + return true; + } + + /** + * serialize the manifest in a C-friendly way + * + * @param array $manifest An array like so: + * <code> + * $manifest[] = array( + * $savepath, + * $size, // original size = 0 + * time(), // save time = 1 + * $offset, // offset from start of files = 2 + * $info['actualsize']); // actual size in the .phar = 3 + * </code> + */ + function serializeManifest($manifest) + { + $ret = ''; + foreach ($manifest as $savepath => $info) { + $ret .= pack('V', strlen($savepath)) . $savepath . call_user_func_array('pack', + array_merge(array('VVVV'), $info)); + } + // save the size of the manifest + return pack('VV', strlen($ret) + 4, count($manifest)) . $ret; } - } ?> \ No newline at end of file http://cvs.php.net/diff.php/pear/PHP_Archive/tests/PEAR.phar?r1=1.6&r2=1.7&ty=u Index: pear/PHP_Archive/tests/PEAR.phar http://cvs.php.net/diff.php/pear/PHP_Archive/tests/eof.phpt?r1=1.2&r2=1.3&ty=u Index: pear/PHP_Archive/tests/eof.phpt diff -u pear/PHP_Archive/tests/eof.phpt:1.2 pear/PHP_Archive/tests/eof.phpt:1.3 --- pear/PHP_Archive/tests/eof.phpt:1.2 Sat Jul 23 14:00:55 2005 +++ pear/PHP_Archive/tests/eof.phpt Wed Nov 30 00:25:06 2005 @@ -2,7 +2,7 @@ Test seeking a .phar stream --SKIPIF-- <?php -if (version_compare(phpversion(), '5.0.0', '<')) { +if (version_compare(phpversion(), '5.1.0b1', '<')) { echo 'skip php5-only test'; } ?> @@ -10,10 +10,10 @@ <?php require_once dirname(__FILE__) . DIRECTORY_SEPARATOR . 'phpt_test.php.inc'; require_once 'PHP/Archive.php'; -require dirname(__FILE__) . DIRECTORY_SEPARATOR . 'cachestat' . DIRECTORY_SEPARATOR . - 'cachestat.phar'; +require dirname(__FILE__) . DIRECTORY_SEPARATOR . 'longfilename' . DIRECTORY_SEPARATOR . + 'longphar.phar'; $phpunit = new PEAR_PHPTest(true); -$fp = fopen('phar://cachestat.phar/test1.php', 'r'); +$fp = fopen('phar://longphar.phar/testtesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttest.php', 'r'); var_dump(feof($fp), ftell($fp)); fseek($fp, 10000); var_dump(feof($fp), ftell($fp)); @@ -21,7 +21,7 @@ echo 'tests done'; ?> --EXPECT-- -phar://cachestat.phar/test1.phpstring(5) "hello" +phar://longphar.phar/testtesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttest.phpstring(5) "hello" bool(false) int(0) bool(true) http://cvs.php.net/diff.php/pear/PHP_Archive/tests/filenotfound.phpt?r1=1.1&r2=1.2&ty=u Index: pear/PHP_Archive/tests/filenotfound.phpt diff -u pear/PHP_Archive/tests/filenotfound.phpt:1.1 pear/PHP_Archive/tests/filenotfound.phpt:1.2 --- pear/PHP_Archive/tests/filenotfound.phpt:1.1 Wed Apr 13 23:19:44 2005 +++ pear/PHP_Archive/tests/filenotfound.phpt Wed Nov 30 00:25:06 2005 @@ -17,5 +17,5 @@ echo 'tests done'; ?> --EXPECT-- -Error: "test2.php" not found in phar "cachestat.phar" +Error: "test2.php" is not a file in phar "filenotfound.phar" tests done \ No newline at end of file http://cvs.php.net/diff.php/pear/PHP_Archive/tests/makepearphar.php.inc?r1=1.7&r2=1.8&ty=u Index: pear/PHP_Archive/tests/makepearphar.php.inc diff -u pear/PHP_Archive/tests/makepearphar.php.inc:1.7 pear/PHP_Archive/tests/makepearphar.php.inc:1.8 --- pear/PHP_Archive/tests/makepearphar.php.inc:1.7 Tue May 3 14:37:27 2005 +++ pear/PHP_Archive/tests/makepearphar.php.inc Wed Nov 30 00:25:06 2005 @@ -1,6 +1,5 @@ <?php -$peardir = 'C:\devel\pear_with_channels'; -$xmlrpcdir = 'C:\php5\pear\XML'; +$peardir = 'C:\development\pear-core'; require_once 'PEAR/PackageFile.php'; require_once 'PEAR/Config.php'; @@ -15,6 +14,20 @@ $commandcontents = str_replace('@PEARVER@', $pearver, $commandcontents); $creator->addString($commandcontents, 'index.php'); +$commandcontents = file_get_contents($peardir . DIRECTORY_SEPARATOR . 'OS' . + DIRECTORY_SEPARATOR . 'Guess.php'); +$commandcontents = str_replace( + array( + "include_once \"", + "@package_version@", + ), + array( + "include_once \"phar://go-pear.phar/", + $pearver, + ), + $commandcontents); +$creator->addString($commandcontents, 'OS/Guess.php'); + $commandcontents = file_get_contents($peardir . DIRECTORY_SEPARATOR . 'PEAR' . DIRECTORY_SEPARATOR . 'Command.php'); $commandcontents = str_replace( @@ -35,11 +48,13 @@ array( "require_once '", "include_once '", + 'if (file_exists($path . "/PEAR/Task/$task.php")) {', "include_once \"PEAR/Task/\$task.php", ), array( "require_once 'phar://PEAR.phar/", "include_once 'phar://PEAR.phar/", + 'if (true) {', // we're self-contained, so this should work "include_once \"phar://PEAR.phar/PEAR/Task/\$task.php", ), $commandcontents); @@ -60,23 +75,24 @@ $creator->addString($commandcontents, 'PEAR/Frontend.php'); $commandcontents = file_get_contents($peardir . DIRECTORY_SEPARATOR . 'PEAR' . - DIRECTORY_SEPARATOR . 'Command' . DIRECTORY_SEPARATOR . 'Package.php'); + DIRECTORY_SEPARATOR . 'Downloader' . DIRECTORY_SEPARATOR . 'Package.php'); $commandcontents = str_replace( array( "require_once '", "include_once '", - "@DATA-DIR@", + "@PEAR-VER@", ), array( "require_once 'phar://PEAR.phar/", "include_once 'phar://PEAR.phar/", - "phar://PEAR.phar", + $pearver, ), $commandcontents); -$creator->addString($commandcontents, 'PEAR/Command/Package.php'); +$creator->addString($commandcontents, 'PEAR/Downloader/Package.php'); $commandcontents = file_get_contents($peardir . DIRECTORY_SEPARATOR . 'PEAR' . - DIRECTORY_SEPARATOR . 'Downloader' . DIRECTORY_SEPARATOR . 'Package.php'); + DIRECTORY_SEPARATOR . 'PackageFile' . DIRECTORY_SEPARATOR . 'v2' . + DIRECTORY_SEPARATOR . 'Validator.php'); $commandcontents = str_replace( array( "require_once '", @@ -89,16 +105,16 @@ $pearver, ), $commandcontents); -$creator->addString($commandcontents, 'PEAR/Downloader/Package.php'); +$creator->addString($commandcontents, 'PEAR/PackageFile/v2/Validator.php'); $commandcontents = file_get_contents($peardir . DIRECTORY_SEPARATOR . 'PEAR' . - DIRECTORY_SEPARATOR . 'PackageFile' . DIRECTORY_SEPARATOR . 'Generator' . - DIRECTORY_SEPARATOR . 'v1.php'); + DIRECTORY_SEPARATOR . 'PackageFile' . DIRECTORY_SEPARATOR . 'v2' . + DIRECTORY_SEPARATOR . 'rw.php'); $commandcontents = str_replace( array( "require_once '", "include_once '", - "@PEAR-VER@", + "@package_version@", ), array( "require_once 'phar://PEAR.phar/", @@ -106,11 +122,11 @@ $pearver, ), $commandcontents); -$creator->addString($commandcontents, 'PEAR/PackageFile/Generator/v1.php'); +$creator->addString($commandcontents, 'PEAR/PackageFile/v2/rw.php'); $commandcontents = file_get_contents($peardir . DIRECTORY_SEPARATOR . 'PEAR' . DIRECTORY_SEPARATOR . 'PackageFile' . DIRECTORY_SEPARATOR . 'Generator' . - DIRECTORY_SEPARATOR . 'v2.php'); + DIRECTORY_SEPARATOR . 'v1.php'); $commandcontents = str_replace( array( "require_once '", @@ -123,10 +139,11 @@ $pearver, ), $commandcontents); -$creator->addString($commandcontents, 'PEAR/PackageFile/Generator/v2.php'); +$creator->addString($commandcontents, 'PEAR/PackageFile/Generator/v1.php'); $commandcontents = file_get_contents($peardir . DIRECTORY_SEPARATOR . 'PEAR' . - DIRECTORY_SEPARATOR . 'Builder.php'); + DIRECTORY_SEPARATOR . 'PackageFile' . DIRECTORY_SEPARATOR . 'Generator' . + DIRECTORY_SEPARATOR . 'v2.php'); $commandcontents = str_replace( array( "require_once '", @@ -139,7 +156,7 @@ $pearver, ), $commandcontents); -$creator->addString($commandcontents, 'PEAR/Builder.php'); +$creator->addString($commandcontents, 'PEAR/PackageFile/Generator/v2.php'); $commandcontents = file_get_contents($peardir . DIRECTORY_SEPARATOR . 'PEAR' . DIRECTORY_SEPARATOR . 'Dependency2.php'); @@ -157,6 +174,20 @@ $commandcontents); $creator->addString($commandcontents, 'PEAR/Dependency2.php'); +$commandcontents = file_get_contents($peardir . DIRECTORY_SEPARATOR . 'OS' . + DIRECTORY_SEPARATOR . 'Guess.php'); +$commandcontents = str_replace( + array( + "include_once \"", + "@package_version@", + ), + array( + "include_once \"phar://PEAR.phar/", + $pearver, + ), + $commandcontents); +$creator->addString($commandcontents, 'OS/Guess.php'); + $commandcontents = file_get_contents($peardir . DIRECTORY_SEPARATOR . 'PEAR' . DIRECTORY_SEPARATOR . 'PackageFile.php'); $commandcontents = str_replace( @@ -173,12 +204,12 @@ $commandcontents); $creator->addString($commandcontents, 'PEAR/PackageFile.php'); -$creator->addFile($xmlrpcdir . DIRECTORY_SEPARATOR . 'RPC.php', 'XML/RPC.php', true); $creator->addFile($peardir . DIRECTORY_SEPARATOR . 'template.spec', 'PEAR/template.spec'); $creator->addDir($peardir, array('tests/', 'scripts/', 'go-pear-list.php', 'install-pear.php', + '*OS/Guess.php', '*PEAR/Autoloader.php', '*PEAR/Builder.php', '*PEAR/Dependency.php', @@ -186,7 +217,6 @@ '*PEAR/Dependency2.php', '*PEAR/PackageFile/Generator/v1.php', '*PEAR/PackageFile/Generator/v2.php', - '*PEAR/newRemote.php', '*PEAR/ErrorStack5.php', '*PEAR/Exception.php', '*PEAR/FTP.php', @@ -205,6 +235,6 @@ '*PEAR/Task/Replace/rw.php', '*PEAR/Task/Unixeol/rw.php', '*PEAR/Task/Windowseol/rw.php', - '*PEAR/Frontend.php'), array('*.php'), 'PEAR.phar'); + '*PEAR/Frontend.php'), array('*.php','*.xml'), 'PEAR.phar'); $creator->savePhar(dirname(__FILE__) . DIRECTORY_SEPARATOR . 'PEAR.phar'); ?> \ No newline at end of file http://cvs.php.net/diff.php/pear/PHP_Archive/tests/normalstat.phpt?r1=1.1&r2=1.2&ty=u Index: pear/PHP_Archive/tests/normalstat.phpt diff -u pear/PHP_Archive/tests/normalstat.phpt:1.1 pear/PHP_Archive/tests/normalstat.phpt:1.2 --- pear/PHP_Archive/tests/normalstat.phpt:1.1 Tue May 3 14:34:28 2005 +++ pear/PHP_Archive/tests/normalstat.phpt Wed Nov 30 00:25:06 2005 @@ -10,9 +10,10 @@ <?php require_once dirname(__FILE__) . DIRECTORY_SEPARATOR . 'phpt_test.php.inc'; require_once 'PHP/Archive.php'; -require dirname(__FILE__) . DIRECTORY_SEPARATOR . 'cachestat' . DIRECTORY_SEPARATOR . - 'cachestat.phar'; +require dirname(__FILE__) . DIRECTORY_SEPARATOR . 'longfilename' . DIRECTORY_SEPARATOR . + 'longphar.phar'; $phpunit = new PEAR_PHPTest(true); +$x = stat('phar://longphar.phar/testtesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttest.php'); $phpunit->assertEquals(array ( 0 => 0, 1 => 0, @@ -22,9 +23,9 @@ 5 => 0, 6 => 0, 7 => 47, - 8 => 0, - 9 => 0, - 10 => 0, + 8 => $x[8], + 9 => $x[8], + 10 => $x[8], 11 => -1, 12 => -1, 'dev' => 0, @@ -35,14 +36,14 @@ 'gid' => 0, 'rdev' => 0, 'size' => 47, - 'atime' => 0, - 'mtime' => 0, - 'ctime' => 0, + 'atime' => $x[8], + 'mtime' => $x[8], + 'ctime' => $x[8], 'blksize' => -1, 'blocks' => -1, -), stat('phar://cachestat.phar/test1.php'), 'stat'); +), $x, 'stat'); echo 'tests done'; ?> --EXPECT-- -phar://cachestat.phar/test1.phpstring(5) "hello" +phar://longphar.phar/testtesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttest.phpstring(5) "hello" tests done \ No newline at end of file http://cvs.php.net/diff.php/pear/PHP_Archive/tests/pearindex.php?r1=1.6&r2=1.7&ty=u Index: pear/PHP_Archive/tests/pearindex.php diff -u pear/PHP_Archive/tests/pearindex.php:1.6 pear/PHP_Archive/tests/pearindex.php:1.7 --- pear/PHP_Archive/tests/pearindex.php:1.6 Mon May 2 18:23:45 2005 +++ pear/PHP_Archive/tests/pearindex.php Wed Nov 30 00:25:06 2005 @@ -19,7 +19,6 @@ print "$errortype: $m in $file on $line\n"; } //set_error_handler('testerr'); -PHP_Archive::cacheStat('PEAR.phar'); // {{{ usage() function usage($error = null, $helpsubject = null) @@ -159,6 +158,22 @@ } $ui = &PEAR_Command::getFrontendObject(); $config = &PEAR_Config::singleton($pear_user_config, $pear_system_config); +if (PEAR::isError($config)) { + $_file = ''; + if ($pear_user_config !== false) { + $_file .= $pear_user_config; + } + if ($pear_system_config !== false) { + $_file .= '/' . $pear_system_config; + } + if ($_file == '/') { + $_file = 'The default config file'; + } + $config->getMessage(); + $ui->outputData("ERROR: $_file is not a valid config file or is corrupted."); + // We stop, we have no idea where we are :) + exit(); +} $ui->setConfig($config); PEAR::setErrorHandling(PEAR_ERROR_CALLBACK, array($ui, "displayFatalError")); if (ini_get('safe_mode')) { http://cvs.php.net/diff.php/pear/PHP_Archive/tests/phar.log?r1=1.1&r2=1.2&ty=u Index: pear/PHP_Archive/tests/phar.log http://cvs.php.net/diff.php/pear/PHP_Archive/tests/require_once.phpt?r1=1.3&r2=1.4&ty=u Index: pear/PHP_Archive/tests/require_once.phpt diff -u pear/PHP_Archive/tests/require_once.phpt:1.3 pear/PHP_Archive/tests/require_once.phpt:1.4 --- pear/PHP_Archive/tests/require_once.phpt:1.3 Sun Jul 24 15:38:55 2005 +++ pear/PHP_Archive/tests/require_once.phpt Wed Nov 30 00:25:06 2005 @@ -12,5 +12,4 @@ ?> --EXPECTF-- phar://require_once.phar/indexhooha.php -Fatal error: Error: "nosuchfile.php" not found in phar "require_once.phar" in %s on line %s -PHP Fatal error: Error: "nosuchfile.php" not found in phar "require_once.phar" in %s on line %s \ No newline at end of file +Fatal error: Error: "nosuchfile.php" is not a file in phar "require_once.phar" in %s on line %s \ No newline at end of file http://cvs.php.net/diff.php/pear/PHP_Archive/tests/seek.phpt?r1=1.1&r2=1.2&ty=u Index: pear/PHP_Archive/tests/seek.phpt diff -u pear/PHP_Archive/tests/seek.phpt:1.1 pear/PHP_Archive/tests/seek.phpt:1.2 --- pear/PHP_Archive/tests/seek.phpt:1.1 Tue May 3 14:34:28 2005 +++ pear/PHP_Archive/tests/seek.phpt Wed Nov 30 00:25:06 2005 @@ -10,10 +10,10 @@ <?php require_once dirname(__FILE__) . DIRECTORY_SEPARATOR . 'phpt_test.php.inc'; require_once 'PHP/Archive.php'; -require dirname(__FILE__) . DIRECTORY_SEPARATOR . 'cachestat' . DIRECTORY_SEPARATOR . - 'cachestat.phar'; +require dirname(__FILE__) . DIRECTORY_SEPARATOR . 'longfilename' . DIRECTORY_SEPARATOR . + 'longphar.phar'; $phpunit = new PEAR_PHPTest(true); -$fp = fopen('phar://cachestat.phar/test1.php', 'r'); +$fp = fopen('phar://longphar.phar/testtesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttest.php', 'r'); var_dump(ftell($fp)); var_dump(fread($fp, 2)); fseek($fp, 3); @@ -36,7 +36,7 @@ echo 'tests done'; ?> --EXPECT-- -phar://cachestat.phar/test1.phpstring(5) "hello" +phar://longphar.phar/testtesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttest.phpstring(5) "hello" int(0) string(2) "<?" int(3) http://cvs.php.net/diff.php/pear/PHP_Archive/tests/streamstat.phpt?r1=1.1&r2=1.2&ty=u Index: pear/PHP_Archive/tests/streamstat.phpt diff -u pear/PHP_Archive/tests/streamstat.phpt:1.1 pear/PHP_Archive/tests/streamstat.phpt:1.2 --- pear/PHP_Archive/tests/streamstat.phpt:1.1 Tue May 3 14:34:28 2005 +++ pear/PHP_Archive/tests/streamstat.phpt Wed Nov 30 00:25:06 2005 @@ -10,10 +10,11 @@ <?php require_once dirname(__FILE__) . DIRECTORY_SEPARATOR . 'phpt_test.php.inc'; require_once 'PHP/Archive.php'; -require dirname(__FILE__) . DIRECTORY_SEPARATOR . 'cachestat' . DIRECTORY_SEPARATOR . - 'cachestat.phar'; -$fp = fopen('phar://cachestat.phar/test1.php', 'r'); +require dirname(__FILE__) . DIRECTORY_SEPARATOR . 'longfilename' . DIRECTORY_SEPARATOR . + 'longphar.phar'; +$fp = fopen('phar://longphar.phar/testtesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttest.php', 'r'); $phpunit = new PEAR_PHPTest(true); +$x = fstat($fp); $phpunit->assertEquals(array ( 0 => 0, 1 => 0, @@ -23,9 +24,9 @@ 5 => 0, 6 => 0, 7 => 47, - 8 => 0, - 9 => 0, - 10 => 0, + 8 => $x[8], + 9 => $x[8], + 10 => $x[8], 11 => -1, 12 => -1, 'dev' => 0, @@ -36,15 +37,15 @@ 'gid' => 0, 'rdev' => 0, 'size' => 47, - 'atime' => 0, - 'mtime' => 0, - 'ctime' => 0, + 'atime' => $x[8], + 'mtime' => $x[8], + 'ctime' => $x[8], 'blksize' => -1, 'blocks' => -1, -), fstat($fp), 'stat'); +), $x, 'stat'); fclose($fp); echo 'tests done'; ?> --EXPECT-- -phar://cachestat.phar/test1.phpstring(5) "hello" +phar://longphar.phar/testtesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttest.phpstring(5) "hello" tests done \ No newline at end of file http://cvs.php.net/diff.php/pear/PHP_Archive/tests/filenotfound/filenotfound.phar?r1=1.3&r2=1.4&ty=u Index: pear/PHP_Archive/tests/filenotfound/filenotfound.phar http://cvs.php.net/diff.php/pear/PHP_Archive/tests/longfilename/longphar.phar?r1=1.5&r2=1.6&ty=u Index: pear/PHP_Archive/tests/longfilename/longphar.phar http://cvs.php.net/diff.php/pear/PHP_Archive/tests/opendir/opendir.phar?r1=1.4&r2=1.5&ty=u Index: pear/PHP_Archive/tests/opendir/opendir.phar http://cvs.php.net/diff.php/pear/PHP_Archive/tests/require_once/require_once.phar?r1=1.3&r2=1.4&ty=u Index: pear/PHP_Archive/tests/require_once/require_once.phar
http://cvs.php.net/diff.php/pear/PHP_Archive/Archive.php?r1=1.19&r2=1.20&ty=u Index: pear/PHP_Archive/Archive.php diff -u pear/PHP_Archive/Archive.php:1.19 pear/PHP_Archive/Archive.php:1.20 --- pear/PHP_Archive/Archive.php:1.19 Sun Jul 24 11:42:20 2005 +++ pear/PHP_Archive/Archive.php Wed Nov 30 00:24:54 2005 @@ -13,79 +13,93 @@ * URIs to your includes. i.e. require_once 'phar://config.php' will include config.php * from the root of the PHAR file. * - * Tar/Gz code borrowed from the excellent File_Archive package by Vincent Lascaux. + * Gz code borrowed from the excellent File_Archive package by Vincent Lascaux. * * @copyright Copyright © David Shafik and Synaptic Media 2004. All rights reserved. * @author Davey Shafik <davey@synapticmedia.net> * @author Greg Beaver <cellog@php.net> * @link http://www.synapticmedia.net Synaptic Media - * @version $Id: Archive.php,v 1.19 2005/07/24 15:42:20 cellog Exp $ + * @version $Id: Archive.php,v 1.20 2005/11/30 05:24:54 cellog Exp $ * @package PHP_Archive * @category PHP */ class PHP_Archive { + private $_compressed; /** - * @var string Current phar basename (like PEAR.phar) + * @var string Real path to the .phar archive */ - protected $basename; + protected $pharName = null; /** - * @var string Archive filename - */ - protected $archiveName = null; - /** - * Current Stat info of the current file in the tar - */ - protected $currentStat = null; - /** - * Current file name in the tar + * Current file name in the phar * @var string */ protected $currentFilename = null; /** - * Length of the current tar file - * @var int - */ - protected $internalFileLength = 0; - /** - * Length of the current tar file's footer - * @var int + * Length of current file in the phar + * @var string */ - protected $footerLength = 0; + protected $internalFileLength = null; /** - * @var string Content of the file being requested + * Current file statistics (size, creation date, etc.) + * @var string */ - protected $file = null; + protected $currentStat = null; /** * @var resource|null Pointer to open .phar */ protected $fp = null; /** - * @var int length of the current archive - */ - protected $fplen = null; - /** * @var int Current Position of the pointer */ protected $position = 0; - private static $_cache; + private static $_pharMapping = array(); + private static $_manifest = array(); + private static $_fileStart = array(); + private $basename; + /** - * @param string basename of the phar to cache stat from. + * Map a full real file path to an alias used to refer to the .phar + * + * This function can only be called from the initialization of the .phar itself. + * Any attempt to call from outside the .phar or to re-alias the .phar will fail + * as a security measure. + * @param string $file full realpath() filepath, like /path/to/go-pear.phar + * @param string $alias alias used in opening a file within the phar + * like phar://go-pear.phar/file + * @param bool $compressed determines whether to attempt zlib uncompression + * on accessing internal files + * @param int $dataoffset the value of __COMPILER_HALT_OFFSET__ */ - public static function cacheStat($pharname) + public static function mapPhar($file, $alias, $compressed, $dataoffset) { - if (!isset(self::$_cache)) { - self::$_cache = array(); + if ($compressed) { + if (!function_exists('gzinflate')) { + die('Error: zlib extension is not enabled - gzinflate() function needed' . + ' for compressed .phars'); + } } - self::$_cache[$pharname] = array(); + // this ensures that this is safe + if (!in_array($file, get_included_files())) { + die('SECURITY ERROR: PHP_Archive::mapPhar can only be called from within ' . + 'the phar that initiates it'); + } + if (!is_array(self::$_pharMapping)) { + self::$_pharMapping = array(); + } + if (isset(self::$_pharMapping[$alias])) { + die('ERROR: PHP_Archive::mapPhar has already been called for alias "' . + $alias . '" cannot re-alias to "' . $file . '"'); + } + self::$_pharMapping[$alias] = array($file, $compressed, $dataoffset); } /** * @param string */ - protected function processFile($path) + public static function processFile($path) { if ($path == '.') { return ''; @@ -93,6 +107,9 @@ $std = str_replace("\\", "/", $path); while ($std != ($std = ereg_replace("[^\/:?]+/\.\./", "", $std))) ; $std = str_replace("/./", "", $std); + if (strlen($std) > 1 && $std[0] == '/') { + $std = substr($std, 1); + } if (strncmp($std, "./", 2) == 0) { return substr($std, 2); } else { @@ -104,156 +121,43 @@ * Seek in the master archive to a matching file or directory * @param string */ - protected function selectFile($path) + protected function selectFile($path, $allowdirs = true) { - $std = $this->processFile($path); - $this->_index = 0; - while (($error = $this->_nextFile()) === true) { - if (empty($std) || $std == $this->currentFilename || + $std = self::processFile($path); + if (isset(self::$_manifest[$this->basename][$path])) { + $this->_setCurrentFile($path); + return true; + } + if (!$allowdirs) { + return 'Error: "' . $path . '" is not a file in phar "' . $this->basename . '"'; + } + foreach (self::$_manifest[$this->basename] as $file => $info) { + if (empty($std) || //$std is a directory - strncmp($std.'/', $this->currentFilename, strlen($std)+1) == 0) { - if (isset($this->cachedFpos)) { - @fseek($this->fp, $this->cachedFpos); - } + strncmp($std.'/', $path, strlen($std)+1) == 0) { + $this->currentFilename = $this->internalFileLength = $this->currentStat = null; return true; } } - if (@ftell($this->fp) >= $this->fplen) { - return 'Error: "' . $path . '" not found in phar "' . $this->basename . '"'; - } - return $error; + return 'Error: "' . $path . '" not found in phar "' . $this->basename . '"'; } - /** - * Process a raw tar header and extract file name, size, and additional info - * @param string contents of the header - * @uses $footerLength sets the footer length - * @uses $internalFileLength sets the file length, if filename < 100 chars - * @uses $currentStat sets the file statistics - * @return array|string a string is returned on error - */ - private function _processHeader($rawHeader) + private function _setCurrentFile($path) { - if (strlen($rawHeader) < 512 || $rawHeader == pack("a512", "")) { - return 'Error: phar "' . $this->archiveName . '" has corrupted tar header'; - } - - $header = unpack( - "a100filename/a8mode/a8uid/a8gid/a12size/a12mtime/". - "a8checksum/a1type/a100linkname/a6magic/a2version/". - "a32uname/a32gname/a8devmajor/a8devminor/a155path", - $rawHeader); $this->currentStat = array( - 2 => octdec($header['mode']), - 4 => octdec($header['uid']), - 5 => octdec($header['gid']), - 7 => octdec($header['size']), - 9 => octdec($header['mtime']) + 2 => 0100444, // file mode, readable by all, writeable by none + 4 => 0, // uid + 5 => 0, // gid + 7 => self::$_manifest[$this->basename][$path][0], // size + 9 => self::$_manifest[$this->basename][$path][1], // creation time ); - - $this->internalFileLength = $this->currentStat[7]; - if ($this->internalFileLength % 512 == 0) { - $this->footerLength = 0; - } else { - $this->footerLength = 512 - $this->internalFileLength % 512; - } - return $header; - } - - /** - * Seek to the next file, if any, and verify its integrity - * @return boolean|array|string if a cached file is used, true is returned. False is returned - * for a directory entry, and the raw header unpacked is returned - * on seek success. On error, a string is returned - */ - private function _nextFile() - { - if (isset(self::$_cache) && - isset(self::$_cache[$this->basename]) && - isset(self::$_cache[$this->basename][$this->_index])) { - $this->currentFilename = - self::$_cache[$this->basename][$this->_index]['file']; - $this->currentStat = - self::$_cache[$this->basename][$this->_index]['stat']; - $this->internalFileLength = - self::$_cache[$this->basename][$this->_index]['length']; - $this->cachedFpos = self::$_cache[$this->basename][$this->_index]['fpos']; - $this->footerLength = - self::$_cache[$this->basename][$this->_index]['footerlen']; - $this->_index++; - return true; - } - if (isset($this->cachedFpos)) { - @fseek($this->fp, $this->cachedFpos); - } - fseek($this->fp, $this->internalFileLength + $this->footerLength, SEEK_CUR); - $rawHeader = @fread($this->fp, 512); - $header = $this->_processHeader($rawHeader); - if (is_string($header)) { - return $header; - } - if ($header['type'] == '5') { - return false; // directory entry - } - - if ($header['type'] == 'L') { - // filenames longer than 100 characters - // borrowed from Archive_Tar written by Vincent Blavet - $longFilename = ''; - $n = floor($header['size']/512); - for ($i=0; $i < $n; $i++) { - $content = @fread($this->fp, 512); - $longFilename .= $content; - } - if (($header['size'] % 512) != 0) { - $content = @fread($this->fp, 512); - $longFilename .= $content; - } - // ----- Read the next header - $newHeader = @fread($this->fp, 512); - $header = $this->_processHeader($newHeader); - if (is_string($header)) { - return $header; - } - $header['filename'] = trim($longFilename); - $rawHeader = $newHeader; - } - $this->currentFilename = $this->processFile($header['path'] . $header['filename']); - $checksum = 8 * ord(" "); - if (version_compare(phpversion(), '5.0.0', '>=')) { - $c1 = str_split(substr($rawHeader, 0, 512)); - $checkheader = array_merge(array_slice($c1, 0, 148), array_slice($c1, 156)); - if (!function_exists('_PharDoChecksum')) { - function _PharDoChecksum($a, $b) {return $a + ord($b);} - } - $checksum += array_reduce($checkheader, '_PharDoChecksum'); - } else { - for ($i = 0; $i < 148; $i++) { - $checksum += ord($rawHeader{$i}); - } - for ($i = 156; $i < 512; $i++) { - $checksum += ord($rawHeader{$i}); - } - } - - if (octdec($header['checksum']) != $checksum) { - return 'Error: phar "' . - $this->archiveName . '" Checksum error on entry "' . $this->currentFilename . '"'; - } - if (isset(self::$_cache) && - isset(self::$_cache[$this->basename])) { - self::$_cache[$this->basename][] = - array( - 'file' => $this->currentFilename, - 'stat' => $this->currentStat, - 'length' => $this->internalFileLength, - 'fpos' => @ftell($this->fp), - 'footerlen' => $this->footerLength, - ); - $this->cachedFpos = null; + $this->currentFilename = $path; + // actual file length in file includes 8-byte header + $this->internalFileLength = self::$_manifest[$this->basename][$path][3] - 8; + // seek to offset of file header within the .phar + if (is_resource(@$this->fp)) { + fseek($this->fp, self::$_fileStart[$this->basename] + self::$_manifest[$this->basename][$path][2]); } - $this->_index++; - return true; } /** @@ -266,11 +170,11 @@ { $this->fp = @fopen($this->archiveName, "rb"); $stat = fstat($this->fp); - $this->fplen = $stat['size']; if (!$this->fp) { return array('Error: cannot open phar "' . $this->archiveName . '"'); } - if (($e = $this->selectFile($path)) === true) { + if (($e = $this->selectFile($path, false)) === true) { + $temp = unpack("Vcrc32/Visize", fread($this->fp, 8)); $data = ''; $count = $this->internalFileLength; while ($count) { @@ -283,6 +187,19 @@ } } @fclose($this->fp); + if ($this->_compressed) { + $data = gzinflate($data); + } + if (!isset(self::$_manifest[$this->basename][$path]['ok'])) { + if ($temp['isize'] != $this->currentStat[7]) { + return array("Not valid internal .phar file (size error {$size} != " . + $this->currentStat[7] . ")"); + } + if ($temp['crc32'] != crc32($data)) { + return array("Not valid internal .phar file (checksum error)"); + } + self::$_manifest[$this->basename][$path]['ok'] = true; + } return $data; } else { @fclose($this->fp); @@ -303,36 +220,59 @@ */ public function initializeStream($file) { - $aname = get_included_files(); - $this->archiveName = 'phar://'; - if (strpos($file, '.phar')) { - // grab the basename of the phar we want - $test = substr($file, 0, strpos($file, '.phar') + 5); - } else { - $test = false; - } - while (count($aname)) { - $this->archiveName = array_pop($aname); - if (strpos($this->archiveName, 'phar://') === false) { - if ($test) { - if (strpos($this->archiveName, $test)) { - break; - } - } else { - break; - } - } + $info = parse_url($file); + if (!isset($info['host']) || !count(self::$_pharMapping)) { + // malformed internal file + return false; } - if ($test && $this->archiveName != 'phar://') { - $this->basename = $test; - $file = substr($file, strlen($test) + 1); - if (!$file) { - $file = '/'; // this is for opendir requests - } + if (!isset($info['path'])) { + // last opened phar is requested + $info['path'] = $info['host']; + $info['host'] = ''; + } elseif (strlen($info['path']) > 1) { + $info['path'] = substr($info['path'], 1); + } + if (isset(self::$_pharMapping[$info['host']])) { + $this->basename = $info['host']; + $this->archiveName = self::$_pharMapping[$info['host']][0]; + $this->_compressed = self::$_pharMapping[$info['host']][1]; + } else { + // no such phar has been included, or last opened phar is requested + $pharinfo = end(self::$_pharMapping); + $this->basename = key(self::$_pharMapping); + $this->archiveName = $pharinfo[0]; + $this->_compressed = $pharinfo[1]; + } + if (!isset(self::$_manifest[$this->basename])) { + $fp = fopen($this->archiveName, 'rb'); + // seek to __HALT_COMPILER_OFFSET__ + fseek($fp, self::$_pharMapping[$this->basename][2]); + $manifest_length = unpack('Vlen', fread($fp, 4)); + self::$_manifest[$this->basename] = + $this->unserializeManifest(fread($fp, $manifest_length['len'])); + self::$_fileStart[$this->basename] = ftell($fp); + fclose($fp); } + $file = $info['path']; return $file; } + + function unserializeManifest($manifest) + { + $info = unpack('V', substr($manifest, 0, 4)); + $manifest = substr($manifest, 4); + $ret = array(); + for ($i = 0; $i < $info[1]; $i++) { + $len = unpack('V', substr($manifest, 0, 4)); + $savepath = substr($manifest, 4, $len[1]); + $manifest = substr($manifest, $len[1] + 4); + $ret[$savepath] = array_values(unpack('Va/Vb/Vc/Vd', substr($manifest, 0, 16))); + $manifest = substr($manifest, 16); + } + return $ret; + } + /** * Open the requested file - PHP streams API * @@ -354,9 +294,8 @@ */ private function _streamOpen($file, $searchForDir = false) { - $path = substr($file, 7); - $path = $this->initializeStream($path); - if ($this->archiveName == 'phar://') { + $path = $this->initializeStream($file); + if (!$path) { trigger_error('Error: Unknown phar in "' . $file . '"', E_USER_ERROR); } if (is_array($this->file = $this->extractFile($path))) { @@ -372,34 +311,7 @@ return true; } } - $compressed = $this->file ? (int) $this->file{0} : false; - $this->file ? $this->file = substr($this->file, 1) : false; - if ($compressed) { - if (!function_exists('gzinflate')) { - trigger_error('Error: zlib extension is not enabled - gzinflate() function needed' . - ' for compressed .phars'); - return false; - } - $header = substr($this->file, 0, 10); - $temp = unpack("Vcrc32/Visize", substr($this->file, -8)); - - $id = @unpack("H2id1/H2id2/C1tmp/C1flags", substr($header, 0, 4)); - if ($id['id1'] != "1f" || $id['id2'] != "8b") { - trigger_error("Not valid gz file (wrong header)", E_USER_ERROR); - return false; - } - $this->file = gzinflate(substr($this->file, 10, strlen($this->file) - 8)); - if ($temp['isize'] != strlen($this->file)) { - trigger_error("Not valid gz file (size error {$size} != " . - strlen($this->file) . ")", E_USER_ERROR); - return false; - } - if ($temp['crc32'] != crc32($this->file)) { - trigger_error("Not valid gz file (checksum error)", E_USER_ERROR); - return false; - } - } if (!is_null($this->file) && $this->file !== false) { return true; } else { @@ -426,7 +338,7 @@ */ function stream_eof() { - return $this->position >= strlen($this->file); + return $this->position >= $this->currentStat[7]; } /** @@ -445,16 +357,16 @@ $this->position = $pos; break; case SEEK_CUR: - if ($pos + strlen($this->file) < 0) { + if ($pos + $this->currentStat[7] < 0) { return false; } $this->position += $pos; break; case SEEK_END: - if ($pos + strlen($this->file) < 0) { + if ($pos + $this->currentStat[7] < 0) { return false; } - $this->position = $pos + strlen($this->file); + $this->position = $pos + $this->currentStat[7]; default: return false; } @@ -471,7 +383,8 @@ } /** - * The result of an fstat call, returns mod time from tar, and file size - PHP streams API + * The result of an fstat call, returns mod time from creation, and file size - + * PHP streams API * @uses _stream_stat() * @access private */ @@ -487,8 +400,17 @@ */ public function _stream_stat($file = null) { - $std = $file ? $this->processFile($file) : $this->currentFilename; - $isdir = strncmp($std . '/', $this->currentFilename, strlen($std) + 1) == 0; + $std = $file ? self::processFile($file) : $this->currentFilename; + if ($file) { + if (isset(self::$_manifest[$this->basename][$file])) { + $this->_setCurrentFile($file); + $isdir = false; + } else { + $isdir = true; + } + } else { + $isdir = false; // open streams must be files + } $mode = $isdir ? 0040444 : 0100444; // 040000 = dir, 010000 = file // everything is readable, nothing is writeable @@ -497,7 +419,7 @@ 'dev' => 0, 'ino' => 0, 'mode' => $mode, 'nlink' => 0, 'uid' => 0, 'gid' => 0, 'rdev' => 0, 'blksize' => 0, 'blocks' => 0, - 'size' => strlen($this->file), + 'size' => $this->currentStat[7], 'atime' => $this->currentStat[9], 'mtime' => $this->currentStat[9], 'ctime' => $this->currentStat[9], @@ -512,8 +434,6 @@ */ public function url_stat($url, $flags) { - $this->_streamOpen($url, true); - $url = substr($url, 7); $path = $this->initializeStream($url); return $this->_stream_stat($path); } @@ -528,32 +448,33 @@ $info = parse_url($path); $path = !empty($info['path']) ? $info['host'] . $info['path'] : $info['host'] . '/'; - $path = $this->initializeStream($path); - if ($this->archiveName == 'phar://') { + $path = $this->initializeStream('phar://' . $path); + if (isset(self::$_manifest[$this->basename][$path])) { + trigger_error('Error: "' . $path . '" is a file, and cannot be opened with opendir', + E_USER_ERROR); + return false; + } + if ($path == false) { trigger_error('Error: Unknown phar in "' . $file . '"', E_USER_ERROR); return false; } $this->fp = @fopen($this->archiveName, "rb"); - $stat = fstat($this->fp); - $this->fplen = $stat['size']; if (!$this->fp) { - return array('Error: cannot open phar "' . $this->archiveName . '"'); + trigger_error('Error: cannot open phar "' . $this->archiveName . '"'); + return false; } $this->_dirFiles = array(); - while (($error = $this->_nextFile()) === true) { - if (strpos($this->currentFilename, '#PHP_ARCHIVE_HEADER-0.5.0.php')) { - continue; - } + foreach (self::$_manifest[$this->basename] as $file => $info) { if ($path == '/') { - if (strpos($this->currentFilename, '/')) { - $this->_dirFiles[array_shift($a = explode('/', $this->currentFilename))] = true; + if (strpos($file, '/')) { + $this->_dirFiles[array_shift($a = explode('/', $file))] = true; } else { - $this->_dirFiles[$this->currentFilename] = true; + $this->_dirFiles[$file] = true; } - } elseif (strpos($this->currentFilename, $path) === 0) { - $fname = substr($this->currentFilename, strlen($path) + 1); + } elseif (strpos($file, $path) === 0) { + $fname = substr($file, strlen($path) + 1); if (strpos($fname, '/')) { - $this->_dirFiles[array_unshift(explode('/', $fname))] = true; + $this->_dirFiles[array_unshift($a = explode('/', $fname))] = true; } else { $this->_dirFiles[$fname] = true; } http://cvs.php.net/diff.php/pear/PHP_Archive/package.php?r1=1.13&r2=1.14&ty=u Index: pear/PHP_Archive/package.php diff -u pear/PHP_Archive/package.php:1.13 pear/PHP_Archive/package.php:1.14 --- pear/PHP_Archive/package.php:1.13 Mon Sep 5 16:02:51 2005 +++ pear/PHP_Archive/package.php Wed Nov 30 00:24:55 2005 @@ -2,20 +2,21 @@ require_once 'PEAR/PackageFileManager.php'; require_once 'PEAR/PackageFileManager2.php'; PEAR::setErrorHAndling(PEAR_ERROR_DIE); -$version = '0.6.1'; -$apiversion = '0.6'; +$version = '0.7.0'; +$apiversion = '0.7'; $notes = <<<EOT -Bugfix release - * fix faulty dependency on unreleased Archive_Tar - * fix version_compare()'s bungling of versioning ending with -dev +major refactoring - .tar file format is no longer used +DRAMATIC improvement in efficiency of disk use, memory usage, +and processing speed. EOT; $package = PEAR_PackageFileManager2::importFromPackageFile1(dirname(__FILE__) . DIRECTORY_SEPARATOR . 'package.xml', $options = array( 'ignore' => array('package.php', 'package.xml', 'package2.xml', '*.bak', '*src*', - '*.tgz', '*pear_media*', 'index.htm', 'PEAR.phar', 'docs/', 'phar_unpack.php', 'info.phar'), - 'filelistgenerator' => 'cvs', // other option is 'file' + '*.tgz', '*pear_media*', 'index.htm', 'PEAR.phar', 'docs/', 'phar_unpack.php', 'info.phar', + '*CVS*'), + 'filelistgenerator' => 'file', // other option is 'file' 'changelogoldtonew' => false, 'baseinstalldir' => 'PHP', 'packagedirectory' => dirname(__FILE__), @@ -28,14 +29,17 @@ $package->setAPIStability('alpha'); $package->setNotes($notes); $package->clearDeps(); -$package->addPackageDepWithChannel('required', 'Archive_Tar', 'pear.php.net', '1.3.1'); -$package->addPackageDepWithChannel('required', 'PEAR', 'pear.php.net', '1.3.5'); +$package->addPackageDepWithChannel('required', 'PEAR', 'pear.php.net', '1.4.3'); $package->setPhpDep('5.1.0b1'); -$package->setPearinstallerDep('1.4.0b1'); -$package->generateContents(); +$package->setPearinstallerDep('1.4.3'); $package->addReplacement('Archive.php', 'package-info', '@API-VER@', 'api-version'); $package->addReplacement('Archive/Creator.php', 'package-info', '@API-VER@', 'api-version'); +$package->generateContents(); + +$package->setPackageType('php'); +$package->addRelease(); + $pf1 = $package->exportCompatiblePackageFile1($options); if (isset($_SERVER['argv'][1]) && $_SERVER['argv'][1] == 'commit') { $package->writePackageFile(); http://cvs.php.net/diff.php/pear/PHP_Archive/package.xml?r1=1.13&r2=1.14&ty=u Index: pear/PHP_Archive/package.xml diff -u pear/PHP_Archive/package.xml:1.13 pear/PHP_Archive/package.xml:1.14 --- pear/PHP_Archive/package.xml:1.13 Mon Sep 5 16:02:51 2005 +++ pear/PHP_Archive/package.xml Wed Nov 30 00:24:55 2005 @@ -1,6 +1,6 @@ -<?xml version="1.0" encoding="ISO-8859-1" ?> +<?xml version="1.0" encoding="UTF-8" ?> <!DOCTYPE package SYSTEM "http://pear.php.net/dtd/package-1.0"> -<package version="1.0" packagerversion="1.4.0b1"> +<package version="1.0" packagerversion="1.4.5"> <name>PHP_Archive</name> <summary>Create and Use PHP Archive files</summary> <description>PHP_Archive allows you to create a single .phar file containing an entire application. @@ -20,18 +20,17 @@ </maintainer> </maintainers> <release> - <version>0.6.1</version> - <date>2005-09-05</date> + <version>0.7.0</version> + <date>2005-11-25</date> <license>PHP License</license> <state>alpha</state> - <notes>Bugfix release - * fix faulty dependency on unreleased Archive_Tar - * fix version_compare()'s bungling of versioning ending with -dev + <notes>major refactoring - .tar file format is no longer used +DRAMATIC improvement in efficiency of disk use, memory usage, +and processing speed. </notes> <deps> <dep type="php" rel="ge" version="5.1.0b1" optional="no"/> - <dep type="pkg" rel="ge" version="1.3.1" optional="no">Archive_Tar</dep> - <dep type="pkg" rel="ge" version="1.3.5" optional="no">PEAR</dep> + <dep type="pkg" rel="ge" version="1.4.3" optional="no">PEAR</dep> </deps> <filelist> <dir name="/" baseinstalldir="PHP"> @@ -39,6 +38,9 @@ <file role="php" name="Creator.php"> <replace from="@API-VER@" to="api-version" type="package-info"/> </file> + <file role="php" name="Creator2.php"> + <replace from="@API-VER@" to="api-version" type="package-info"/> + </file> </dir> <!-- /Archive --> <dir name="tests"> <dir name="cachestat"> @@ -93,18 +95,31 @@ <file role="php" name="Archive.php"> <replace from="@API-VER@" to="api-version" type="package-info"/> </file> + <file role="php" name="Archive2.php"> + <replace from="@API-VER@" to="api-version" type="package-info"/> + </file> </dir> <!-- / --> </filelist> </release> <changelog> <release> + <version>0.7.0</version> + <date>2005-11-25</date> + <license>PHP License</license> + <state>alpha</state> + <notes>major refactoring - .tar file format is no longer used +DRAMATIC improvement in efficiency of disk use, memory usage, +and processing speed. + </notes> + </release> + <release> <version>0.6.1</version> <date>2005-09-05</date> <license>PHP License</license> <state>alpha</state> <notes>Bugfix release * fix faulty dependency on unreleased Archive_Tar - * fix version_compare()'s bungling of versioning ending with -dev + * fix version_compare()'s bungling of versioning ending with -dev </notes> </release> <release> http://cvs.php.net/diff.php/pear/PHP_Archive/package2.xml?r1=1.5&r2=1.6&ty=u Index: pear/PHP_Archive/package2.xml diff -u pear/PHP_Archive/package2.xml:1.5 pear/PHP_Archive/package2.xml:1.6 --- pear/PHP_Archive/package2.xml:1.5 Mon Sep 5 16:02:51 2005 +++ pear/PHP_Archive/package2.xml Wed Nov 30 00:24:55 2005 @@ -1,5 +1,5 @@ -<?xml version="1.0"?> -<package packagerversion="1.4.0b1" version="2.0" xmlns="http://pear.php.net/dtd/package-2.0" xmlns:tasks="http://pear.php.net/dtd/tasks-1.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://pear.php.net/dtd/tasks-1.0 +<?xml version="1.0" encoding="UTF-8"?> +<package packagerversion="1.4.5" version="2.0" xmlns="http://pear.php.net/dtd/package-2.0" xmlns:tasks="http://pear.php.net/dtd/tasks-1.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://pear.php.net/dtd/tasks-1.0 http://pear.php.net/dtd/tasks-1.0.xsd http://pear.php.net/dtd/package-2.0 http://pear.php.net/dtd/package-2.0.xsd"> @@ -21,76 +21,86 @@ <email>cellog@php.net</email> <active>yes</active> </lead> - <date>2005-09-05</date> - <time>15:02:17</time> + <date>2005-11-25</date> + <time>02:05:03</time> <version> - <release>0.6.1</release> - <api>0.6</api> + <release>0.7.0</release> + <api>0.7</api> </version> <stability> <release>alpha</release> <api>alpha</api> </stability> <license uri="http://www.php.net/license">PHP License</license> - <notes>Bugfix release - * fix faulty dependency on unreleased Archive_Tar - * fix version_compare()'s bungling of versioning ending with -dev</notes> + <notes>major refactoring - .tar file format is no longer used +DRAMATIC improvement in efficiency of disk use, memory usage, +and processing speed.</notes> <contents> <dir baseinstalldir="PHP" name="/"> <dir name="Archive"> - <file name="Creator.php" role="php" /> + <file baseinstalldir="PHP" name="Creator.php" role="php"> + <tasks:replace from="@API-VER@" to="api-version" type="package-info" /> + </file> + <file baseinstalldir="PHP" name="Creator2.php" role="php"> + <tasks:replace from="@API-VER@" to="api-version" type="package-info" /> + </file> </dir> <!-- /Archive --> <dir name="tests"> <dir name="cachestat"> - <file name="cachestat.phar" role="test" /> - <file name="makecachestatphar.php.inc" role="test" /> + <file baseinstalldir="PHP" name="cachestat.phar" role="test" /> + <file baseinstalldir="PHP" name="makecachestatphar.php.inc" role="test" /> </dir> <!-- /tests/cachestat --> <dir name="filenotfound"> - <file name="filenotfound.phar" role="test" /> - <file name="makefilenotfoundphar.php.inc" role="test" /> + <file baseinstalldir="PHP" name="filenotfound.phar" role="test" /> + <file baseinstalldir="PHP" name="makefilenotfoundphar.php.inc" role="test" /> </dir> <!-- /tests/filenotfound --> <dir name="longfilename"> - <file name="longphar.phar" role="test" /> - <file name="makelongphar.php.inc" role="test" /> + <file baseinstalldir="PHP" name="longphar.phar" role="test" /> + <file baseinstalldir="PHP" name="makelongphar.php.inc" role="test" /> </dir> <!-- /tests/longfilename --> <dir name="opendir"> - <file name="makeopendirphar.php.inc" role="test" /> - <file name="opendir.phar" role="test" /> + <file baseinstalldir="PHP" name="makeopendirphar.php.inc" role="test" /> + <file baseinstalldir="PHP" name="opendir.phar" role="test" /> </dir> <!-- /tests/opendir --> <dir name="planet_php"> - <file name="default_phar.php" role="test" /> + <file baseinstalldir="PHP" name="default_phar.php" role="test" /> </dir> <!-- /tests/planet_php --> <dir name="require_once"> - <file name="makerequire_oncephar.php.inc" role="test" /> - <file name="require_once.phar" role="test" /> + <file baseinstalldir="PHP" name="makerequire_oncephar.php.inc" role="test" /> + <file baseinstalldir="PHP" name="require_once.phar" role="test" /> </dir> <!-- /tests/require_once --> - <file name="cachestat.phpt" role="test" /> - <file name="cachestattest.php" role="test" /> - <file name="eof.phpt" role="test" /> - <file name="filenotfound.phpt" role="test" /> - <file name="filenotfoundtest.php" role="test" /> - <file name="gopearphar.php.inc" role="test" /> - <file name="longfilename.phpt" role="test" /> - <file name="makepearphar.php.inc" role="test" /> - <file name="new_phar.phar" role="test" /> - <file name="normalstat.phpt" role="test" /> - <file name="opendir.phpt" role="test" /> - <file name="pearindex.php" role="test" /> - <file name="phar.log" role="test" /> - <file name="phpt_test.php.inc" role="test" /> - <file name="require_once.phpt" role="test" /> - <file name="savetest.php" role="test" /> - <file name="seek.phpt" role="test" /> - <file name="streamstat.phpt" role="test" /> - <file name="test.php" role="test" /> - <file name="test1.php" role="test" /> - <file name="test_path.php" role="test" /> - <file name="test_phar.phar" role="test" /> - <file name="test_phar2.phar" role="test" /> - <file name="test_require.php" role="test" /> - <file name="test_tar.tar" role="test" /> + <file baseinstalldir="PHP" name="cachestat.phpt" role="test" /> + <file baseinstalldir="PHP" name="cachestattest.php" role="test" /> + <file baseinstalldir="PHP" name="eof.phpt" role="test" /> + <file baseinstalldir="PHP" name="filenotfound.phpt" role="test" /> + <file baseinstalldir="PHP" name="filenotfoundtest.php" role="test" /> + <file baseinstalldir="PHP" name="gopearphar.php.inc" role="test" /> + <file baseinstalldir="PHP" name="longfilename.phpt" role="test" /> + <file baseinstalldir="PHP" name="makepearphar.php.inc" role="test" /> + <file baseinstalldir="PHP" name="new_phar.phar" role="test" /> + <file baseinstalldir="PHP" name="normalstat.phpt" role="test" /> + <file baseinstalldir="PHP" name="opendir.phpt" role="test" /> + <file baseinstalldir="PHP" name="pearindex.php" role="test" /> + <file baseinstalldir="PHP" name="phar.log" role="test" /> + <file baseinstalldir="PHP" name="phpt_test.php.inc" role="test" /> + <file baseinstalldir="PHP" name="require_once.phpt" role="test" /> + <file baseinstalldir="PHP" name="savetest.php" role="test" /> + <file baseinstalldir="PHP" name="seek.phpt" role="test" /> + <file baseinstalldir="PHP" name="streamstat.phpt" role="test" /> + <file baseinstalldir="PHP" name="test.php" role="test" /> + <file baseinstalldir="PHP" name="test1.php" role="test" /> + <file baseinstalldir="PHP" name="test_path.php" role="test" /> + <file baseinstalldir="PHP" name="test_phar.phar" role="test" /> + <file baseinstalldir="PHP" name="test_phar2.phar" role="test" /> + <file baseinstalldir="PHP" name="test_require.php" role="test" /> + <file baseinstalldir="PHP" name="test_tar.tar" role="test" /> </dir> <!-- /tests --> - <file name="Archive.php" role="php" /> + <file baseinstalldir="PHP" name="Archive.php" role="php"> + <tasks:replace from="@API-VER@" to="api-version" type="package-info" /> + </file> + <file baseinstalldir="PHP" name="Archive2.php" role="php"> + <tasks:replace from="@API-VER@" to="api-version" type="package-info" /> + </file> </dir> <!-- / --> </contents> <dependencies> @@ -99,24 +109,58 @@ <min>5.1.0b1</min> </php> <pearinstaller> - <min>1.4.0b1</min> + <min>1.4.3</min> </pearinstaller> <package> - <name>Archive_Tar</name> - <channel>pear.php.net</channel> - <min>1.3.1</min> - </package> - <package> <name>PEAR</name> <channel>pear.php.net</channel> - <min>1.3.5</min> + <min>1.4.3</min> </package> </required> </dependencies> - <phprelease /> + <phprelease> + <filelist> + <install as="Archive.php" name="Archive2.php" /> + <install as="Archive/Creator.php" name="Archive/Creator2.php" /> + <ignore name="Archive.php" /> + <ignore name="Archive/Creator.php" /> + </filelist> + </phprelease> <changelog> <release> <version> + <release>0.7.0</release> + <api>0.7</api> + </version> + <stability> + <release>alpha</release> + <api>alpha</api> + </stability> + <date>2005-11-25</date> + <license>PHP License</license> + <notes>major refactoring - .tar file format is no longer used +DRAMATIC improvement in efficiency of disk use, memory usage, +and processing speed.</notes> + </release> + <release> + <version> + <release>0.6.1</release> + <api>0.6.1</api> + </version> + <stability> + <release>alpha</release> + <api>alpha</api> + </stability> + <date>2005-09-05</date> + <license uri="http://www.php.net/license">PHP License</license> + <notes>Bugfix release + * fix faulty dependency on unreleased Archive_Tar + * fix version_compare()'s bungling of versioning ending with -dev + + </notes> + </release> + <release> + <version> <release>0.6.0</release> <api>0.6.0</api> </version> @@ -220,20 +264,5 @@ </notes> </release> - <release> - <version> - <release>0.6.1</release> - <api>0.6</api> - </version> - <stability> - <release>alpha</release> - <api>alpha</api> - </stability> - <date>2005-09-05</date> - <license>PHP License</license> - <notes>Bugfix release - * fix faulty dependency on unreleased Archive_Tar - * fix version_compare()'s bungling of versioning ending with -dev</notes> - </release> </changelog> </package> http://cvs.php.net/diff.php/pear/PHP_Archive/Archive/Creator.php?r1=1.17&r2=1.18&ty=u Index: pear/PHP_Archive/Archive/Creator.php diff -u pear/PHP_Archive/Archive/Creator.php:1.17 pear/PHP_Archive/Archive/Creator.php:1.18 --- pear/PHP_Archive/Archive/Creator.php:1.17 Mon Sep 5 15:58:32 2005 +++ pear/PHP_Archive/Archive/Creator.php Wed Nov 30 00:24:59 2005 @@ -1,84 +1,48 @@ <?php -/** - * PHP_Archive Creator Class - * - * @package PHP_Archive - * @category PHP - */ - -/** - * Require PHP_Archive - */ - -require_once 'PHP/Archive.php'; - -/** - * Require System, for temporary dir functions - */ require_once 'System.php'; - -/** - * Require Archive_Tar - */ - -require_once 'Archive/Tar.php'; - -/** - * PHP_Archive Creator Class - * - * This class allows you to easily, programatically create PHP Archives (PHAR files) - * - * @copyright Copyright © David Shafik and Synaptic Media 2004. All rights reserved. - * @author Davey Shafik <davey@synapticmedia.net> - * @link http://www.synapticmedia.net Synaptic Media - * @version $Id: Creator.php,v 1.17 2005/09/05 19:58:32 cellog Exp $ - * @package PHP_Archive - * @category PHP - * @example c:\web\php-cvs\pear\PHP_Archive\docs\examples\PHP_Archive_Creator_Example_1.php Example PHP_Archive_Creator usage - * @todo Implement PHP_Archive_Creator::addDir(); - */ - -class PHP_Archive_Creator { - +require_once 'PHP/Archive.php'; +class PHP_Archive_Creator +{ /** * @var string The Archive Filename */ - protected $archive_name; - - /** - * @var object An instance of Archive_Tar - */ - - protected $tar; - + /** * @var string The temporary path to the TAR archive */ - protected $temp_path; - + /** * @var string Where the TAR archive will be saved */ - protected $save_path; + + /** + * @var string The phar alias + */ + protected $alias; /** * @var boolean Whether or not the archive should be compressed */ - protected $compress = false; - + /** * @var boolean Whether or not a file has been added to the archive */ - protected $modified = false; - + + /** + * Used to construct the internal manifest, or listing of files/directories + * + * @var array + */ + protected $manifest = array(); + /** * PHP_Archive Constructor - * + * * @param string $init_file Init file (file called by default upon PHAR execution) * @param boolean $compress Whether to compress the files or not (will cause slowdown!) * @param mixed $allow_direct_access The file extension to prepend to requests for files @@ -87,31 +51,26 @@ * any file but the init file (you should handle other * pages in your init file code). If you set it to True, * then the exact PATH_INFO is used - * @return void + * @param string $alias alias name like "go-pear.phar" to be used for opening + * files from this phar */ public function __construct($init_file = 'index.php', $compress = false, - $allow_direct_access = false) + $allow_direct_access = false, $alias = null) { $this->compress = $compress; - $this->temp_path = System::mktemp('phr'); - $tar = new Archive_Tar($this->temp_path); + $this->temp_path = System::mktemp(array('-d', 'phr')); $contents = trim(str_replace(array('<?php', '?>'), array('', ''), file_get_contents(dirname(dirname(__FILE__)) . DIRECTORY_SEPARATOR . 'Archive.php'))); // make sure .phars added to CVS don't get checksum errors because of CVS tags $contents = str_replace('* @version $Id', '* @version Id', $contents); $unpack_code = <<<PHP - - - - - - - - - +<?php #PHP_ARCHIVE_HEADER-@API-VER@ error_reporting(E_ALL); if (version_compare(str_replace('-dev', '', phpversion()), '5.1.0b1', '<')) { -die('Error: .phar files require PHP 5.1 or newer'); +die('Error: .phar files require PHP 5.1.0b1 or newer'); +} +if (function_exists('mb_internal_encoding')) { + mb_internal_encoding('ASCII'); } if (!class_exists('PHP_Archive')) { $contents @@ -126,6 +85,11 @@ } PHP; + $this->alias = $alias; + $alias = $this->alias ? $this->alias : '@ALIAS@'; + $unpack_code .= 'PHP_Archive::mapPhar(__FILE__, "' . addslashes($alias) . '", ' . + ($compress ? 'true' : 'false') . ", __COMPILER_HALT_OFFSET__ + strlen(' ?> +'));"; if (!$allow_direct_access) { $unpack_code .= <<<PHP @@ -154,11 +118,7 @@ <?php __HALT_COMPILER(); ?> PHP; - $tar->addString('<?php #PHP_ARCHIVE_HEADER-0.5.0.php', $unpack_code); - - $this->code = $unpack_code; - - $this->tar = $tar; + file_put_contents($this->temp_path . DIRECTORY_SEPARATOR . 'loader.php', $unpack_code); } /** @@ -184,22 +144,35 @@ public function addString($file_contents, $save_path, $magicrequire = false) { + $save_path = PHP_Archive::processFile($save_path); if ($magicrequire) { $file_contents = str_replace("require_once '", "require_once 'phar://$magicrequire/", $file_contents); $file_contents = str_replace("include_once '", "include_once 'phar://$magicrequire/", $file_contents); } - if ($this->compress) { - $file_contents = '1' . - pack("C1C1C1C1VC1C1", 0x1f, 0x8b, 8, 0, time(), 2, 0xFF) . - gzdeflate($file_contents, 9) . - pack("VV",crc32($file_contents),strlen($file_contents)); - } else { - $file_contents = '0' . $file_contents; + if (!file_exists($this->temp_path . DIRECTORY_SEPARATOR . 'contents')) { + mkdir($this->temp_path . DIRECTORY_SEPARATOR . 'contents'); } - clearstatcache(); // a newly created archive could be erased if this is not performed - return $this->tar->addString($save_path, $file_contents); + $size = strlen($file_contents); + // always use gz header/footer to help ensure validity of file + $file_contents = + pack("VV",crc32($file_contents),strlen($file_contents)) . + ($this->compress ? gzdeflate($file_contents, 9) : $file_contents); + System::mkdir(array('-p', dirname($this->temp_path . DIRECTORY_SEPARATOR . 'contents' . + DIRECTORY_SEPARATOR . $save_path))); + if (file_exists($this->temp_path . DIRECTORY_SEPARATOR . 'contents' . + DIRECTORY_SEPARATOR . $save_path)) { + die('ERROR: path "' . $save_path . '" already exists'); + } + file_put_contents($this->temp_path . DIRECTORY_SEPARATOR . 'contents' . + DIRECTORY_SEPARATOR . $save_path, $file_contents); + $this->manifest[$save_path] = + array( + 'tempfile' => $this->temp_path . DIRECTORY_SEPARATOR . 'contents' . + DIRECTORY_SEPARATOR . $save_path, + 'originalsize' => $size, + 'actualsize' => strlen($file_contents)); } /** @@ -406,15 +379,16 @@ $list = $this->dirList($dir); return $this->addArray($list, $magicrequire); } - + /** - * Add an array of files to the archive + * add an array of files to the archive * - * @param array $files This is an associative array of the format - * 'file_to_archive' => 'save_path_in_archive' - * @return boolean + * @param unknown_type $files + * @param bool $magicrequire determines whether to attempt to replace all + * calls to require or include with internal + * phar includes + * @return unknown */ - public function addArray($files, $magicrequire = false) { if (!is_array($files) || empty($files)) { @@ -425,19 +399,77 @@ } return !in_array(false, $returns); } - + /** - * Save the PHAR Archive + * Construct the .phar and save it * - * @param string $file_path The file path of where to save the file - * @return void + * @param string $file_path + * @return bool success of operation */ - - public function savePhar($file_path = null) + public function savePhar($file_path) { - @unlink($file_path); - copy($this->temp_path, $file_path); + uksort($this->manifest, 'strnatcasecmp'); + $newfile = fopen($file_path, 'wb'); + if (!$newfile) { + return false; + } + $loader = fopen($this->temp_path . DIRECTORY_SEPARATOR . 'loader.php', 'rb'); + if (isset($this->alias)) { + stream_copy_to_stream($loader, $newfile); + fclose($loader); + } else { + fclose($loader); + $loader = file_get_contents($this->temp_path . DIRECTORY_SEPARATOR . 'loader.php'); + $loader = str_replace('@ALIAS@', addslashes(basename($file_path)), $loader); + fwrite($newfile, $loader); + } + // relative offset from end of manifest + $offset = 0; + $manifest = array(); + // create the manifest + foreach ($this->manifest as $savepath => $info) { + $size = $info['originalsize']; + $manifest[$savepath] = array( + $size, // original size = 0 + time(), // save time = 1 + $offset, // offset from start of files = 2 + $info['actualsize']); // actual size in the .phar = 3 + $offset += $info['actualsize']; + } + $manifest = $this->serializeManifest($manifest); + fwrite($newfile, $manifest); + // save each file + foreach ($this->manifest as $savepath => $info) { + $file = fopen($info['tempfile'], 'rb'); + stream_copy_to_stream($file, $newfile); + fclose($file); + } + fclose($newfile); + return true; + } + + /** + * serialize the manifest in a C-friendly way + * + * @param array $manifest An array like so: + * <code> + * $manifest[] = array( + * $savepath, + * $size, // original size = 0 + * time(), // save time = 1 + * $offset, // offset from start of files = 2 + * $info['actualsize']); // actual size in the .phar = 3 + * </code> + */ + function serializeManifest($manifest) + { + $ret = ''; + foreach ($manifest as $savepath => $info) { + $ret .= pack('V', strlen($savepath)) . $savepath . call_user_func_array('pack', + array_merge(array('VVVV'), $info)); + } + // save the size of the manifest + return pack('VV', strlen($ret) + 4, count($manifest)) . $ret; } - } ?> \ No newline at end of file http://cvs.php.net/diff.php/pear/PHP_Archive/tests/PEAR.phar?r1=1.6&r2=1.7&ty=u Index: pear/PHP_Archive/tests/PEAR.phar http://cvs.php.net/diff.php/pear/PHP_Archive/tests/eof.phpt?r1=1.2&r2=1.3&ty=u Index: pear/PHP_Archive/tests/eof.phpt diff -u pear/PHP_Archive/tests/eof.phpt:1.2 pear/PHP_Archive/tests/eof.phpt:1.3 --- pear/PHP_Archive/tests/eof.phpt:1.2 Sat Jul 23 14:00:55 2005 +++ pear/PHP_Archive/tests/eof.phpt Wed Nov 30 00:25:06 2005 @@ -2,7 +2,7 @@ Test seeking a .phar stream --SKIPIF-- <?php -if (version_compare(phpversion(), '5.0.0', '<')) { +if (version_compare(phpversion(), '5.1.0b1', '<')) { echo 'skip php5-only test'; } ?> @@ -10,10 +10,10 @@ <?php require_once dirname(__FILE__) . DIRECTORY_SEPARATOR . 'phpt_test.php.inc'; require_once 'PHP/Archive.php'; -require dirname(__FILE__) . DIRECTORY_SEPARATOR . 'cachestat' . DIRECTORY_SEPARATOR . - 'cachestat.phar'; +require dirname(__FILE__) . DIRECTORY_SEPARATOR . 'longfilename' . DIRECTORY_SEPARATOR . + 'longphar.phar'; $phpunit = new PEAR_PHPTest(true); -$fp = fopen('phar://cachestat.phar/test1.php', 'r'); +$fp = fopen('phar://longphar.phar/testtesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttest.php', 'r'); var_dump(feof($fp), ftell($fp)); fseek($fp, 10000); var_dump(feof($fp), ftell($fp)); @@ -21,7 +21,7 @@ echo 'tests done'; ?> --EXPECT-- -phar://cachestat.phar/test1.phpstring(5) "hello" +phar://longphar.phar/testtesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttest.phpstring(5) "hello" bool(false) int(0) bool(true) http://cvs.php.net/diff.php/pear/PHP_Archive/tests/filenotfound.phpt?r1=1.1&r2=1.2&ty=u Index: pear/PHP_Archive/tests/filenotfound.phpt diff -u pear/PHP_Archive/tests/filenotfound.phpt:1.1 pear/PHP_Archive/tests/filenotfound.phpt:1.2 --- pear/PHP_Archive/tests/filenotfound.phpt:1.1 Wed Apr 13 23:19:44 2005 +++ pear/PHP_Archive/tests/filenotfound.phpt Wed Nov 30 00:25:06 2005 @@ -17,5 +17,5 @@ echo 'tests done'; ?> --EXPECT-- -Error: "test2.php" not found in phar "cachestat.phar" +Error: "test2.php" is not a file in phar "filenotfound.phar" tests done \ No newline at end of file http://cvs.php.net/diff.php/pear/PHP_Archive/tests/makepearphar.php.inc?r1=1.7&r2=1.8&ty=u Index: pear/PHP_Archive/tests/makepearphar.php.inc diff -u pear/PHP_Archive/tests/makepearphar.php.inc:1.7 pear/PHP_Archive/tests/makepearphar.php.inc:1.8 --- pear/PHP_Archive/tests/makepearphar.php.inc:1.7 Tue May 3 14:37:27 2005 +++ pear/PHP_Archive/tests/makepearphar.php.inc Wed Nov 30 00:25:06 2005 @@ -1,6 +1,5 @@ <?php -$peardir = 'C:\devel\pear_with_channels'; -$xmlrpcdir = 'C:\php5\pear\XML'; +$peardir = 'C:\development\pear-core'; require_once 'PEAR/PackageFile.php'; require_once 'PEAR/Config.php'; @@ -15,6 +14,20 @@ $commandcontents = str_replace('@PEARVER@', $pearver, $commandcontents); $creator->addString($commandcontents, 'index.php'); +$commandcontents = file_get_contents($peardir . DIRECTORY_SEPARATOR . 'OS' . + DIRECTORY_SEPARATOR . 'Guess.php'); +$commandcontents = str_replace( + array( + "include_once \"", + "@package_version@", + ), + array( + "include_once \"phar://go-pear.phar/", + $pearver, + ), + $commandcontents); +$creator->addString($commandcontents, 'OS/Guess.php'); + $commandcontents = file_get_contents($peardir . DIRECTORY_SEPARATOR . 'PEAR' . DIRECTORY_SEPARATOR . 'Command.php'); $commandcontents = str_replace( @@ -35,11 +48,13 @@ array( "require_once '", "include_once '", + 'if (file_exists($path . "/PEAR/Task/$task.php")) {', "include_once \"PEAR/Task/\$task.php", ), array( "require_once 'phar://PEAR.phar/", "include_once 'phar://PEAR.phar/", + 'if (true) {', // we're self-contained, so this should work "include_once \"phar://PEAR.phar/PEAR/Task/\$task.php", ), $commandcontents); @@ -60,23 +75,24 @@ $creator->addString($commandcontents, 'PEAR/Frontend.php'); $commandcontents = file_get_contents($peardir . DIRECTORY_SEPARATOR . 'PEAR' . - DIRECTORY_SEPARATOR . 'Command' . DIRECTORY_SEPARATOR . 'Package.php'); + DIRECTORY_SEPARATOR . 'Downloader' . DIRECTORY_SEPARATOR . 'Package.php'); $commandcontents = str_replace( array( "require_once '", "include_once '", - "@DATA-DIR@", + "@PEAR-VER@", ), array( "require_once 'phar://PEAR.phar/", "include_once 'phar://PEAR.phar/", - "phar://PEAR.phar", + $pearver, ), $commandcontents); -$creator->addString($commandcontents, 'PEAR/Command/Package.php'); +$creator->addString($commandcontents, 'PEAR/Downloader/Package.php'); $commandcontents = file_get_contents($peardir . DIRECTORY_SEPARATOR . 'PEAR' . - DIRECTORY_SEPARATOR . 'Downloader' . DIRECTORY_SEPARATOR . 'Package.php'); + DIRECTORY_SEPARATOR . 'PackageFile' . DIRECTORY_SEPARATOR . 'v2' . + DIRECTORY_SEPARATOR . 'Validator.php'); $commandcontents = str_replace( array( "require_once '", @@ -89,16 +105,16 @@ $pearver, ), $commandcontents); -$creator->addString($commandcontents, 'PEAR/Downloader/Package.php'); +$creator->addString($commandcontents, 'PEAR/PackageFile/v2/Validator.php'); $commandcontents = file_get_contents($peardir . DIRECTORY_SEPARATOR . 'PEAR' . - DIRECTORY_SEPARATOR . 'PackageFile' . DIRECTORY_SEPARATOR . 'Generator' . - DIRECTORY_SEPARATOR . 'v1.php'); + DIRECTORY_SEPARATOR . 'PackageFile' . DIRECTORY_SEPARATOR . 'v2' . + DIRECTORY_SEPARATOR . 'rw.php'); $commandcontents = str_replace( array( "require_once '", "include_once '", - "@PEAR-VER@", + "@package_version@", ), array( "require_once 'phar://PEAR.phar/", @@ -106,11 +122,11 @@ $pearver, ), $commandcontents); -$creator->addString($commandcontents, 'PEAR/PackageFile/Generator/v1.php'); +$creator->addString($commandcontents, 'PEAR/PackageFile/v2/rw.php'); $commandcontents = file_get_contents($peardir . DIRECTORY_SEPARATOR . 'PEAR' . DIRECTORY_SEPARATOR . 'PackageFile' . DIRECTORY_SEPARATOR . 'Generator' . - DIRECTORY_SEPARATOR . 'v2.php'); + DIRECTORY_SEPARATOR . 'v1.php'); $commandcontents = str_replace( array( "require_once '", @@ -123,10 +139,11 @@ $pearver, ), $commandcontents); -$creator->addString($commandcontents, 'PEAR/PackageFile/Generator/v2.php'); +$creator->addString($commandcontents, 'PEAR/PackageFile/Generator/v1.php'); $commandcontents = file_get_contents($peardir . DIRECTORY_SEPARATOR . 'PEAR' . - DIRECTORY_SEPARATOR . 'Builder.php'); + DIRECTORY_SEPARATOR . 'PackageFile' . DIRECTORY_SEPARATOR . 'Generator' . + DIRECTORY_SEPARATOR . 'v2.php'); $commandcontents = str_replace( array( "require_once '", @@ -139,7 +156,7 @@ $pearver, ), $commandcontents); -$creator->addString($commandcontents, 'PEAR/Builder.php'); +$creator->addString($commandcontents, 'PEAR/PackageFile/Generator/v2.php'); $commandcontents = file_get_contents($peardir . DIRECTORY_SEPARATOR . 'PEAR' . DIRECTORY_SEPARATOR . 'Dependency2.php'); @@ -157,6 +174,20 @@ $commandcontents); $creator->addString($commandcontents, 'PEAR/Dependency2.php'); +$commandcontents = file_get_contents($peardir . DIRECTORY_SEPARATOR . 'OS' . + DIRECTORY_SEPARATOR . 'Guess.php'); +$commandcontents = str_replace( + array( + "include_once \"", + "@package_version@", + ), + array( + "include_once \"phar://PEAR.phar/", + $pearver, + ), + $commandcontents); +$creator->addString($commandcontents, 'OS/Guess.php'); + $commandcontents = file_get_contents($peardir . DIRECTORY_SEPARATOR . 'PEAR' . DIRECTORY_SEPARATOR . 'PackageFile.php'); $commandcontents = str_replace( @@ -173,12 +204,12 @@ $commandcontents); $creator->addString($commandcontents, 'PEAR/PackageFile.php'); -$creator->addFile($xmlrpcdir . DIRECTORY_SEPARATOR . 'RPC.php', 'XML/RPC.php', true); $creator->addFile($peardir . DIRECTORY_SEPARATOR . 'template.spec', 'PEAR/template.spec'); $creator->addDir($peardir, array('tests/', 'scripts/', 'go-pear-list.php', 'install-pear.php', + '*OS/Guess.php', '*PEAR/Autoloader.php', '*PEAR/Builder.php', '*PEAR/Dependency.php', @@ -186,7 +217,6 @@ '*PEAR/Dependency2.php', '*PEAR/PackageFile/Generator/v1.php', '*PEAR/PackageFile/Generator/v2.php', - '*PEAR/newRemote.php', '*PEAR/ErrorStack5.php', '*PEAR/Exception.php', '*PEAR/FTP.php', @@ -205,6 +235,6 @@ '*PEAR/Task/Replace/rw.php', '*PEAR/Task/Unixeol/rw.php', '*PEAR/Task/Windowseol/rw.php', - '*PEAR/Frontend.php'), array('*.php'), 'PEAR.phar'); + '*PEAR/Frontend.php'), array('*.php','*.xml'), 'PEAR.phar'); $creator->savePhar(dirname(__FILE__) . DIRECTORY_SEPARATOR . 'PEAR.phar'); ?> \ No newline at end of file http://cvs.php.net/diff.php/pear/PHP_Archive/tests/normalstat.phpt?r1=1.1&r2=1.2&ty=u Index: pear/PHP_Archive/tests/normalstat.phpt diff -u pear/PHP_Archive/tests/normalstat.phpt:1.1 pear/PHP_Archive/tests/normalstat.phpt:1.2 --- pear/PHP_Archive/tests/normalstat.phpt:1.1 Tue May 3 14:34:28 2005 +++ pear/PHP_Archive/tests/normalstat.phpt Wed Nov 30 00:25:06 2005 @@ -10,9 +10,10 @@ <?php require_once dirname(__FILE__) . DIRECTORY_SEPARATOR . 'phpt_test.php.inc'; require_once 'PHP/Archive.php'; -require dirname(__FILE__) . DIRECTORY_SEPARATOR . 'cachestat' . DIRECTORY_SEPARATOR . - 'cachestat.phar'; +require dirname(__FILE__) . DIRECTORY_SEPARATOR . 'longfilename' . DIRECTORY_SEPARATOR . + 'longphar.phar'; $phpunit = new PEAR_PHPTest(true); +$x = stat('phar://longphar.phar/testtesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttest.php'); $phpunit->assertEquals(array ( 0 => 0, 1 => 0, @@ -22,9 +23,9 @@ 5 => 0, 6 => 0, 7 => 47, - 8 => 0, - 9 => 0, - 10 => 0, + 8 => $x[8], + 9 => $x[8], + 10 => $x[8], 11 => -1, 12 => -1, 'dev' => 0, @@ -35,14 +36,14 @@ 'gid' => 0, 'rdev' => 0, 'size' => 47, - 'atime' => 0, - 'mtime' => 0, - 'ctime' => 0, + 'atime' => $x[8], + 'mtime' => $x[8], + 'ctime' => $x[8], 'blksize' => -1, 'blocks' => -1, -), stat('phar://cachestat.phar/test1.php'), 'stat'); +), $x, 'stat'); echo 'tests done'; ?> --EXPECT-- -phar://cachestat.phar/test1.phpstring(5) "hello" +phar://longphar.phar/testtesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttest.phpstring(5) "hello" tests done \ No newline at end of file http://cvs.php.net/diff.php/pear/PHP_Archive/tests/pearindex.php?r1=1.6&r2=1.7&ty=u Index: pear/PHP_Archive/tests/pearindex.php diff -u pear/PHP_Archive/tests/pearindex.php:1.6 pear/PHP_Archive/tests/pearindex.php:1.7 --- pear/PHP_Archive/tests/pearindex.php:1.6 Mon May 2 18:23:45 2005 +++ pear/PHP_Archive/tests/pearindex.php Wed Nov 30 00:25:06 2005 @@ -19,7 +19,6 @@ print "$errortype: $m in $file on $line\n"; } //set_error_handler('testerr'); -PHP_Archive::cacheStat('PEAR.phar'); // {{{ usage() function usage($error = null, $helpsubject = null) @@ -159,6 +158,22 @@ } $ui = &PEAR_Command::getFrontendObject(); $config = &PEAR_Config::singleton($pear_user_config, $pear_system_config); +if (PEAR::isError($config)) { + $_file = ''; + if ($pear_user_config !== false) { + $_file .= $pear_user_config; + } + if ($pear_system_config !== false) { + $_file .= '/' . $pear_system_config; + } + if ($_file == '/') { + $_file = 'The default config file'; + } + $config->getMessage(); + $ui->outputData("ERROR: $_file is not a valid config file or is corrupted."); + // We stop, we have no idea where we are :) + exit(); +} $ui->setConfig($config); PEAR::setErrorHandling(PEAR_ERROR_CALLBACK, array($ui, "displayFatalError")); if (ini_get('safe_mode')) { http://cvs.php.net/diff.php/pear/PHP_Archive/tests/phar.log?r1=1.1&r2=1.2&ty=u Index: pear/PHP_Archive/tests/phar.log http://cvs.php.net/diff.php/pear/PHP_Archive/tests/require_once.phpt?r1=1.3&r2=1.4&ty=u Index: pear/PHP_Archive/tests/require_once.phpt diff -u pear/PHP_Archive/tests/require_once.phpt:1.3 pear/PHP_Archive/tests/require_once.phpt:1.4 --- pear/PHP_Archive/tests/require_once.phpt:1.3 Sun Jul 24 15:38:55 2005 +++ pear/PHP_Archive/tests/require_once.phpt Wed Nov 30 00:25:06 2005 @@ -12,5 +12,4 @@ ?> --EXPECTF-- phar://require_once.phar/indexhooha.php -Fatal error: Error: "nosuchfile.php" not found in phar "require_once.phar" in %s on line %s -PHP Fatal error: Error: "nosuchfile.php" not found in phar "require_once.phar" in %s on line %s \ No newline at end of file +Fatal error: Error: "nosuchfile.php" is not a file in phar "require_once.phar" in %s on line %s \ No newline at end of file http://cvs.php.net/diff.php/pear/PHP_Archive/tests/seek.phpt?r1=1.1&r2=1.2&ty=u Index: pear/PHP_Archive/tests/seek.phpt diff -u pear/PHP_Archive/tests/seek.phpt:1.1 pear/PHP_Archive/tests/seek.phpt:1.2 --- pear/PHP_Archive/tests/seek.phpt:1.1 Tue May 3 14:34:28 2005 +++ pear/PHP_Archive/tests/seek.phpt Wed Nov 30 00:25:06 2005 @@ -10,10 +10,10 @@ <?php require_once dirname(__FILE__) . DIRECTORY_SEPARATOR . 'phpt_test.php.inc'; require_once 'PHP/Archive.php'; -require dirname(__FILE__) . DIRECTORY_SEPARATOR . 'cachestat' . DIRECTORY_SEPARATOR . - 'cachestat.phar'; +require dirname(__FILE__) . DIRECTORY_SEPARATOR . 'longfilename' . DIRECTORY_SEPARATOR . + 'longphar.phar'; $phpunit = new PEAR_PHPTest(true); -$fp = fopen('phar://cachestat.phar/test1.php', 'r'); +$fp = fopen('phar://longphar.phar/testtesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttest.php', 'r'); var_dump(ftell($fp)); var_dump(fread($fp, 2)); fseek($fp, 3); @@ -36,7 +36,7 @@ echo 'tests done'; ?> --EXPECT-- -phar://cachestat.phar/test1.phpstring(5) "hello" +phar://longphar.phar/testtesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttest.phpstring(5) "hello" int(0) string(2) "<?" int(3) http://cvs.php.net/diff.php/pear/PHP_Archive/tests/streamstat.phpt?r1=1.1&r2=1.2&ty=u Index: pear/PHP_Archive/tests/streamstat.phpt diff -u pear/PHP_Archive/tests/streamstat.phpt:1.1 pear/PHP_Archive/tests/streamstat.phpt:1.2 --- pear/PHP_Archive/tests/streamstat.phpt:1.1 Tue May 3 14:34:28 2005 +++ pear/PHP_Archive/tests/streamstat.phpt Wed Nov 30 00:25:06 2005 @@ -10,10 +10,11 @@ <?php require_once dirname(__FILE__) . DIRECTORY_SEPARATOR . 'phpt_test.php.inc'; require_once 'PHP/Archive.php'; -require dirname(__FILE__) . DIRECTORY_SEPARATOR . 'cachestat' . DIRECTORY_SEPARATOR . - 'cachestat.phar'; -$fp = fopen('phar://cachestat.phar/test1.php', 'r'); +require dirname(__FILE__) . DIRECTORY_SEPARATOR . 'longfilename' . DIRECTORY_SEPARATOR . + 'longphar.phar'; +$fp = fopen('phar://longphar.phar/testtesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttest.php', 'r'); $phpunit = new PEAR_PHPTest(true); +$x = fstat($fp); $phpunit->assertEquals(array ( 0 => 0, 1 => 0, @@ -23,9 +24,9 @@ 5 => 0, 6 => 0, 7 => 47, - 8 => 0, - 9 => 0, - 10 => 0, + 8 => $x[8], + 9 => $x[8], + 10 => $x[8], 11 => -1, 12 => -1, 'dev' => 0, @@ -36,15 +37,15 @@ 'gid' => 0, 'rdev' => 0, 'size' => 47, - 'atime' => 0, - 'mtime' => 0, - 'ctime' => 0, + 'atime' => $x[8], + 'mtime' => $x[8], + 'ctime' => $x[8], 'blksize' => -1, 'blocks' => -1, -), fstat($fp), 'stat'); +), $x, 'stat'); fclose($fp); echo 'tests done'; ?> --EXPECT-- -phar://cachestat.phar/test1.phpstring(5) "hello" +phar://longphar.phar/testtesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttest.phpstring(5) "hello" tests done \ No newline at end of file http://cvs.php.net/diff.php/pear/PHP_Archive/tests/filenotfound/filenotfound.phar?r1=1.3&r2=1.4&ty=u Index: pear/PHP_Archive/tests/filenotfound/filenotfound.phar http://cvs.php.net/diff.php/pear/PHP_Archive/tests/longfilename/longphar.phar?r1=1.5&r2=1.6&ty=u Index: pear/PHP_Archive/tests/longfilename/longphar.phar http://cvs.php.net/diff.php/pear/PHP_Archive/tests/opendir/opendir.phar?r1=1.4&r2=1.5&ty=u Index: pear/PHP_Archive/tests/opendir/opendir.phar http://cvs.php.net/diff.php/pear/PHP_Archive/tests/require_once/require_once.phar?r1=1.3&r2=1.4&ty=u Index: pear/PHP_Archive/tests/require_once/require_once.phar