]> granicus.if.org Git - php/commitdiff
work on Windows support (use Tar class and System class)
authorTomas V.V.Cox <cox@php.net>
Sun, 7 Oct 2001 20:16:41 +0000 (20:16 +0000)
committerTomas V.V.Cox <cox@php.net>
Sun, 7 Oct 2001 20:16:41 +0000 (20:16 +0000)
pear/PEAR/Installer.php
pear/PEAR/Packager.php

index 01ff470cd370e080b6aa35bddc92c87f747c1662..3e70b13c868c41ff98ecb7b3f0ebe7ecd8a641ed 100644 (file)
 //
 // $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>
@@ -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.");
         }
 
index 6a4f10c6e8332bdba08cc7604bd2c27635f9b194..acc116898bd7f71ef623830f305ce0178869e2bd 100644 (file)
@@ -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 <ssb@fast.no>
@@ -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);
             }