-
Notifications
You must be signed in to change notification settings - Fork 2
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Patch Phing to fix relative symlinks #179
Merged
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
7cdc28b
add relative symlink patch for Phing
byrond fba2a70
use URL for Phing patch
byrond b6dd367
use symlink phing task for includeresource
byrond 39e6044
make relative symlinks the default
byrond 576ed7e
Use 'protected' instead of 'private' (coding standards).
becw 74ffd50
Document where the patch came from.
becw File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
### phing-relative-symlinks.patch | ||
|
||
Source: [https://github.com/phingofficial/phing/pull/695](https://github.com/phingofficial/phing/pull/695) | ||
|
||
This patch updates Phing's SymlinkTask to allow creating relative symlinks, using the syntax: | ||
|
||
``` | ||
<symlink link="path/to/destination" target="path/to/target" relative="true" /> | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
diff --git a/classes/phing/tasks/ext/SymlinkTask.php b/classes/phing/tasks/ext/SymlinkTask.php | ||
index f132b4f747..87844a0d09 100644 | ||
--- a/classes/phing/tasks/ext/SymlinkTask.php | ||
+++ b/classes/phing/tasks/ext/SymlinkTask.php | ||
@@ -206,6 +206,46 @@ public function isRelative() | ||
return $this->relative; | ||
} | ||
|
||
+ /** | ||
+ * Given an existing path, convert it to a path relative to a given starting path. | ||
+ * | ||
+ * @param string $endPath Absolute path of target | ||
+ * @param string $startPath Absolute path where traversal begins | ||
+ * | ||
+ * @return string Path of target relative to starting path | ||
+ */ | ||
+ public function makePathRelative($endPath, $startPath) | ||
+ { | ||
+ // Normalize separators on Windows | ||
+ if ('\\' === DIRECTORY_SEPARATOR) { | ||
+ $endPath = str_replace('\\', '/', $endPath); | ||
+ $startPath = str_replace('\\', '/', $startPath); | ||
+ } | ||
+ | ||
+ // Split the paths into arrays | ||
+ $startPathArr = explode('/', trim($startPath, '/')); | ||
+ $endPathArr = explode('/', trim($endPath, '/')); | ||
+ | ||
+ // Find for which directory the common path stops | ||
+ $index = 0; | ||
+ while (isset($startPathArr[$index]) && isset($endPathArr[$index]) && $startPathArr[$index] === $endPathArr[$index]) { | ||
+ ++$index; | ||
+ } | ||
+ | ||
+ // Determine how deep the start path is relative to the common path (ie, "web/bundles" = 2 levels) | ||
+ $depth = count($startPathArr) - $index; | ||
+ | ||
+ // Repeated "../" for each level need to reach the common path | ||
+ $traverser = str_repeat('../', $depth); | ||
+ | ||
+ $endPathRemainder = implode('/', array_slice($endPathArr, $index)); | ||
+ | ||
+ // Construct $endPath from traversing to the common path, then to the remaining $endPath | ||
+ $relativePath = $traverser.('' !== $endPathRemainder ? $endPathRemainder.'/' : ''); | ||
+ | ||
+ return '' === $relativePath ? './' : $relativePath; | ||
+ } | ||
+ | ||
/** | ||
* Generates an array of directories / files to be linked | ||
* If _filesets is empty, returns getTarget() | ||
@@ -235,11 +275,7 @@ protected function getMap() | ||
throw new BuildException('Link must be an existing directory when using fileset'); | ||
} | ||
|
||
- if ($this->isRelative()) { | ||
- $fromDir = $fs->getDir($this->getProject())->getPath(); | ||
- } else { | ||
- $fromDir = $fs->getDir($this->getProject())->getAbsolutePath(); | ||
- } | ||
+ $fromDir = $fs->getDir($this->getProject())->getAbsolutePath(); | ||
|
||
if (!is_dir($fromDir)) { | ||
$this->log('Directory doesn\'t exist: ' . $fromDir, Project::MSG_WARN); | ||
@@ -300,6 +336,11 @@ protected function symlink($target, $link) | ||
{ | ||
$fs = FileSystem::getFileSystem(); | ||
|
||
+ if ($this->isRelative()) { | ||
+ $link =(new PhingFile($link))->getAbsolutePath(); | ||
+ $target = rtrim($this->makePathRelative($target, dirname($link)), '/'); | ||
+ } | ||
+ | ||
if (is_link($link) && @readlink($link) == $target) { | ||
$this->log('Link exists: ' . $link, Project::MSG_INFO); | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we add a README to the patches directory that explains where this patch comes from?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I went ahead and added a README.