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

View File

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