From 4e17263773ea06b64aa6c191ec0875adfaaf43d9 Mon Sep 17 00:00:00 2001 From: Stefan Paletta Date: Fri, 9 Jan 2015 17:27:14 +0100 Subject: [PATCH] =?UTF-8?q?switch=20the=20=C2=BBcurrent=C2=AB=20symlink=20?= =?UTF-8?q?in=20an=20atomic=20way?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Mage/Task/BuiltIn/Deployment/ReleaseTask.php | 7 ++++--- Mage/Task/BuiltIn/Releases/RollbackTask.php | 6 ++++-- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/Mage/Task/BuiltIn/Deployment/ReleaseTask.php b/Mage/Task/BuiltIn/Deployment/ReleaseTask.php index 84187ad..e7baf30 100644 --- a/Mage/Task/BuiltIn/Deployment/ReleaseTask.php +++ b/Mage/Task/BuiltIn/Deployment/ReleaseTask.php @@ -75,9 +75,10 @@ class ReleaseTask extends AbstractTask implements IsReleaseAware, SkipOnOverride } // Remove symlink if exists; create new symlink and change owners - $command = 'rm -f ' . $symlink - . ' ; ' - . 'ln -sf ' . $currentCopy . ' ' . $symlink; + $tmplink = $currentCopy . '.tmp'; + $command = 'ln -sfn ' . $currentCopy . ' ' . $tmplink + . ' && ' + . 'mv -T ' . $tmplink . ' ' . $symlink; if ($resultFetch && $userGroup != '') { $command .= ' && ' diff --git a/Mage/Task/BuiltIn/Releases/RollbackTask.php b/Mage/Task/BuiltIn/Releases/RollbackTask.php index 7a437fd..1aff8e3 100644 --- a/Mage/Task/BuiltIn/Releases/RollbackTask.php +++ b/Mage/Task/BuiltIn/Releases/RollbackTask.php @@ -127,9 +127,11 @@ class RollbackTask extends AbstractTask implements IsReleaseAware $userGroup = ''; $resultFetch = $this->runCommandRemote('ls -ld ' . $rollbackTo . ' | awk \'{print \$3":"\$4}\'', $userGroup); - $command = 'rm -f ' . $symlink + + $tmplink = $rollbackTo . '.tmp'; + $command = 'ln -sfn ' . $currentCopy . ' ' . $tmplink . ' && ' - . 'ln -sf ' . $rollbackTo . ' ' . $symlink; + . 'mv -T ' . $tmplink . ' ' . $symlink; if ($resultFetch) { $command .= ' && chown -h ' . $userGroup . ' ' . $symlink;