From 7899f23d991aa901c110b5bf276c0c7fb165799a Mon Sep 17 00:00:00 2001 From: Joey Hess Date: Sun, 6 Mar 2016 18:03:50 -0400 Subject: refactor and propigate failure after re-running propellor --- src/Propellor/CmdLine.hs | 25 +++++++++++++++++-------- 1 file changed, 17 insertions(+), 8 deletions(-) (limited to 'src/Propellor') 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 -- cgit v1.2.3