diff options
| author | Joey Hess <joeyh@joeyh.name> | 2016-03-06 18:03:50 -0400 |
|---|---|---|
| committer | Joey Hess <joeyh@joeyh.name> | 2016-03-06 18:09:49 -0400 |
| commit | 7899f23d991aa901c110b5bf276c0c7fb165799a (patch) | |
| tree | b0d8ca6792564c5b9c4302c2cb0f08f02d4f0d94 /src/Propellor | |
| parent | 03f90d23747e7c5291a4a4d044ed46aa5872fb55 (diff) | |
refactor and propigate failure after re-running propellor
Diffstat (limited to 'src/Propellor')
| -rw-r--r-- | src/Propellor/CmdLine.hs | 25 |
1 files changed, 17 insertions, 8 deletions
diff --git a/src/Propellor/CmdLine.hs b/src/Propellor/CmdLine.hs index a0ae9cb5..5e6769c9 100644 --- a/src/Propellor/CmdLine.hs +++ b/src/Propellor/CmdLine.hs @@ -149,6 +149,9 @@ unknownhost h hosts = errorMessage $ unlines , "Known hosts: " ++ unwords (map hostName hosts) ] +-- Builds propellor (when allowed) and if it looks like a new binary, +-- re-execs it to continue. +-- Otherwise, runs the IO action to continue. buildFirst :: CanRebuild -> CmdLine -> IO () -> IO () buildFirst CanRebuild cmdline next = do oldtime <- getmtime @@ -156,14 +159,20 @@ buildFirst CanRebuild cmdline next = do newtime <- getmtime if newtime == oldtime then next - else void $ boolSystem "./propellor" - [ Param "--continue" - , Param (show cmdline) - ] + else continueAfterBuild cmdline where getmtime = catchMaybeIO $ getModificationTime "propellor" buildFirst NoRebuild _ next = next +continueAfterBuild :: CmdLine -> IO a +continueAfterBuild cmdline = go =<< boolSystem "./propellor" + [ Param "--continue" + , Param (show cmdline) + ] + where + go True = exitSuccess + go False = exitWith (ExitFailure 1) + fetchFirst :: IO () -> IO () fetchFirst next = do whenM hasOrigin $ @@ -176,14 +185,14 @@ updateFirst canrebuild cmdline next = ifM hasOrigin , next ) +-- If changes can be fetched from origin, Builds propellor (when allowed) +-- and re-execs the updated propellor binary to continue. +-- Otherwise, runs the IO action to continue. updateFirst' :: CanRebuild -> CmdLine -> IO () -> IO () updateFirst' CanRebuild cmdline next = ifM fetchOrigin ( do buildPropellor - void $ boolSystem "./propellor" - [ Param "--continue" - , Param (show cmdline) - ] + continueAfterBuild cmdline , next ) updateFirst' NoRebuild _ next = next |
