From 61019ecd49d7b3f89f83fcb872967af4598c5cda Mon Sep 17 00:00:00 2001 From: Arjun Kathuria Date: Tue, 29 Jun 2021 14:31:13 +0530 Subject: [PATCH] Adds reporting remaining leftover files sorted by Depth. --- lib/GHCup.hs | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/lib/GHCup.hs b/lib/GHCup.hs index 0a380fc..1c1ce27 100644 --- a/lib/GHCup.hs +++ b/lib/GHCup.hs @@ -1437,10 +1437,22 @@ rmGhcupDirs = do reportRemainingFiles ghcupDir = do remainingFiles <- liftIO $ getDirectoryContentsRecursive ghcupDir - remainingFilesAbsolute <- makePathsAbsolute remainingFiles + let normalizedFilePaths = fmap normalise remainingFiles + let sortedByDepthRemainingFiles = reverse $ sortBy compareFn normalizedFilePaths + remainingFilesAbsolute <- makePathsAbsolute sortedByDepthRemainingFiles + pure remainingFilesAbsolute - makePathsAbsolute paths = liftIO $ traverse makeAbsolute paths + where + calcDepth :: FilePath -> Int + calcDepth = length . filter isPathSeparator + + compareFn :: FilePath -> FilePath -> Ordering + compareFn fp1 fp2 = compare (calcDepth fp1) (calcDepth fp2) + + makePathsAbsolute :: (MonadIO m) => [FilePath] -> m [FilePath] + makePathsAbsolute paths = liftIO $ + traverse (makeAbsolute . normalise) paths -- we expect only files inside cache/log dir -- we report remaining files/dirs later,