From 3b3dde8413d5cc609924b24e6608636f5f13e6ee Mon Sep 17 00:00:00 2001 From: Arjun Kathuria Date: Wed, 23 Jun 2021 10:36:17 +0530 Subject: [PATCH] updates deleting dirs in rmGhcupDirs according to feedback on merge request --- lib/GHCup.hs | 37 +++++++++++++++++++++++++++++-------- 1 file changed, 29 insertions(+), 8 deletions(-) diff --git a/lib/GHCup.hs b/lib/GHCup.hs index 13d722f..08c648e 100644 --- a/lib/GHCup.hs +++ b/lib/GHCup.hs @@ -1348,18 +1348,39 @@ rmGhcupDirs = 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 confFilePath = do $logInfo "removing Ghcup Config File" hideError doesNotExistErrorType $ liftIO $ removeFile confFilePath + rmCacheDir cacheDir = do + $logInfo "removing ghcup cache Dir" + contents <- liftIO $ listDirectory cacheDir + forM_ contents removeIfFile + removeDirIfEmpty cacheDir + + rmLogsDir logsDir = do + $logInfo "removing ghcup logs Dir" + contents <- liftIO $ listDirectory logsDir + forM_ contents removeIfFile + removeDirIfEmpty logsDir + + removeIfFile filepath = do + isFile <- checkIfSymlink filepath + isSymlink <- checkIfRegularFile filepath + + if isFile && not isSymlink + then liftIO $ removeFile filepath + else pure () + + checkIfSymlink filepath = + liftIO $ pathIsSymbolicLink filepath + + checkIfRegularFile filepath = + liftIO $ doesFileExist filepath + + removeDirIfEmpty filepath = + liftIO $ removeDirectory filepath + ------------------ --[ Debug info ]-- ------------------