Skip to content

Commit

Permalink
- Only decompress package once
Browse files Browse the repository at this point in the history
- Allow relative directory package calls (for ex:
  pear install packs/Pear_DB-1.1.tgz)
  • Loading branch information
tvvcox committed Jul 18, 2001
1 parent 9576ab2 commit 9638928
Showing 1 changed file with 27 additions and 36 deletions.
63 changes: 27 additions & 36 deletions pear/PEAR/Installer.php
Original file line number Diff line number Diff line change
Expand Up @@ -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]>
Expand Down Expand Up @@ -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.");
}

Expand All @@ -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;
Expand Down

0 comments on commit 9638928

Please sign in to comment.