From 118a2744fe0efab6e415600f5a37d47476ff6a6c Mon Sep 17 00:00:00 2001 From: Arjun Kathuria Date: Wed, 23 Jun 2021 10:10:28 +0530 Subject: [PATCH] adds new getGhcupConfFilePath fn to GHCup.hs, also refactors to use for error handling in missing file cases --- lib/GHCup.hs | 44 ++++++++++++++++---------------------------- 1 file changed, 16 insertions(+), 28 deletions(-) diff --git a/lib/GHCup.hs b/lib/GHCup.hs index 857267b..13d722f 100644 --- a/lib/GHCup.hs +++ b/lib/GHCup.hs @@ -1313,7 +1313,8 @@ rmTool ListResult {lVer, lTool, lCross} = do rmGhcupDirs :: ( MonadReader AppState m , MonadIO m - , MonadLogger m) + , MonadLogger m + , MonadCatch m ) => m () rmGhcupDirs = do dirs@Dirs @@ -1323,10 +1324,15 @@ rmGhcupDirs = do , cacheDir , confDir } <- asks dirs - let envDir = baseDir "env" + let envFilePath = baseDir "env" - -- remove env Dir - rmEnvDir envDir + confFilePath <- getConfigFilePath + + -- remove env File + rmEnvFile envFilePath + +-- remove the configFile file + rmConfFile confFilePath -- remove entire cache Dir rmCacheDir cacheDir @@ -1334,43 +1340,25 @@ rmGhcupDirs = do -- remove entire logs Dir rmLogsDir logsDir - -- remove the $ghcupConfigDir/config.yaml file - rmConfFile confDir - liftIO $ print dirs where - rmEnvDir envDir = do - isEnvDirPresent <- liftIO $ doesDirectoryExist envDir - - if isEnvDirPresent - then do - $logInfo "Removing Ghcup Environment Dir" - liftIO $ removeDirectory envDir - else - $logInfo "EnvDir Not Found, Skipping" + rmEnvFile enFilePath = do + $logInfo "Removing Ghcup Environment File" + hideError doesNotExistErrorType $ liftIO $ removeFile enFilePath rmCacheDir cacheDir = do $logInfo "removing ghcup cache Dir" liftIO $ removeDirectory cacheDir - rmLogsDir logsDir = do $logInfo "removing ghcup logs Dir" liftIO $ removeDirectory logsDir - rmConfFile confDir = do - let confPath = confDir "config.yaml" - - exists <- liftIO $ doesFileExist confPath - - if exists - then do - $logInfo "removing config.yaml" - liftIO $ removeFile confPath - else - $logInfo "no config file found, skipping." + rmConfFile confFilePath = do + $logInfo "removing Ghcup Config File" + hideError doesNotExistErrorType $ liftIO $ removeFile confFilePath ------------------ --[ Debug info ]--