From 20a3246bc8df700423f27f6baa54596290747c5c Mon Sep 17 00:00:00 2001 From: Andrew Cady Date: Mon, 12 Oct 2020 15:35:28 -0400 Subject: factor --- fsmgr.hs | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/fsmgr.hs b/fsmgr.hs index 00f840b..890064d 100644 --- a/fsmgr.hs +++ b/fsmgr.hs @@ -220,6 +220,11 @@ readFileOptional f = IO.doesFileExist f >>= \case True -> readFile f False -> return "" +copyParentDevices :: FilePath -> FilePath -> Action () +copyParentDevices parent out = do + devices <- either (const []) lines . readEither <$> liftIO (readFileOptional (parent <.> "devices.txt")) + writeFile' (out -<.> "devices.txt") (unlines $ parent:devices) + buildInitialImage :: DiskImageConfig -> FilePath -> FilePath -> Action () buildInitialImage DiskImageConfig{..} mountpoint out = do case initialImage of @@ -241,8 +246,7 @@ buildInitialImage DiskImageConfig{..} mountpoint out = do let parent = f -<.> "seed.btrfs" need [parent] - devices <- either (const []) lines . readEither <$> liftIO (readFileOptional (parent <.> "devices.txt")) - writeFile' (out -<.> "devices.txt") (unlines $ parent:devices) + copyParentDevices parent out -- allocate new image file cmd_ "rm -f" [out] -- cgit v1.2.3