Make target dir before invoking "ln".

Fix bug with spaces in path.
This commit is contained in:
Андрей Колченко 2014-11-05 17:16:55 +03:00
parent 9d30900798
commit 3a41a860d0

View file

@ -4,6 +4,7 @@ namespace Mage\Task\BuiltIn\Filesystem;
use Mage\Task\AbstractTask; use Mage\Task\AbstractTask;
use Mage\Task\Releases\IsReleaseAware; use Mage\Task\Releases\IsReleaseAware;
use Mage\Task\SkipException; use Mage\Task\SkipException;
use Symfony\Component\Filesystem\Filesystem;
/** /**
* Class LinkSharedFilesTask * Class LinkSharedFilesTask
@ -70,26 +71,23 @@ class LinkSharedFilesTask extends AbstractTask implements IsReleaseAware
throw new SkipException('No files and folders configured for sym-linking.'); throw new SkipException('No files and folders configured for sym-linking.');
} }
$sharedFolderName = $this->getParameter('shared', 'shared'); $remoteDirectory = rtrim($this->getConfig()->deployment('to'), '/') . '/';
$sharedFolderPath = rtrim($this->getConfig()->deployment('to'), '/') . '/' . $sharedFolderName; $sharedFolderPath = $remoteDirectory . $this->getParameter('shared', 'shared');
$releasesDirectory = $this->getConfig()->release('directory', 'releases'); $releasesDirectoryPath = $remoteDirectory . $this->getConfig()->release('directory', 'releases');
$releasesDirectoryPath = rtrim($this->getConfig()->deployment('to'), '/') . '/' . $releasesDirectory;
$currentCopy = $releasesDirectoryPath . '/' . $this->getConfig()->getReleaseId(); $currentCopy = $releasesDirectoryPath . '/' . $this->getConfig()->getReleaseId();
$relativeDiffPath = str_replace($this->getConfig()->deployment('to'), '', $currentCopy) . '/'; $fileSystem = new Filesystem();
foreach ($linkedEntities as $ePath) { foreach ($linkedEntities as $ePath) {
list($entityPath, $strategy) = $this->getPath($ePath); list($entityPath, $strategy) = $this->getPath($ePath);
$sharedEntityLinkedPath = "$sharedFolderPath/$entityPath"; if ($strategy === self::RELATIVE_LINKING) {
if ($strategy == self::RELATIVE_LINKING) { $dirName = dirname($currentCopy . '/' . $entityPath);
$parentFolderPath = dirname($entityPath); $target = $fileSystem->makePathRelative($sharedFolderPath, $dirName) . $entityPath;
$relativePath = $parentFolderPath == '.' ? $relativeDiffPath : $relativeDiffPath . $parentFolderPath . '/'; } else {
$sharedEntityLinkedPath = ltrim( $target = $sharedFolderPath . '/' . $entityPath;
preg_replace('/(\w+\/)/', '../', $relativePath),
'/'
) . $sharedFolderName . '/' . $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); $this->runCommandRemote($command);
} }