summary history branches tags files
commit:40454c68ea6d30e61eb16414677d5bf378bc4f80
author:avh4
committer:avh4
date:Sun Jan 22 16:21:10 2023 -0800
parents:70645c14473d325772dc3bc1ff7e43f6d9910cfe
Remove collectAndPrintGcroot
diff --git a/sizer.hs b/sizer.hs
line changes: +4/-7
index 356c397..c88470f
--- a/sizer.hs
+++ b/sizer.hs
@@ -7,15 +7,16 @@ import Data.Aeson (ToJSON(..), FromJSON(..), Value(..), (.:), (.=), object)
 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
@@ -76,10 +77,6 @@ printGcroot gcroot = 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