From 95b7cf36aa13d85c1d5509bf7183756f6ca8b11b Mon Sep 17 00:00:00 2001 From: pingu Date: Fri, 13 Oct 2023 15:54:57 +0200 Subject: [PATCH] =?UTF-8?q?^=E3=85=82^?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/Main.hs | 28 +++++++++++++--------------- 1 file changed, 13 insertions(+), 15 deletions(-) diff --git a/app/Main.hs b/app/Main.hs index 69483ae..94d6ee9 100644 --- a/app/Main.hs +++ b/app/Main.hs @@ -1,29 +1,27 @@ module Main where -import System.Posix.Types () -import System.Posix.Files () import System.Posix.Directory ( getWorkingDirectory ) import System.Directory ( pathIsSymbolicLink, doesFileExist, getFileSize, doesDirectoryExist ) -import System.Environment () import Data.Functor ( (<&>) ) -import Control.Monad ( (<=<), filterM ) +import Control.Monad ( filterM ) import System.Directory.Extra ( listContents ) +import Brick -listFiles :: FilePath -> IO [FilePath] -listFiles dir = filterM ((return . not) <=< pathIsSymbolicLink) =<< filterM doesFileExist =<< listContents dir +listNonSymFiles :: FilePath -> IO [FilePath] +listNonSymFiles dir = filterM (fmap not . pathIsSymbolicLink) =<< filterM doesFileExist =<< listContents dir -listDirectories :: FilePath -> IO [FilePath] -listDirectories dir = filterM ((return . not) <=< pathIsSymbolicLink) =<< filterM doesDirectoryExist =<< listContents dir +listNonSymDirectories :: FilePath -> IO [FilePath] +listNonSymDirectories dir = filterM (fmap not . pathIsSymbolicLink) =<< filterM doesDirectoryExist =<< listContents dir -getAllSubpaths :: FilePath -> IO [(FilePath, Integer)] -getAllSubpaths x = do - sub <- listDirectories x - subFiles <- mapM getAllSubpaths sub - local <- listFiles x >>= (\y -> mapM getFileSize y <&> zip y) - return $ local ++ concat subFiles +getSizeSubpaths :: FilePath -> IO [(FilePath, Integer)] +getSizeSubpaths x = do + sub <- listNonSymDirectories x + subby <- mapM (\y -> (y,) . sum . map snd <$> getSizeSubpaths y) sub + local <- listNonSymFiles x >>= (\y -> mapM getFileSize y <&> zip y) + return $ local ++ subby main :: IO () main = do a <- getWorkingDirectory - print =<< getAllSubpaths a + print =<< getSizeSubpaths a