Find directory if missing

This commit is contained in:
Mats Rauhala 2021-01-01 08:00:39 +02:00
parent e741d7fd59
commit 32afc6ba29

View File

@ -25,7 +25,7 @@ import Control.Monad.State
import UnliftIO import UnliftIO
(MonadUnliftIO(..)) (MonadUnliftIO(..))
import UnliftIO.Directory import UnliftIO.Directory
(copyFile) (copyFile, createDirectoryIfMissing)
import UnliftIO.Temporary import UnliftIO.Temporary
(withSystemTempDirectory) (withSystemTempDirectory)
@ -44,7 +44,9 @@ newtype BuukaM a = BuukaM (ReaderT Environment IO a)
) )
runBuukaM :: Environment -> BuukaM a -> IO a runBuukaM :: Environment -> BuukaM a -> IO a
runBuukaM env (BuukaM f) = runReaderT f env runBuukaM env (BuukaM f) = do
createDirectoryIfMissing True (workdir env)
runReaderT f env
data DecodeException data DecodeException
= YamlParseException ParseException = YamlParseException ParseException
@ -56,7 +58,7 @@ buukaQ :: BuukaQ a -> BuukaM a
buukaQ q = do buukaQ q = do
w <- asks workdir w <- asks workdir
decoded <- (decode <$> liftIO (B.readFile (w </> "buuka.yaml"))) `catch` handleNotFound decoded <- (decode <$> liftIO (B.readFile (w </> "buuka.yaml"))) `catch` handleNotFound
either (throwM) (pure . runReader (runBuukaQ q)) decoded either throwM (pure . runReader (runBuukaQ q)) decoded
where where
handleNotFound IOError{ioe_type = NoSuchThing} = pure (Right mempty) handleNotFound IOError{ioe_type = NoSuchThing} = pure (Right mempty)
handleNotFound e = throwM e handleNotFound e = throwM e