forked from php/php-src
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Allow relative directory package calls (for ex: pear install packs/Pear_DB-1.1.tgz)
- Loading branch information
Showing
1 changed file
with
27 additions
and
36 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -29,7 +29,6 @@ | |
* - move the package db handler methods to its own class. | ||
* - install also the package.xml? | ||
* - remove unneeded code | ||
* - only decrompress pack once | ||
* | ||
* @since PHP 4.0.2 | ||
* @author Stig Bakken <[email protected]> | ||
|
@@ -252,53 +251,44 @@ function install($pkgfile) | |
fclose($wp); | ||
$this->log(1, '...done: ' . number_format($bytes, 0, '', ',') . ' bytes'); | ||
} | ||
// Test for package.xml ------------------------------------------- | ||
// XXX FIXME only decompress once | ||
$fp = popen("gzip -dc $pkgfile | tar -tf -", 'r'); | ||
if (!$fp) { | ||
return $this->raiseError("Unable to examine $pkgfile (gzip or tar failed)"); | ||
} | ||
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; | ||
} | ||
} | ||
pclose($fp); | ||
if (!$descfile) { | ||
return $this->raiseError("Invalid package: no package.xml file found!"); | ||
} | ||
|
||
// Decompress pack in tmp dir ------------------------------------- | ||
|
||
// To allow relative package file calls | ||
if (!chdir(dirname($pkgfile))) { | ||
return $this->raiseError('Unable to chdir to pakage directory'); | ||
} | ||
$pkgfile = getcwd() . DIRECTORY_SEPARATOR . basename($pkgfile); | ||
|
||
// XXX FIXME Windows | ||
$this->tmpdir = tempnam("/tmp", "pear"); | ||
$this->tmpdir = tempnam('/tmp', 'pear'); | ||
unlink($this->tmpdir); | ||
if (!mkdir($this->tmpdir, 0755)) { | ||
return $this->raiseError("Unable to create temporary directory $this->tmpdir."); | ||
} else { | ||
$this->log(2, '...tmp dir created at ' . $this->tmpdir); | ||
$this->log(2, '+ tmp dir created at ' . $this->tmpdir); | ||
} | ||
$this->addTempFile($this->tmpdir); | ||
|
||
|
||
// XXX FIXME Windows should check for drive | ||
if (substr($pkgfile, 0, 1) == DIRECTORY_SEPARATOR) { | ||
$pkgfilepath = $pkgfile; | ||
} else { | ||
$pkgfilepath = $this->pwd . DIRECTORY_SEPARATOR . $pkgfile; | ||
} | ||
|
||
if (!chdir($this->tmpdir)) { | ||
return $this->raiseError("Unable to chdir to $this->tmpdir."); | ||
} | ||
// XXX FIXME Windows | ||
system("gzip -dc $pkgfilepath | tar -xf -"); | ||
$this->log(2, "launched command: gzip -dc $pkgfilepath | tar -xf -"); | ||
if (!is_file($descfile)) { | ||
$this->log(2, "No desc file found: $descfile"); | ||
$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)"); | ||
} | ||
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; | ||
} | ||
} | ||
pclose($fp); | ||
if (!isset($descfile) || !is_file($descfile)) { | ||
return $this->raiseError("No package.xml file after extracting the archive."); | ||
} | ||
|
||
|
@@ -313,9 +303,10 @@ function install($pkgfile) | |
return $this->raiseError("No script destination directory found\n", | ||
null, PEAR_ERROR_DIE); | ||
} | ||
$tmp_path = dirname($descfile); | ||
foreach ($pkginfo['filelist'] as $fname => $atts) { | ||
$dest_dir = $this->phpdir . DIRECTORY_SEPARATOR . dirname($fname); | ||
$fname = dirname($descfile) . DIRECTORY_SEPARATOR . $fname; | ||
$fname = $tmp_path . DIRECTORY_SEPARATOR . $fname; | ||
$this->_copyFile($fname, $dest_dir, $atts); | ||
} | ||
return true; | ||
|