adds better error handling when removing files and dirs in rmGhcupDirs function
This commit is contained in:
parent
3b3dde8413
commit
33eaa765d7
21
lib/GHCup.hs
21
lib/GHCup.hs
@ -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 ]--
|
||||||
|
Loading…
Reference in New Issue
Block a user