Remove collectAndPrintGcroot
import Data.Aeson.Types (prependFailure, typeMismatch)
import Data.Text (Text)
import GHC.Base (quotInt)
-import Relude (foldMapM)
+import Relude (catMaybes, foldMapM)
import System.Directory (doesDirectoryExist, listDirectory, pathIsSymbolicLink)
import System.Posix.Files qualified as Posix
import System.Process.Typed (readProcess_, proc)
main :: IO ()
main = do
- gcroots <- findRoots "/nix/var/nix/gcroots"
- mapM_ collectAndPrintGcroot gcroots
+ gcrootPaths <- findRoots "/nix/var/nix/gcroots"
+ gcroots <- catMaybes <$> mapM collectGcroot gcrootPaths
+ mapM_ printGcroot gcroots
findRoots :: FilePath -> IO [FilePath]
findRoots path = do
putStr (gcrootPath gcroot <> ": ")
putStrLn $ formatFileSize $ totalSize (gcrootDependencies gcroot)
-collectAndPrintGcroot :: FilePath -> IO ()
-collectAndPrintGcroot gcroot =
- maybe (return ()) printGcroot =<< collectGcroot gcroot
-
totalSize :: (Foldable f, Functor f) => f PathInfo -> Int
totalSize = sum . fmap pathInfoNarSize