From: Tomas V.V.Cox Date: Fri, 28 Sep 2001 00:55:16 +0000 (+0000) Subject: implemented infoFromTgzFile() X-Git-Tag: php4~29 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=15ac0567f9f551168c3dc1eefbc479fd317686ee;p=php implemented infoFromTgzFile() --- diff --git a/pear/PEAR/Common.php b/pear/PEAR/Common.php index d6b02cb6b4..5680f55acf 100644 --- a/pear/PEAR/Common.php +++ b/pear/PEAR/Common.php @@ -21,6 +21,7 @@ // $Id$ require_once 'PEAR.php'; +require_once 'Archive/Tar.php'; /** * TODO: @@ -372,10 +373,32 @@ class PEAR_Common extends PEAR */ function infoFromTgzFile($file) { - // untar in temp - // chdir($tmp); - //return $this->infoFromDescriptionFile('package.xml'); - // clean temp + $file = basename($file); // XXX Fixme: Only allows file in the current dir + if (!@is_file($file)) { + return $this->raiseError('no tar file supplied'); + } + $tar = new Archive_Tar($file, true); + // XXX Fixme Windows + $tmpdir = '/tmp' . DIRECTORY_SEPARATOR . $file; + if (file_exists($tmpdir)) { + return $this->raiseError('Tmpdir: ' . $tmpdir .' already exists', + null, PEAR_ERROR_TRIGGER, E_USER_ERROR); + } + if (!mkdir($tmpdir, 0755)) { + return $this->raiseError("Unable to create temporary directory $tmpdir.", + null, PEAR_ERROR_TRIGGER, E_USER_ERROR); + } + $tar->extract($tmpdir); + // Assume the decompressed dir name + if (($pos = strrpos($file, '.')) === false) { + return $this->raiseError('file doesn\'t follow the package name convention'); + } + $pkgdir = substr($file, 0, $pos); + + $xml = $tmpdir . DIRECTORY_SEPARATOR . $pkgdir . DIRECTORY_SEPARATOR .'package.xml'; + $info = $this->infoFromDescriptionFile($xml); + system("rm -rf $tmpdir"); // XXX FIXME Windows + return $info; } } ?> \ No newline at end of file