Find directory if missing

This commit is contained in:
Mats Rauhala 2021-01-01 08:00:39 +02:00
parent e741d7fd59
commit 32afc6ba29
1 changed files with 5 additions and 3 deletions

View File

@ -25,7 +25,7 @@ import Control.Monad.State
import UnliftIO
(MonadUnliftIO(..))
import UnliftIO.Directory
(copyFile)
(copyFile, createDirectoryIfMissing)
import UnliftIO.Temporary
(withSystemTempDirectory)
@ -44,7 +44,9 @@ newtype BuukaM a = BuukaM (ReaderT Environment 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
= YamlParseException ParseException
@ -56,7 +58,7 @@ buukaQ :: BuukaQ a -> BuukaM a
buukaQ q = do
w <- asks workdir
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
handleNotFound IOError{ioe_type = NoSuchThing} = pure (Right mempty)
handleNotFound e = throwM e