Permalink
Browse files

Remove existing link/file/dir if overwrite is true (inspired by pull …

…request #90)
  • Loading branch information...
1 parent 72c83f8 commit 64b10a64105ffa486e5ac69be2f93500662663ef @mrook mrook committed Feb 18, 2012
Showing with 16 additions and 12 deletions.
  1. +16 −12 classes/phing/tasks/ext/SymlinkTask.php
@@ -282,24 +282,28 @@ public function main()
*/
protected function symlink($target, $link)
{
- if (file_exists($link)) {
- if (!is_link($link)) {
- $this->log('File exists: ' . $link, Project::MSG_ERR);
+ $fs = FileSystem::getFileSystem();
+
+ if (is_link($link) && readlink($link) == $target) {
+ $this->log('Link exists: ' . $link, Project::MSG_INFO);
+ return true;
+ } elseif (file_exists($link)) {
+ if (!$this->getOverwrite()) {
+ $this->log('Not overwriting existing link ' . $link, Project::MSG_ERR);
return false;
}
-
- if (readlink($link) == $target || !$this->getOverwrite()) {
- $this->log('Link exists: ' . $link, Project::MSG_ERR);
- return false;
+
+ if (is_link($link) || is_file($link)) {
+ $fs->unlink($link);
+ $this->log('Link removed: ' . $link, Project::MSG_INFO);
+ } else {
+ $fs->rmdir($link, true);
+ $this->log('Directory removed: ' . $link, Project::MSG_INFO);
}
-
- unlink($link);
}
- $fs = FileSystem::getFileSystem();
-
$this->log('Linking: ' . $target . ' to ' . $link, Project::MSG_INFO);
return $fs->symlink($target, $link);
}
-}
+}

0 comments on commit 64b10a6

Please sign in to comment.