Skip to content

Commit 2c1af4d

Browse files
committed
package() now returns the full path of the generated package also improved
windows support (if php getcwd() returns also the drive letter, please test it)
1 parent ae92dc7 commit 2c1af4d

File tree

1 file changed

+13
-15
lines changed

1 file changed

+13
-15
lines changed

pear/PEAR/Packager.php

Lines changed: 13 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -121,16 +121,14 @@ function package($pkgfile = 'package.xml')
121121
return $pkginfo;
122122
}
123123
// TMP DIR -------------------------------------------------
124-
$pwd = getcwd();
125-
$new_pwd = dirname($pkgfile);
126-
// We allow calls like "pear package /home/cox/mypack/package.xml"
127-
if ($new_pwd != '.') {
128-
chdir($new_pwd);
129-
$new_pwd = getcwd();
130-
$orig_pwd = $pwd;
131-
$pwd = $new_pwd;
132-
$pkgfile = basename($pkgfile);
124+
$orig_pwd = getcwd();
125+
// We allow calls like "pear package /home/user/mypack/package.xml"
126+
if (!@chdir(dirname($pkgfile))) {
127+
return $this->raiseError('Couldn\'t chdir to package.xml dir',
128+
null, PEAR_ERROR_TRIGGER, E_USER_ERROR);
133129
}
130+
$pwd = getcwd();
131+
$pkgfile = basename($pkgfile);
134132
$pkgver = $pkginfo['package'] . '-' . $pkginfo['version'];
135133
// don't want strange characters
136134
$pkgver = ereg_replace ('[^a-zA-Z0-9._-]', '_', $pkgver);
@@ -172,15 +170,15 @@ function package($pkgfile = 'package.xml')
172170

173171
// TAR the Package -------------------------------------------
174172
chdir(dirname($this->tmpdir));
173+
$dest_package = $orig_pwd . DIRECTORY_SEPARATOR . "${pkgver}.tgz";
175174
// XXX FIXME Windows and non-GNU tar
176-
$pwd = (isset($orig_pwd)) ? $orig_pwd : $pwd;
177-
$cmd = "tar -cvzf $pwd/${pkgver}.tgz $pkgver";
175+
$cmd = "tar -cvzf $dest_package $pkgver";
176+
$this->log(2, "+ launched cmd: $cmd");
178177
// XXX TODO: add an extra param where to leave the package?
179178
$this->log(1, `$cmd`);
180-
$this->log(1, "Package $pwd/${pkgver}.tgz done");
181-
if (isset($orig_pwd)) {
182-
chdir($orig_pwd);
183-
}
179+
$this->log(1, "Package $dest_package done");
180+
chdir($orig_pwd);
181+
return $dest_package;
184182
}
185183

186184
/* XXXX REMOVEME: this is the old code

0 commit comments

Comments
 (0)