From 3a41a860d055bd582949f4fdd2b4322ac6ffb6ab Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=90=D0=BD=D0=B4=D1=80=D0=B5=D0=B9=20=D0=9A=D0=BE=D0=BB?= =?UTF-8?q?=D1=87=D0=B5=D0=BD=D0=BA=D0=BE?= Date: Wed, 5 Nov 2014 17:16:55 +0300 Subject: [PATCH] Make target dir before invoking "ln". Fix bug with spaces in path. --- .../Filesystem/LinkSharedFilesTask.php | 28 +++++++++---------- 1 file changed, 13 insertions(+), 15 deletions(-) diff --git a/Mage/Task/BuiltIn/Filesystem/LinkSharedFilesTask.php b/Mage/Task/BuiltIn/Filesystem/LinkSharedFilesTask.php index 2276cca..714b424 100644 --- a/Mage/Task/BuiltIn/Filesystem/LinkSharedFilesTask.php +++ b/Mage/Task/BuiltIn/Filesystem/LinkSharedFilesTask.php @@ -4,6 +4,7 @@ namespace Mage\Task\BuiltIn\Filesystem; use Mage\Task\AbstractTask; use Mage\Task\Releases\IsReleaseAware; use Mage\Task\SkipException; +use Symfony\Component\Filesystem\Filesystem; /** * Class LinkSharedFilesTask @@ -70,26 +71,23 @@ class LinkSharedFilesTask extends AbstractTask implements IsReleaseAware throw new SkipException('No files and folders configured for sym-linking.'); } - $sharedFolderName = $this->getParameter('shared', 'shared'); - $sharedFolderPath = rtrim($this->getConfig()->deployment('to'), '/') . '/' . $sharedFolderName; - $releasesDirectory = $this->getConfig()->release('directory', 'releases'); - $releasesDirectoryPath = rtrim($this->getConfig()->deployment('to'), '/') . '/' . $releasesDirectory; - + $remoteDirectory = rtrim($this->getConfig()->deployment('to'), '/') . '/'; + $sharedFolderPath = $remoteDirectory . $this->getParameter('shared', 'shared'); + $releasesDirectoryPath = $remoteDirectory . $this->getConfig()->release('directory', 'releases'); $currentCopy = $releasesDirectoryPath . '/' . $this->getConfig()->getReleaseId(); - $relativeDiffPath = str_replace($this->getConfig()->deployment('to'), '', $currentCopy) . '/'; + $fileSystem = new Filesystem(); foreach ($linkedEntities as $ePath) { list($entityPath, $strategy) = $this->getPath($ePath); - $sharedEntityLinkedPath = "$sharedFolderPath/$entityPath"; - if ($strategy == self::RELATIVE_LINKING) { - $parentFolderPath = dirname($entityPath); - $relativePath = $parentFolderPath == '.' ? $relativeDiffPath : $relativeDiffPath . $parentFolderPath . '/'; - $sharedEntityLinkedPath = ltrim( - preg_replace('/(\w+\/)/', '../', $relativePath), - '/' - ) . $sharedFolderName . '/' . $entityPath; + if ($strategy === self::RELATIVE_LINKING) { + $dirName = dirname($currentCopy . '/' . $entityPath); + $target = $fileSystem->makePathRelative($sharedFolderPath, $dirName) . $entityPath; + } else { + $target = $sharedFolderPath . '/' . $entityPath; } - $command = "ln -nfs $sharedEntityLinkedPath $currentCopy/$entityPath"; + $command = 'mkdir -p ' . escapeshellarg(dirname($target)); + $this->runCommandRemote($command); + $command = 'ln -nfs ' . escapeshellarg($target) . ' ' . escapeshellarg($currentCopy . '/' . $entityPath); $this->runCommandRemote($command); }