mirror of
https://github.com/php/php-src.git
synced 2024-09-22 18:37:25 +00:00
- Removed the xml parser code (use now PEAR_Common::infoFromDescriptionFile())
- Added the ability to build packages without the need of being in the same dir as the package.xml file (f.ex: pear package ./mypack/package.xml) - Removed methods log() and mkdirHier() as they are now in Common.php - More debug code and error checks
This commit is contained in:
parent
5cb96db143
commit
bed51fa581
@ -14,11 +14,12 @@
|
|||||||
// | license@php.net so we can mail you a copy immediately. |
|
// | license@php.net so we can mail you a copy immediately. |
|
||||||
// +----------------------------------------------------------------------+
|
// +----------------------------------------------------------------------+
|
||||||
// | Authors: Stig Bakken <ssb@fast.no> |
|
// | Authors: Stig Bakken <ssb@fast.no> |
|
||||||
// | |
|
// | Tomas V.V.Cox <cox@idecnet.com> |
|
||||||
// +----------------------------------------------------------------------+
|
// +----------------------------------------------------------------------+
|
||||||
//
|
//
|
||||||
|
// $Id$
|
||||||
|
|
||||||
require_once "PEAR.php";
|
require_once 'PEAR/Common.php';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Administration class used to make a PEAR release tarball.
|
* Administration class used to make a PEAR release tarball.
|
||||||
@ -26,7 +27,7 @@ require_once "PEAR.php";
|
|||||||
* @since PHP 4.0.2
|
* @since PHP 4.0.2
|
||||||
* @author Stig Bakken <ssb@fast.no>
|
* @author Stig Bakken <ssb@fast.no>
|
||||||
*/
|
*/
|
||||||
class PEAR_Packager extends PEAR
|
class PEAR_Packager extends PEAR_Common
|
||||||
{
|
{
|
||||||
// {{{ properties
|
// {{{ properties
|
||||||
|
|
||||||
@ -109,14 +110,83 @@ class PEAR_Packager extends PEAR
|
|||||||
|
|
||||||
// {{{ package()
|
// {{{ package()
|
||||||
|
|
||||||
function package($pkgfile = "package.xml")
|
function package($pkgfile = 'package.xml')
|
||||||
|
{
|
||||||
|
$pkginfo = $this->infoFromDescriptionFile($pkgfile);
|
||||||
|
if (PEAR::isError($pkginfo)) {
|
||||||
|
return $pkginfo;
|
||||||
|
}
|
||||||
|
// TMP DIR -------------------------------------------------
|
||||||
|
$pwd = getcwd();
|
||||||
|
$new_pwd = dirname($pkgfile);
|
||||||
|
// We allow calls like "pear package /home/cox/mypack/package.xml"
|
||||||
|
if ($new_pwd != '.') {
|
||||||
|
chdir($new_pwd);
|
||||||
|
$new_pwd = getcwd();
|
||||||
|
$orig_pwd = $pwd;
|
||||||
|
$pwd = $new_pwd;
|
||||||
|
$pkgfile = basename($pkgfile);
|
||||||
|
}
|
||||||
|
$pkgver = $pkginfo['package'] . '-' . $pkginfo['version'];
|
||||||
|
// don't want strange characters
|
||||||
|
$pkgver = ereg_replace ('[^a-zA-Z0-9._-]', '_', $pkgver);
|
||||||
|
$this->tmpdir = $pwd . DIRECTORY_SEPARATOR . $pkgver;
|
||||||
|
if (file_exists($this->tmpdir)) {
|
||||||
|
return $this->raiseError('Tmpdir: ' . $this->tmpdir .' already exists',
|
||||||
|
null, PEAR_ERROR_TRIGGER, E_USER_ERROR);
|
||||||
|
}
|
||||||
|
if (!mkdir($this->tmpdir, 0755)) {
|
||||||
|
return $this->raiseError("Unable to create temporary directory $this->tmpdir.",
|
||||||
|
null, PEAR_ERROR_TRIGGER, E_USER_ERROR);
|
||||||
|
} else {
|
||||||
|
$this->log(2, "...TmpDir created at: " . $this->tmpdir);
|
||||||
|
}
|
||||||
|
$this->_tempfiles[] = $this->tmpdir;
|
||||||
|
|
||||||
|
// Copy files -----------------------------------------------
|
||||||
|
$files = &$pkginfo['filelist'];
|
||||||
|
foreach ($files as $fname => $atts) {
|
||||||
|
$file = $this->tmpdir . DIRECTORY_SEPARATOR . $fname;
|
||||||
|
$dir = dirname($file);
|
||||||
|
if (!@is_dir($dir)) {
|
||||||
|
if (!$this->mkDirHier($dir)) {
|
||||||
|
return $this->raiseError("could not mkdir $dir");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (!@copy($fname, $file)) {
|
||||||
|
$this->log(0, "could not copy $fname to $file");
|
||||||
|
} else {
|
||||||
|
$this->log(2, "...copying from $fname to $file");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// XXX TODO: Rebuild the package file as the old method did?
|
||||||
|
if (!@copy($pkgfile, $this->tmpdir . DIRECTORY_SEPARATOR . $pkgfile)) {
|
||||||
|
return $this->raiseError("could not copy $pkgfile to " . $this->tmpdir);
|
||||||
|
}
|
||||||
|
$this->log(2, "...copying package $pkgfile to " . $this->tmpdir);
|
||||||
|
|
||||||
|
// TAR the Package -------------------------------------------
|
||||||
|
chdir(dirname($this->tmpdir));
|
||||||
|
// XXX FIXME Windows and non-GNU tar
|
||||||
|
$pwd = (isset($orig_pwd)) ? $orig_pwd : $pwd;
|
||||||
|
$cmd = "tar -cvzf $pwd/${pkgver}.tgz $pkgver";
|
||||||
|
// XXX TODO: add an extra param where to leave the package?
|
||||||
|
$this->log(1, `$cmd`);
|
||||||
|
$this->log(1, "Package $pwd/${pkgver}.tgz done");
|
||||||
|
if (isset($orig_pwd)) {
|
||||||
|
chdir($orig_pwd);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/* XXXX REMOVEME: this is the old code
|
||||||
|
function _package($pkgfile = "package.xml")
|
||||||
{
|
{
|
||||||
$pwd = getcwd();
|
$pwd = getcwd();
|
||||||
$fp = @fopen($pkgfile, "r");
|
$fp = @fopen($pkgfile, "r");
|
||||||
if (!is_resource($fp)) {
|
if (!is_resource($fp)) {
|
||||||
return $this->raiseError($php_errormsg);
|
return $this->raiseError($php_errormsg);
|
||||||
}
|
}
|
||||||
|
|
||||||
$xp = xml_parser_create();
|
$xp = xml_parser_create();
|
||||||
if (!$xp) {
|
if (!$xp) {
|
||||||
return $this->raiseError("Unable to create XML parser.");
|
return $this->raiseError("Unable to create XML parser.");
|
||||||
@ -130,7 +200,7 @@ class PEAR_Packager extends PEAR
|
|||||||
$this->element_stack = array();
|
$this->element_stack = array();
|
||||||
$this->pkginfo = array();
|
$this->pkginfo = array();
|
||||||
$this->current_element = false;
|
$this->current_element = false;
|
||||||
|
|
||||||
$data = fread($fp, filesize($pkgfile));
|
$data = fread($fp, filesize($pkgfile));
|
||||||
fclose($fp);
|
fclose($fp);
|
||||||
if (!xml_parse($xp, $data, true)) {
|
if (!xml_parse($xp, $data, true)) {
|
||||||
@ -182,36 +252,6 @@ class PEAR_Packager extends PEAR
|
|||||||
|
|
||||||
// }}}
|
// }}}
|
||||||
|
|
||||||
// {{{ mkDirHier()
|
|
||||||
|
|
||||||
function mkDirHier($dir)
|
|
||||||
{
|
|
||||||
$dirstack = array();
|
|
||||||
while (!is_dir($dir) && $dir != DIRECTORY_SEPARATOR) {
|
|
||||||
array_unshift($dirstack, $dir);
|
|
||||||
$dir = dirname($dir);
|
|
||||||
}
|
|
||||||
while ($newdir = array_shift($dirstack)) {
|
|
||||||
if (mkdir($newdir, 0777)) {
|
|
||||||
$this->log(1, "created dir $newdir");
|
|
||||||
} else {
|
|
||||||
return $this->raiseError("mkdir($newdir) failed");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// }}}
|
|
||||||
// {{{ log()
|
|
||||||
|
|
||||||
function log($level, $msg)
|
|
||||||
{
|
|
||||||
if ($this->debug >= $level) {
|
|
||||||
print "$msg\n";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// }}}
|
|
||||||
|
|
||||||
// {{{ startHandler()
|
// {{{ startHandler()
|
||||||
|
|
||||||
function startHandler($xp, $name, $attribs)
|
function startHandler($xp, $name, $attribs)
|
||||||
@ -309,7 +349,7 @@ class PEAR_Packager extends PEAR
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
*/
|
||||||
// }}}
|
// }}}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user