| 193 | | // check if tar is out of date with respect to each |
| 194 | | // fileset |
| 195 | | $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 | |
| 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 | |