From 59519febbc18d8691666b17611ca2ed4bebde38e Mon Sep 17 00:00:00 2001 From: Arjun Kathuria Date: Sat, 26 Jun 2021 19:52:32 +0530 Subject: [PATCH] handle symlink case when deleting directories in rmGhcupDirs --- lib/GHCup.hs | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/lib/GHCup.hs b/lib/GHCup.hs index b35c692..0648079 100644 --- a/lib/GHCup.hs +++ b/lib/GHCup.hs @@ -1381,19 +1381,19 @@ rmGhcupDirs = do $logInfo "removing ghcup cache Dir" contents <- liftIO $ listDirectory cacheDir forM_ contents deleteFile - removeDirIfEmpty cacheDir + removeDirIfEmptyOrIsSymlink cacheDir rmLogsDir logsDir = do $logInfo "removing ghcup logs Dir" contents <- liftIO $ listDirectory logsDir forM_ contents deleteFile - removeDirIfEmpty logsDir + removeDirIfEmptyOrIsSymlink logsDir rmBinDir binDir = do #if !defined(IS_WINDOWS) isXDGStyle <- liftIO $ useXDG if not isXDGStyle - then removeDirIfEmpty binDir + then removeDirIfEmptyOrIsSymlink binDir else pure () #else removeDirIfEmpty binDir @@ -1402,8 +1402,17 @@ rmGhcupDirs = do deleteFile filepath = do hideError InappropriateType $ rmFile filepath - removeDirIfEmpty filepath = - hideError UnsatisfiedConstraints $ liftIO $ removeDirectory filepath + removeDirIfEmptyOrIsSymlink filepath = + hideError UnsatisfiedConstraints $ + handleIO' InappropriateType + (handleIfSym filepath) + (liftIO $ removeDirectory filepath) + where + handleIfSym fp e = do + isSym <- liftIO $ pathIsSymbolicLink fp + if isSym + then liftIO $ deleteFile fp + else liftIO $ ioError e ------------------ --[ Debug info ]--