From 05c194375e1726b725f453e47115ecb0e8c99a72 Mon Sep 17 00:00:00 2001 From: Cristhian Motoche Date: Wed, 15 Feb 2023 16:13:53 -0500 Subject: [PATCH] fix: Error on release path activation (#216) * fix: Change place where validation happens * chore: Change error message --- src/System/Hapistrano.hs | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/src/System/Hapistrano.hs b/src/System/Hapistrano.hs index 3d3929ba..ec6d1080 100644 --- a/src/System/Hapistrano.hs +++ b/src/System/Hapistrano.hs @@ -120,14 +120,10 @@ activateRelease -> Hapistrano () activateRelease ts deployPath release = do rpath <- releasePath deployPath release Nothing - isRpathExist <- doesDirExist rpath - if isRpathExist then do - let tpath = tempSymlinkPath deployPath - cpath = currentSymlinkPath deployPath - exec (Ln ts rpath tpath) (Just release) -- create a symlink for the new candidate - exec (Mv ts tpath cpath) (Just release) -- atomically replace the symlink - else - failWith 1 (Just $ "The release path '" <> show rpath <> "' cannot be activated.") (Just release) + let tpath = tempSymlinkPath deployPath + cpath = currentSymlinkPath deployPath + exec (Ln ts rpath tpath) (Just release) -- create a symlink for the new candidate + exec (Mv ts tpath cpath) (Just release) -- atomically replace the symlink -- | Creates the file @.hapistrano__state@ containing -- @fail@ or @success@ depending on how the deployment ended. @@ -209,7 +205,12 @@ rollback ts deployPath n mbRestartCommand = do releases <- releasesWithState Success deployPath case genericDrop n releases of [] -> failWith 1 (Just "Could not find the requested release to rollback to.") Nothing - (x:_) -> activateRelease ts deployPath x + (x:_) -> do + rpath <- releasePath deployPath x Nothing + isRpathExist <- doesDirExist rpath + if isRpathExist + then activateRelease ts deployPath x + else failWith 1 (Just $ "Cannot rollback to the release path '" <> show rpath <> "'.") (Just x) forM_ mbRestartCommand (`exec` Nothing) -- | Remove older releases to avoid filling up the target host filesystem.