//
// $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 <ssb@fast.no>
{
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();
$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.");
}
*
* 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 <ssb@fast.no>
$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);
}