This commit is contained in:
pingu 2023-10-13 15:54:57 +02:00
parent bdd857e491
commit 95b7cf36aa

View File

@ -1,29 +1,27 @@
module Main where module Main where
import System.Posix.Types ()
import System.Posix.Files ()
import System.Posix.Directory ( getWorkingDirectory ) import System.Posix.Directory ( getWorkingDirectory )
import System.Directory import System.Directory
( pathIsSymbolicLink, doesFileExist, getFileSize, doesDirectoryExist ) ( pathIsSymbolicLink, doesFileExist, getFileSize, doesDirectoryExist )
import System.Environment ()
import Data.Functor ( (<&>) ) import Data.Functor ( (<&>) )
import Control.Monad ( (<=<), filterM ) import Control.Monad ( filterM )
import System.Directory.Extra ( listContents ) import System.Directory.Extra ( listContents )
import Brick
listFiles :: FilePath -> IO [FilePath] listNonSymFiles :: FilePath -> IO [FilePath]
listFiles dir = filterM ((return . not) <=< pathIsSymbolicLink) =<< filterM doesFileExist =<< listContents dir listNonSymFiles dir = filterM (fmap not . pathIsSymbolicLink) =<< filterM doesFileExist =<< listContents dir
listDirectories :: FilePath -> IO [FilePath] listNonSymDirectories :: FilePath -> IO [FilePath]
listDirectories dir = filterM ((return . not) <=< pathIsSymbolicLink) =<< filterM doesDirectoryExist =<< listContents dir listNonSymDirectories dir = filterM (fmap not . pathIsSymbolicLink) =<< filterM doesDirectoryExist =<< listContents dir
getAllSubpaths :: FilePath -> IO [(FilePath, Integer)] getSizeSubpaths :: FilePath -> IO [(FilePath, Integer)]
getAllSubpaths x = do getSizeSubpaths x = do
sub <- listDirectories x sub <- listNonSymDirectories x
subFiles <- mapM getAllSubpaths sub subby <- mapM (\y -> (y,) . sum . map snd <$> getSizeSubpaths y) sub
local <- listFiles x >>= (\y -> mapM getFileSize y <&> zip y) local <- listNonSymFiles x >>= (\y -> mapM getFileSize y <&> zip y)
return $ local ++ concat subFiles return $ local ++ subby
main :: IO () main :: IO ()
main = do main = do
a <- getWorkingDirectory a <- getWorkingDirectory
print =<< getAllSubpaths a print =<< getSizeSubpaths a