diff --git a/src/Control/Monad/Buuka.hs b/src/Control/Monad/Buuka.hs index 075e859..916da2a 100644 --- a/src/Control/Monad/Buuka.hs +++ b/src/Control/Monad/Buuka.hs @@ -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