From f8448cf02b20e4d6a694fdfeefaeb36c981c6f16 Mon Sep 17 00:00:00 2001 From: Julian Ospald Date: Tue, 17 Mar 2020 19:16:21 +0100 Subject: [PATCH] Make sure directories exist --- app/ghcup/Main.hs | 8 ++++---- lib/GHCup/Download.hs | 10 ++++------ 2 files changed, 8 insertions(+), 10 deletions(-) diff --git a/app/ghcup/Main.hs b/app/ghcup/Main.hs index 4483bf3..e4ccd50 100644 --- a/app/ghcup/Main.hs +++ b/app/ghcup/Main.hs @@ -493,6 +493,10 @@ main = do >>= \opt@Options {..} -> do let settings = toSettings opt + -- create ~/.ghcup dir + ghcdir <- ghcupBaseDir + createDirIfMissing newDirPerms ghcdir + -- logger interpreter logfile <- initGHCupFileLogging [rel|ghcup.log|] let runLogger = myLoggerT LoggerConfig @@ -588,10 +592,6 @@ main = do , DownloadFailed ] - -- create ~/.ghcup dir - ghcdir <- ghcupBaseDir - createDirIfMissing newDirPerms ghcdir - dls <- ( runLogger . flip runReaderT settings diff --git a/lib/GHCup/Download.hs b/lib/GHCup/Download.hs index 7e15f4f..bbf2428 100644 --- a/lib/GHCup/Download.hs +++ b/lib/GHCup/Download.hs @@ -135,13 +135,10 @@ getDownloads urlSource = do L.ByteString smartDl uri' = do let path = view pathL' uri' - json_file <- (liftIO $ ghcupCacheDir) - >>= \cacheDir -> (cacheDir ) <$> urlBaseName path + cacheDir <- liftIO $ ghcupCacheDir + json_file <- (cacheDir ) <$> urlBaseName path e <- - liftIO - $ HIO.handleIOError - (\e -> if isDoesNotExistError e then pure False else throwIO e) - $ doesFileExist json_file + liftIO $ doesFileExist json_file if e then do accessTime <- @@ -168,6 +165,7 @@ getDownloads urlSource = do else -- access in less than 5 minutes, re-use file liftIO $ readFile json_file else do + liftIO $ createDirIfMissing newDirPerms cacheDir getModTime >>= \case Just modTime -> do bs <- liftE $ downloadBS uri'