module Main where import System.Posix.Directory ( getWorkingDirectory ) import System.Directory ( pathIsSymbolicLink, doesFileExist, getFileSize, doesDirectoryExist ) import Data.Functor ( (<&>) ) import Control.Monad ( filterM ) import System.Directory.Extra ( listContents ) import Brick listNonSymFiles :: FilePath -> IO [FilePath] listNonSymFiles dir = filterM (fmap not . pathIsSymbolicLink) =<< filterM doesFileExist =<< listContents dir listNonSymDirectories :: FilePath -> IO [FilePath] listNonSymDirectories dir = filterM (fmap not . pathIsSymbolicLink) =<< filterM doesDirectoryExist =<< listContents dir 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 =<< getSizeSubpaths a