Skip to content

Commit 3d95bf9

Browse files
author
Vincent Blavet
committed
* Remove the use of a temp dir
* Tar archive is now doing the same work with less overhead
1 parent 5746250 commit 3d95bf9

File tree

1 file changed

+11
-37
lines changed

1 file changed

+11
-37
lines changed

pear/PEAR/Packager.php

Lines changed: 11 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -128,54 +128,28 @@ function package($pkgfile = null)
128128
$pkgversion = ereg_replace ('[^a-zA-Z0-9._\-]', '_', $pkginfo['version']);
129129
$pkgver = $pkgname . '-' . $pkgversion;
130130

131-
$tmpdir = $pwd . DIRECTORY_SEPARATOR . $pkgver;
132-
if (file_exists($tmpdir)) {
133-
return $this->raiseError('Tmpdir: ' . $tmpdir .' already exists',
134-
null, PEAR_ERROR_TRIGGER, E_USER_ERROR);
135-
}
136-
if (!mkdir($tmpdir, 0700)) {
137-
return $this->raiseError("Unable to create temporary directory $tmpdir.",
138-
null, PEAR_ERROR_TRIGGER, E_USER_ERROR);
139-
} else {
140-
$this->log(2, "+ tmp dir created at: " . $tmpdir);
141-
}
142-
$this->addTempFile($tmpdir);
131+
// ----- Create the package file list
132+
$filelist = array();
133+
$i = 0;
134+
135+
// ----- Add the package XML file
136+
$filelist[$i++] = $pkgfile;
143137

144138
// Copy files -----------------------------------------------
145139
foreach ($pkginfo['filelist'] as $fname => $atts) {
146-
$file = $tmpdir . DIRECTORY_SEPARATOR . $fname;
147-
$dir = dirname($file);
148-
if (!@is_dir($dir)) {
149-
if (!$this->mkDirHier($dir)) {
150-
return $this->raiseError("could not mkdir $dir");
151-
}
152-
}
153-
//Maintain original file perms
154-
$orig_perms = @fileperms($fname);
155-
if (!@copy($fname, $file)) {
156-
$this->log(0, "could not copy $fname to $file");
140+
if (!file_exists($fname)) {
141+
return $this->raiseError("File $fname does not exists");
157142
} else {
158-
$this->log(2, "+ copying $fname to $file");
159-
@chmod($file, $orig_perms);
143+
$filelist[$i++] = $fname;
160144
}
161145
}
162146
// XXX TODO: Rebuild the package file as the old method did?
163147
164-
// This allows build packages from different pear pack def files
165-
$dest_pkgfile = $tmpdir . DIRECTORY_SEPARATOR . 'package.xml';
166-
$this->log(2, "+ copying package $pkgfile to $dest_pkgfile");
167-
if (!@copy($pkgfile, $dest_pkgfile)) {
168-
return $this->raiseError("could not copy $pkgfile to $dest_pkgfile");
169-
}
170-
@chmod($dest_pkgfile, 0644);
171-
172148
// TAR the Package -------------------------------------------
173-
chdir(dirname($tmpdir));
174149
$dest_package = $this->orig_pwd . DIRECTORY_SEPARATOR . "{$pkgver}.tgz";
175-
$this->log(2, "Attempting to pack $tmpdir dir in $dest_package");
176150
$tar = new Archive_Tar($dest_package, true);
177151
$tar->setErrorHandling(PEAR_ERROR_PRINT);
178-
if (!$tar->create($pkgver)) {
152+
if (!$tar->createModify($filelist, $pkgver)) {
179153
return $this->raiseError('an error ocurred during package creation');
180154
}
181155
$this->log(1, "Package $dest_package done");
@@ -185,4 +159,4 @@ function package($pkgfile = null)
185159
// }}}
186160
}
187161

188-
?>
162+
?>

0 commit comments

Comments
 (0)