Example #1
0
 /**
  * Attempts to rename a file from a source to a destination.
  * If overwrite is set to true, this method overwrites existing file
  * even if the destination file is newer.
  * Otherwise, the source f
  * ile is renamed only if the destination file #
  * is older than it.
  */
 private function renameFile(PhingFile $sourceFile, PhingFile $destFile, $overwrite)
 {
     $renamed = true;
     // ensure that parent dir of dest file exists!
     $parent = $destFile->getParentFile();
     if ($parent !== null) {
         if (!$parent->exists()) {
             $parent->mkdirs();
         }
     }
     if ($destFile->exists()) {
         try {
             $destFile->delete();
         } catch (Exception $e) {
             throw new BuildException("Unable to remove existing file " . $destFile->__toString() . ": " . $e->getMessage());
         }
     }
     $renamed = $sourceFile->renameTo($destFile);
     return $renamed;
 }