Skip to content

Commit 6df5bf4

Browse files
committed
Merge pull request #132 from vs7/master
added compatible windows-linux relative symlinks
2 parents da59990 + 732889b commit 6df5bf4

File tree

1 file changed

+23
-9
lines changed
  • src/MagentoHackathon/Composer/Magento/Deploystrategy

1 file changed

+23
-9
lines changed

src/MagentoHackathon/Composer/Magento/Deploystrategy/Symlink.php

Lines changed: 23 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ public function createDelegate($source, $dest)
7979
} else {
8080
$destPath .= '/' . basename($source);
8181
}
82-
return $this->create($source, substr($destPath, strlen($this->getDestDir())+1));
82+
return $this->create($source, substr($destPath, strlen($this->getDestDir()) + 1));
8383
}
8484

8585
// From now on $destPath can't be a directory, that case is already handled
@@ -94,14 +94,11 @@ public function createDelegate($source, $dest)
9494
}
9595
}
9696

97-
// Windows doesn't allow relative symlinks
98-
if (strtoupper(substr(PHP_OS, 0, 3)) !== 'WIN') {
99-
$sourcePath = $this->getRelativePath($destPath, $sourcePath);
100-
}
97+
$relSourcePath = $this->getRelativePath($destPath, $sourcePath);
10198

10299
// Create symlink
103-
if(false === symlink($sourcePath, $destPath)) {
104-
throw new \ErrorException("An error occured while creating symlink" . $sourcePath);
100+
if (false === $this->_symlink($relSourcePath, $destPath, $sourcePath)) {
101+
throw new \ErrorException("An error occured while creating symlink" . $relSourcePath);
105102
}
106103

107104
// Check we where able to create the symlink
@@ -112,6 +109,17 @@ public function createDelegate($source, $dest)
112109
return true;
113110
}
114111

112+
protected function _symlink($relSourcePath, $destPath, $absSourcePath)
113+
{
114+
if (strtoupper(substr(PHP_OS, 0, 3)) == 'WIN') {
115+
$relSourcePath = str_replace('/', '\\', $relSourcePath);
116+
$param = is_dir($absSourcePath) ? ' /D' : '';
117+
exec('mklink' . $param . ' "' . $destPath . '" "' . $relSourcePath . '"');
118+
} else {
119+
symlink($relSourcePath, $destPath);
120+
}
121+
}
122+
115123
/**
116124
* Returns the relative path from $from to $to
117125
*
@@ -121,10 +129,16 @@ public function createDelegate($source, $dest)
121129
public function getRelativePath($from, $to)
122130
{
123131
// Can't use realpath() here since the destination doesn't exist yet
124-
$from = str_replace(array('/./', '//'), '/', $from);
125-
$from = explode('/', $from);
132+
$from = is_dir($from) ? rtrim($from, '\/') . '/' : $from;
133+
$to = is_dir($to) ? rtrim($to, '\/') . '/' : $to;
134+
135+
$from = str_replace('\\', '/', $from);
136+
$to = str_replace('\\', '/', $to);
126137

138+
$from = str_replace(array('/./', '//'), '/', $from);
127139
$to = str_replace(array('/./', '//'), '/', $to);
140+
141+
$from = explode('/', $from);
128142
$to = explode('/', $to);
129143

130144
$relPath = $to;

0 commit comments

Comments
 (0)