Skip to content

Commit

Permalink
fix: Error on release path activation (#216)
Browse files Browse the repository at this point in the history
* fix: Change place where validation happens

* chore: Change error message
  • Loading branch information
CristhianMotoche authored Feb 15, 2023
1 parent dcd5938 commit 05c1943
Showing 1 changed file with 10 additions and 9 deletions.
19 changes: 10 additions & 9 deletions src/System/Hapistrano.hs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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.
Expand Down

0 comments on commit 05c1943

Please sign in to comment.