Changeset 94
- Timestamp:
- 07/11/06 15:33:29 (4 years ago)
- File:
-
- 1 edited
-
branches/2.2/classes/phing/tasks/ext/TarTask.php (modified) (6 diffs)
Legend:
- Unmodified
- Added
- Removed
-
branches/2.2/classes/phing/tasks/ext/TarTask.php
r59 r94 45 45 private $tarFile; 46 46 private $baseDir; 47 47 private $includeEmpty = true; // Whether to include empty dirs in the TAR 48 48 49 private $longFileMode = "warn"; 49 50 … … 106 107 public function setBasedir(PhingFile $baseDir) { 107 108 $this->baseDir = $baseDir; 109 } 110 111 /** 112 * Set the include empty dirs flag. 113 * @param boolean Flag if empty dirs should be tarred too 114 * @return void 115 * @access public 116 */ 117 function setIncludeEmptyDirs($bool) { 118 $this->includeEmpty = (boolean) $bool; 108 119 } 109 120 … … 191 202 } 192 203 193 // check if tar is out of date with respect to each 194 // fileset195 $upToDate = true;196 foreach($this->filesets as $fs) {197 $files = $fs->getFiles($this->project);198 if (!$this->archiveIsUpToDate($files, $fs->getDir($this->project))) {199 $upToDate = false;200 }201 for ($i=0, $fcount=count($files); $i < $fcount; $i++) {202 if ($this->tarFile->equals(new PhingFile($fs->getDir($this->project), $files[$i]))) {203 throw new BuildException("A tar file cannot include itself", $this->getLocation());204 }205 }206 }207 208 if ($upToDate) { 209 $this->log("Nothing to do: " . $this->tarFile->__toString() . " is up to date.", PROJECT_MSG_INFO);210 return; 211 }212 204 // check if tar is out of date with respect to each fileset 205 if($this->tarFile->exists()) { 206 $upToDate = true; 207 foreach($this->filesets as $fs) { 208 $files = $fs->getFiles($this->project, $this->includeEmpty); 209 if (!$this->archiveIsUpToDate($files, $fs->getDir($this->project))) { 210 $upToDate = false; 211 } 212 for ($i=0, $fcount=count($files); $i < $fcount; $i++) { 213 if ($this->tarFile->equals(new PhingFile($fs->getDir($this->project), $files[$i]))) { 214 throw new BuildException("A tar file cannot include itself", $this->getLocation()); 215 } 216 } 217 } 218 if ($upToDate) { 219 $this->log("Nothing to do: " . $this->tarFile->__toString() . " is up to date.", PROJECT_MSG_INFO); 220 return; 221 } 222 } 223 213 224 $this->log("Building tar: " . $this->tarFile->__toString(), PROJECT_MSG_INFO); 214 225 … … 219 230 220 231 foreach($this->filesets as $fs) { 221 $files = $fs->getFiles($this->project );232 $files = $fs->getFiles($this->project, $this->includeEmpty); 222 233 if (count($files) > 1 && strlen($fs->getFullpath()) > 0) { 223 234 throw new BuildException("fullpath attribute may only " … … 226 237 . "single file."); 227 238 } 228 // FIXME229 // Current model is only adding directories implicitly. This230 // won't add any empty directories. Perhaps modify TarFileSet::getFiles()231 // to also include empty directories. Not high priority, since non-inclusion232 // of empty dirs is probably not unexpected behavior for TarTask.233 239 $fsBasedir = $fs->getDir($this->project); 234 240 $filesToTar = array(); … … 289 295 * the baseDir for the project. 290 296 */ 291 public function getFiles(Project $p) { 297 public function getFiles(Project $p, $includeEmpty = true) { 298 292 299 if ($this->files === null) { 300 293 301 $ds = $this->getDirectoryScanner($p); 294 302 $this->files = $ds->getIncludedFiles(); 295 } 303 304 if ($includeEmpty) { 305 306 // first any empty directories that will not be implicitly added by any of the files 307 $implicitDirs = array(); 308 foreach($this->files as $file) { 309 $implicitDirs[] = dirname($file); 310 } 311 312 $incDirs = $ds->getIncludedDirectories(); 313 314 // we'll need to add to that list of implicit dirs any directories 315 // that contain other *directories* (and not files), since otherwise 316 // we get duplicate directories in the resulting tar 317 foreach($incDirs as $dir) { 318 foreach($incDirs as $dircheck) { 319 if (!empty($dir) && $dir == dirname($dircheck)) { 320 $implicitDirs[] = $dir; 321 } 322 } 323 } 324 325 $implicitDirs = array_unique($implicitDirs); 326 327 // Now add any empty dirs (dirs not covered by the implicit dirs) 328 // to the files array. 329 330 foreach($incDirs as $dir) { // we cannot simply use array_diff() since we want to disregard empty/. dirs 331 if ($dir != "" && $dir != "." && !in_array($dir, $implicitDirs)) { 332 // it's an empty dir, so we'll add it. 333 $this->files[] = $dir; 334 } 335 } 336 } // if $includeEmpty 337 338 } // if ($this->files===null) 339 296 340 return $this->files; 297 341 }
Note: See TracChangeset
for help on using the changeset viewer.
