2001-04-17 01:17:59 +00:00
|
|
|
<?php
|
|
|
|
//
|
|
|
|
// +----------------------------------------------------------------------+
|
2001-12-11 15:32:16 +00:00
|
|
|
// | PHP Version 4 |
|
2001-04-17 01:17:59 +00:00
|
|
|
// +----------------------------------------------------------------------+
|
2001-12-11 15:32:16 +00:00
|
|
|
// | Copyright (c) 1997-2002 The PHP Group |
|
2001-04-17 01:17:59 +00:00
|
|
|
// +----------------------------------------------------------------------+
|
|
|
|
// | This source file is subject to version 2.02 of the PHP license, |
|
|
|
|
// | that is bundled with this package in the file LICENSE, and is |
|
|
|
|
// | available at through the world-wide-web at |
|
|
|
|
// | http://www.php.net/license/2_02.txt. |
|
|
|
|
// | If you did not receive a copy of the PHP license and are unable to |
|
|
|
|
// | obtain it through the world-wide-web, please send a note to |
|
|
|
|
// | license@php.net so we can mail you a copy immediately. |
|
|
|
|
// +----------------------------------------------------------------------+
|
|
|
|
// | Authors: Stig Bakken <ssb@fast.no> |
|
2001-07-17 19:21:55 +00:00
|
|
|
// | Tomas V.V.Cox <cox@idecnet.com> |
|
2001-08-19 12:53:01 +00:00
|
|
|
// | |
|
2001-04-17 01:17:59 +00:00
|
|
|
// +----------------------------------------------------------------------+
|
|
|
|
//
|
2001-07-17 19:21:55 +00:00
|
|
|
// $Id$
|
2001-04-17 01:17:59 +00:00
|
|
|
|
2001-07-17 19:21:55 +00:00
|
|
|
require_once 'PEAR/Common.php';
|
2001-04-17 01:17:59 +00:00
|
|
|
|
|
|
|
/**
|
2001-04-20 13:04:30 +00:00
|
|
|
* Administration class used to make a PEAR release tarball.
|
2001-04-17 01:17:59 +00:00
|
|
|
*
|
2001-07-18 17:13:38 +00:00
|
|
|
* TODO:
|
|
|
|
* - add an extra param the dir where to place the created package
|
2001-10-07 20:16:41 +00:00
|
|
|
* - finish and test Windows support
|
2001-07-18 17:13:38 +00:00
|
|
|
*
|
2001-04-17 01:17:59 +00:00
|
|
|
* @since PHP 4.0.2
|
|
|
|
* @author Stig Bakken <ssb@fast.no>
|
|
|
|
*/
|
2001-07-17 19:21:55 +00:00
|
|
|
class PEAR_Packager extends PEAR_Common
|
2001-04-17 01:17:59 +00:00
|
|
|
{
|
|
|
|
// {{{ properties
|
|
|
|
|
|
|
|
/** assoc with information about the package */
|
|
|
|
var $pkginfo = array();
|
|
|
|
|
|
|
|
/** name of the package directory, for example Foo-1.0 */
|
|
|
|
var $pkgdir;
|
|
|
|
|
|
|
|
/** directory where PHP code files go */
|
|
|
|
var $phpdir;
|
|
|
|
|
|
|
|
/** directory where PHP extension files go */
|
|
|
|
var $extdir;
|
|
|
|
|
|
|
|
/** directory where documentation goes */
|
|
|
|
var $docdir;
|
|
|
|
|
|
|
|
/** directory where system state information goes */
|
|
|
|
var $statedir;
|
|
|
|
|
|
|
|
/** debug mode (integer) */
|
|
|
|
var $debug = 0;
|
|
|
|
|
|
|
|
/** temporary directory */
|
|
|
|
var $tmpdir;
|
|
|
|
|
|
|
|
/** whether file list is currently being copied */
|
|
|
|
var $recordfilelist;
|
|
|
|
|
|
|
|
/** temporary space for copying file list */
|
|
|
|
var $filelist;
|
|
|
|
|
|
|
|
/** package name and version, for example "HTTP-1.0" */
|
|
|
|
var $pkgver;
|
|
|
|
|
|
|
|
// }}}
|
|
|
|
|
|
|
|
// {{{ constructor
|
|
|
|
|
|
|
|
function PEAR_Packager($phpdir = PEAR_INSTALL_DIR,
|
|
|
|
$extdir = PEAR_EXTENSION_DIR,
|
|
|
|
$docdir = '')
|
|
|
|
{
|
|
|
|
$this->PEAR();
|
|
|
|
$this->phpdir = $phpdir;
|
|
|
|
$this->extdir = $extdir;
|
|
|
|
$this->docdir = $docdir;
|
|
|
|
}
|
|
|
|
|
|
|
|
// }}}
|
|
|
|
// {{{ destructor
|
|
|
|
|
2001-10-08 16:52:33 +00:00
|
|
|
function _PEAR_Packager()
|
|
|
|
{
|
2001-10-09 02:56:33 +00:00
|
|
|
chdir($this->orig_pwd);
|
2001-10-08 16:52:33 +00:00
|
|
|
$this->_PEAR_Common();
|
2001-04-17 01:17:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// }}}
|
|
|
|
|
2001-05-28 06:31:03 +00:00
|
|
|
// {{{ package()
|
|
|
|
|
2001-08-19 12:53:01 +00:00
|
|
|
function package($pkgfile = null)
|
2001-07-17 19:21:55 +00:00
|
|
|
{
|
2001-10-09 02:56:33 +00:00
|
|
|
$this->orig_pwd = getcwd();
|
2001-08-19 12:53:01 +00:00
|
|
|
if (empty($pkgfile)) {
|
|
|
|
$pkgfile = 'package.xml';
|
|
|
|
}
|
2001-07-17 19:21:55 +00:00
|
|
|
$pkginfo = $this->infoFromDescriptionFile($pkgfile);
|
|
|
|
if (PEAR::isError($pkginfo)) {
|
|
|
|
return $pkginfo;
|
|
|
|
}
|
2001-12-01 17:55:47 +00:00
|
|
|
// XXX This needs to be checked in infoFromDescriptionFile
|
|
|
|
// or at least a helper method to do the proper checks
|
|
|
|
if (empty($pkginfo['version'])) {
|
|
|
|
return $this->raiseError("No version information found in $pkgfile",
|
|
|
|
null, PEAR_ERROR_TRIGGER, E_USER_ERROR);
|
|
|
|
}
|
2001-07-17 19:21:55 +00:00
|
|
|
// TMP DIR -------------------------------------------------
|
2001-07-31 13:36:54 +00:00
|
|
|
// We allow calls like "pear package /home/user/mypack/package.xml"
|
|
|
|
if (!@chdir(dirname($pkgfile))) {
|
|
|
|
return $this->raiseError('Couldn\'t chdir to package.xml dir',
|
|
|
|
null, PEAR_ERROR_TRIGGER, E_USER_ERROR);
|
2001-07-17 19:21:55 +00:00
|
|
|
}
|
2001-07-31 13:36:54 +00:00
|
|
|
$pwd = getcwd();
|
|
|
|
$pkgfile = basename($pkgfile);
|
2001-11-06 00:22:18 +00:00
|
|
|
if (isset($pkginfo['release_state']) && $pkginfo['release_state'] == 'snapshot') {
|
2001-10-31 05:39:11 +00:00
|
|
|
$pkginfo['version'] = date('Ymd');
|
|
|
|
}
|
2001-07-17 19:21:55 +00:00
|
|
|
// don't want strange characters
|
2001-10-08 16:52:33 +00:00
|
|
|
$pkgname = ereg_replace ('[^a-zA-Z0-9._]', '_', $pkginfo['package']);
|
|
|
|
$pkgversion = ereg_replace ('[^a-zA-Z0-9._\-]', '_', $pkginfo['version']);
|
|
|
|
$pkgver = $pkgname . '-' . $pkgversion;
|
|
|
|
|
2001-10-09 02:56:33 +00:00
|
|
|
$tmpdir = $pwd . DIRECTORY_SEPARATOR . $pkgver;
|
|
|
|
if (file_exists($tmpdir)) {
|
|
|
|
return $this->raiseError('Tmpdir: ' . $tmpdir .' already exists',
|
2001-07-17 19:21:55 +00:00
|
|
|
null, PEAR_ERROR_TRIGGER, E_USER_ERROR);
|
|
|
|
}
|
2001-10-09 02:56:33 +00:00
|
|
|
if (!mkdir($tmpdir, 0700)) {
|
|
|
|
return $this->raiseError("Unable to create temporary directory $tmpdir.",
|
2001-07-17 19:21:55 +00:00
|
|
|
null, PEAR_ERROR_TRIGGER, E_USER_ERROR);
|
|
|
|
} else {
|
2001-10-09 02:56:33 +00:00
|
|
|
$this->log(2, "+ tmp dir created at: " . $tmpdir);
|
2001-07-17 19:21:55 +00:00
|
|
|
}
|
2001-10-09 02:56:33 +00:00
|
|
|
$this->addTempFile($tmpdir);
|
2001-07-17 19:21:55 +00:00
|
|
|
|
|
|
|
// Copy files -----------------------------------------------
|
2001-07-18 17:13:38 +00:00
|
|
|
foreach ($pkginfo['filelist'] as $fname => $atts) {
|
2001-10-09 02:56:33 +00:00
|
|
|
$file = $tmpdir . DIRECTORY_SEPARATOR . $fname;
|
2001-07-17 19:21:55 +00:00
|
|
|
$dir = dirname($file);
|
|
|
|
if (!@is_dir($dir)) {
|
|
|
|
if (!$this->mkDirHier($dir)) {
|
|
|
|
return $this->raiseError("could not mkdir $dir");
|
|
|
|
}
|
|
|
|
}
|
2001-08-19 12:30:24 +00:00
|
|
|
//Maintain original file perms
|
2001-08-19 12:37:51 +00:00
|
|
|
$orig_perms = @fileperms($fname);
|
2001-07-17 19:21:55 +00:00
|
|
|
if (!@copy($fname, $file)) {
|
|
|
|
$this->log(0, "could not copy $fname to $file");
|
|
|
|
} else {
|
2001-10-09 02:56:33 +00:00
|
|
|
$this->log(2, "+ copying $fname to $file");
|
2001-08-19 12:37:51 +00:00
|
|
|
@chmod($file, $orig_perms);
|
2001-07-17 19:21:55 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
// XXX TODO: Rebuild the package file as the old method did?
|
2001-07-18 17:13:38 +00:00
|
|
|
|
|
|
|
// This allows build packages from different pear pack def files
|
2001-10-09 02:56:33 +00:00
|
|
|
$dest_pkgfile = $tmpdir . DIRECTORY_SEPARATOR . 'package.xml';
|
2001-08-19 12:30:24 +00:00
|
|
|
$this->log(2, "+ copying package $pkgfile to $dest_pkgfile");
|
|
|
|
if (!@copy($pkgfile, $dest_pkgfile)) {
|
|
|
|
return $this->raiseError("could not copy $pkgfile to $dest_pkgfile");
|
2001-07-17 19:21:55 +00:00
|
|
|
}
|
2001-10-09 02:56:33 +00:00
|
|
|
@chmod($dest_pkgfile, 0644);
|
2001-07-17 19:21:55 +00:00
|
|
|
|
|
|
|
// TAR the Package -------------------------------------------
|
2001-10-09 02:56:33 +00:00
|
|
|
chdir(dirname($tmpdir));
|
|
|
|
$dest_package = $this->orig_pwd . DIRECTORY_SEPARATOR . "{$pkgver}.tgz";
|
|
|
|
$this->log(2, "Attempting to pack $tmpdir dir in $dest_package");
|
2001-10-08 03:29:34 +00:00
|
|
|
$tar = new Archive_Tar($dest_package, true);
|
|
|
|
$tar->setErrorHandling(PEAR_ERROR_PRINT);
|
|
|
|
if (!$tar->create($pkgver)) {
|
|
|
|
return $this->raiseError('an error ocurred during package creation');
|
|
|
|
}
|
2001-07-31 13:36:54 +00:00
|
|
|
$this->log(1, "Package $dest_package done");
|
|
|
|
return $dest_package;
|
2001-07-17 19:21:55 +00:00
|
|
|
}
|
|
|
|
|
2001-04-17 01:17:59 +00:00
|
|
|
// }}}
|
|
|
|
}
|
|
|
|
|
|
|
|
?>
|