adds better error handling when removing files and dirs in rmGhcupDirs function

This commit is contained in:
Arjun Kathuria 2021-06-23 23:23:54 +05:30
parent 3b3dde8413
commit 33eaa765d7
1 changed files with 5 additions and 16 deletions

View File

@ -1355,31 +1355,20 @@ rmGhcupDirs = do
rmCacheDir cacheDir = do rmCacheDir cacheDir = do
$logInfo "removing ghcup cache Dir" $logInfo "removing ghcup cache Dir"
contents <- liftIO $ listDirectory cacheDir contents <- liftIO $ listDirectory cacheDir
forM_ contents removeIfFile forM_ contents deleteFile
removeDirIfEmpty cacheDir removeDirIfEmpty cacheDir
rmLogsDir logsDir = do rmLogsDir logsDir = do
$logInfo "removing ghcup logs Dir" $logInfo "removing ghcup logs Dir"
contents <- liftIO $ listDirectory logsDir contents <- liftIO $ listDirectory logsDir
forM_ contents removeIfFile forM_ contents deleteFile
removeDirIfEmpty logsDir removeDirIfEmpty logsDir
removeIfFile filepath = do deleteFile filepath = do
isFile <- checkIfSymlink filepath hideError InappropriateType $ liftIO $ removeFile 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 = removeDirIfEmpty filepath =
liftIO $ removeDirectory filepath hideError UnsatisfiedConstraints $ liftIO $ removeDirectory filepath
------------------ ------------------
--[ Debug info ]-- --[ Debug info ]--