From 33eaa765d79cf4e41a8383e38cc6ad9a06740843 Mon Sep 17 00:00:00 2001 From: Arjun Kathuria Date: Wed, 23 Jun 2021 23:23:54 +0530 Subject: [PATCH] adds better error handling when removing files and dirs in rmGhcupDirs function --- lib/GHCup.hs | 21 +++++---------------- 1 file changed, 5 insertions(+), 16 deletions(-) diff --git a/lib/GHCup.hs b/lib/GHCup.hs index 08c648e..0143b6e 100644 --- a/lib/GHCup.hs +++ b/lib/GHCup.hs @@ -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 ]--