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