adds new getGhcupConfFilePath fn to GHCup.hs, also refactors to use for error handling in missing file cases

This commit is contained in:
Arjun Kathuria 2021-06-23 10:10:28 +05:30
parent 2e3dceecf8
commit 118a2744fe
1 changed files with 16 additions and 28 deletions

View File

@ -1313,7 +1313,8 @@ rmTool ListResult {lVer, lTool, lCross} = do
rmGhcupDirs :: ( MonadReader AppState m rmGhcupDirs :: ( MonadReader AppState m
, MonadIO m , MonadIO m
, MonadLogger m) , MonadLogger m
, MonadCatch m )
=> m () => m ()
rmGhcupDirs = do rmGhcupDirs = do
dirs@Dirs dirs@Dirs
@ -1323,10 +1324,15 @@ rmGhcupDirs = do
, cacheDir , cacheDir
, confDir } <- asks dirs , confDir } <- asks dirs
let envDir = baseDir </> "env" let envFilePath = baseDir </> "env"
-- remove env Dir confFilePath <- getConfigFilePath
rmEnvDir envDir
-- remove env File
rmEnvFile envFilePath
-- remove the configFile file
rmConfFile confFilePath
-- remove entire cache Dir -- remove entire cache Dir
rmCacheDir cacheDir rmCacheDir cacheDir
@ -1334,43 +1340,25 @@ rmGhcupDirs = do
-- remove entire logs Dir -- remove entire logs Dir
rmLogsDir logsDir rmLogsDir logsDir
-- remove the $ghcupConfigDir/config.yaml file
rmConfFile confDir
liftIO $ print dirs liftIO $ print dirs
where where
rmEnvDir envDir = do rmEnvFile enFilePath = do
isEnvDirPresent <- liftIO $ doesDirectoryExist envDir $logInfo "Removing Ghcup Environment File"
hideError doesNotExistErrorType $ liftIO $ removeFile enFilePath
if isEnvDirPresent
then do
$logInfo "Removing Ghcup Environment Dir"
liftIO $ removeDirectory envDir
else
$logInfo "EnvDir Not Found, Skipping"
rmCacheDir cacheDir = do rmCacheDir cacheDir = do
$logInfo "removing ghcup cache Dir" $logInfo "removing ghcup cache Dir"
liftIO $ removeDirectory cacheDir liftIO $ removeDirectory cacheDir
rmLogsDir logsDir = do rmLogsDir logsDir = do
$logInfo "removing ghcup logs Dir" $logInfo "removing ghcup logs Dir"
liftIO $ removeDirectory logsDir liftIO $ removeDirectory logsDir
rmConfFile confDir = do rmConfFile confFilePath = do
let confPath = confDir </> "config.yaml" $logInfo "removing Ghcup Config File"
hideError doesNotExistErrorType $ liftIO $ removeFile confFilePath
exists <- liftIO $ doesFileExist confPath
if exists
then do
$logInfo "removing config.yaml"
liftIO $ removeFile confPath
else
$logInfo "no config file found, skipping."
------------------ ------------------
--[ Debug info ]-- --[ Debug info ]--