From bdd857e491ab4c6ac60032641bf81c091834629d Mon Sep 17 00:00:00 2001 From: pingu Date: Fri, 13 Oct 2023 15:24:26 +0200 Subject: [PATCH] =?UTF-8?q?(=E2=80=A2=E0=B8=B4=5F=E2=80=A2=E0=B8=B4)=3F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/Main.hs | 29 ++++++++++++++++++++++------- hcdu.cabal | 4 +++- 2 files changed, 25 insertions(+), 8 deletions(-) diff --git a/app/Main.hs b/app/Main.hs index ecce4b0..69483ae 100644 --- a/app/Main.hs +++ b/app/Main.hs @@ -1,14 +1,29 @@ module Main where -import System.PosixCompat.Types -import System.PosixCompat.Files +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 System.Directory.Extra ( listContents ) -getFileSize :: FilePath -> IO FileOffset -getFileSize = (fileSize <$>) . getFileStatus +listFiles :: FilePath -> IO [FilePath] +listFiles dir = filterM ((return . not) <=< pathIsSymbolicLink) =<< filterM doesFileExist =<< listContents dir -getFolderSize :: FilePath -> IO FileOffset -getFolderSize path = undefined +listDirectories :: FilePath -> IO [FilePath] +listDirectories dir = filterM ((return . 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 main :: IO () main = do - putStrLn "Hello, Haskell!" + a <- getWorkingDirectory + print =<< getAllSubpaths a diff --git a/hcdu.cabal b/hcdu.cabal index 18a1bc6..f9ba179 100644 --- a/hcdu.cabal +++ b/hcdu.cabal @@ -71,7 +71,9 @@ executable hcdu -- Other library packages from which modules are imported. build-depends: base ^>=4.17.1.0 , brick >= 1.9 - , unix-compat >= 0.7 + , unix + , extra + , directory -- Directories containing source files. hs-source-dirs: app