]> granicus.if.org Git - php/commitdiff
- Rewrote infoFromTgzFile() (Stig, no more "pedantic" :-)
authorTomas V.V.Cox <cox@php.net>
Fri, 28 Dec 2001 19:27:08 +0000 (19:27 +0000)
committerTomas V.V.Cox <cox@php.net>
Fri, 28 Dec 2001 19:27:08 +0000 (19:27 +0000)
- Added <description> tag for package.xml
- Temporal fix arround php bug #14744 and temp files cleaning

pear/PEAR/Common.php

index 25813df561d29ba84a06f610ae598be411e64039..e38e549d15eff19bfb89385a844984ce359a58aa 100644 (file)
@@ -67,6 +67,8 @@ class PEAR_Common extends PEAR
 
     function PEAR_Common()
     {
+        $GLOBALS['_PEAR_Common_tempfiles'] = array();
+        $this->_tempfiles =& $GLOBALS['_PEAR_Common_tempfiles'];
         $this->PEAR();
     }
 
@@ -75,8 +77,11 @@ class PEAR_Common extends PEAR
 
     function _PEAR_Common()
     {
-        while (is_array($this->_tempfiles) &&
-               $file = array_shift($this->_tempfiles))
+        // doesn't work due to bug #14744
+        //$tempfiles = $this->_tempfiles;
+        $tempfiles =& $GLOBALS['_PEAR_Common_tempfiles'];
+        while (is_array($tempfiles) &&
+               $file = array_shift($tempfiles))
         {
             if (@is_dir($file)) {
                 System::rm("-rf $file");
@@ -211,6 +216,9 @@ class PEAR_Common extends PEAR
             case 'summary':
                 $this->pkginfo['summary'] = $data;
                 break;
+            case 'description':
+                $this->pkginfo['description'] = $data;
+                break;
             case 'user':
                 $this->current_maintainer['handle'] = $data;
                 break;
@@ -387,33 +395,32 @@ class PEAR_Common extends PEAR
 
     /**
     * Returns info from a tgz pear package
-    * (experimental)
     */
-    function infoFromTgzFile($file, $pedantic = true)
+    function infoFromTgzFile($file)
     {
-        if ($pedantic) {
-            // XXX Fixme: Only allows file in the current dir
-            $file = basename($file);
-        }
         if (!@is_file($file)) {
-            return $this->raiseError('no tar file supplied');
-        }
-        // Assume the decompressed dir name
-        if ($pedantic && ($pos = strrpos($file, '.')) === false) {
-            return $this->raiseError('file doesn\'t follow the package name convention');
+            return $this->raiseError('tgz :: could not open file');
         }
-        $pkgdir = substr($file, 0, $pos);
-        $xml = $pkgdir . DIRECTORY_SEPARATOR . 'package.xml';
-
         $tar = new Archive_Tar($file, true);
-        if (!$tar->extractList($xml)) {
-            return $this->raiseError('could not extract the package.xml file');
+        $content = $tar->listContent();
+        if (!is_array($content)) {
+            return $this->raiseError('tgz :: could not get contents of package');
         }
-        $info = $this->infoFromDescriptionFile($xml);
-        unlink($xml);
-        return $info;
-    }
+        $xml = null;
+        foreach ($content as $file) {
+            $name = $file['filename'];
+            if (ereg('^.*/package.xml$', $name, $match)) {
+                $xml = $match[0];
+            }
+        }
+        $tmpdir = System::mkTemp('-d pear');
+        $this->addTempFile($tmpdir);
+        if (!$xml || !$tar->extractList($xml, $tmpdir)) {
+            return $this->raiseError('tgz :: could not extract the package.xml file');
+        }
+        return $this->infoFromDescriptionFile("$tmpdir/$xml");
 
     // }}}
+    }
 }
 ?>
\ No newline at end of file