From: Tomas V.V.Cox Date: Sun, 7 Oct 2001 20:16:41 +0000 (+0000) Subject: work on Windows support (use Tar class and System class) X-Git-Tag: PRE_PARAMETER_PARSING_API~41 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=5b0e54088260814b416d5196fd20c226f17f4799;p=php work on Windows support (use Tar class and System class) --- diff --git a/pear/PEAR/Installer.php b/pear/PEAR/Installer.php index 01ff470cd3..3e70b13c86 100644 --- a/pear/PEAR/Installer.php +++ b/pear/PEAR/Installer.php @@ -20,14 +20,15 @@ // // $Id$ -require_once "PEAR/Common.php"; +require_once 'PEAR/Common.php'; /** * Administration class used to install PEAR packages and maintain the * installed package database. * * TODO: - * - maintain file perms (look at umask or fileperms+chmod), ideas are welcome + * - finish and test Windows support + * - kill FIXME's * * @since PHP 4.0.2 * @author Stig Bakken @@ -81,7 +82,7 @@ class PEAR_Installer extends PEAR_Common { chdir($this->pwd); if ($this->tmpdir && is_dir($this->tmpdir)) { - system("rm -rf $this->tmpdir"); // XXX FIXME Windows + System::rm("-rf $this->tmpdir"); } $this->tmpdir = null; $this->_PEAR_Common(); @@ -156,26 +157,20 @@ class PEAR_Installer extends PEAR_Common $this->log(2, '+ tmp dir created at ' . $this->tmpdir); } $this->addTempFile($this->tmpdir); - if (!chdir($this->tmpdir)) { - return $this->raiseError("Unable to chdir to $this->tmpdir."); - } - // XXX FIXME Windows - $fp = popen("gzip -dc $pkgfile | tar -xvf -", 'r'); - $this->log(2, "+ launched command: gzip -dc $pkgfile | tar -xvf -"); - if (!is_resource($fp)) { - return $this->raiseError("Unable to examine $pkgfile (gzip or tar failed)"); + + $tar = new Archive_Tar($pkgfile, true); + if (!$tar->extract($this->tmpdir)) { + return $this->raiseError("Unable to unpack $pkgfile"); } - while ($line = fgets($fp, 4096)) { - $line = rtrim($line); - if (preg_match('!^[^/]+/package.xml$!', $line)) { - if (isset($descfile)) { - return $this->raiseError("Invalid package: multiple package.xml files at depth one!"); - } - $descfile = $line; - } + $file = basename($pkgfile); + // Assume the decompressed dir name + if (($pos = strrpos($file, '.')) === false) { + return $this->raiseError('package doesn\'t follow the package name convention'); } - pclose($fp); - if (!isset($descfile) || !is_file($descfile)) { + $pkgdir = substr($file, 0, $pos); + $descfile = $this->tmpdir . DIRECTORY_SEPARATOR . $pkgdir . DIRECTORY_SEPARATOR . 'package.xml'; + + if (!is_file($descfile)) { return $this->raiseError("No package.xml file after extracting the archive."); } diff --git a/pear/PEAR/Packager.php b/pear/PEAR/Packager.php index 6a4f10c6e8..acc116898b 100644 --- a/pear/PEAR/Packager.php +++ b/pear/PEAR/Packager.php @@ -27,7 +27,7 @@ require_once 'PEAR/Common.php'; * * TODO: * - add an extra param the dir where to place the created package - * - preserve file permissions (solve umask in copy problem) + * - finish and test Windows support * * @since PHP 4.0.2 * @author Stig Bakken @@ -104,7 +104,7 @@ class PEAR_Packager extends PEAR_Common $file = array_shift($this->_tempfiles)) { if (is_dir($file)) { - system("rm -rf $file"); // XXX FIXME Windows + System::rm("-rf $file"); // XXX FIXME Windows } else { unlink($file); }