summary history branches tags files
commit:7636874ad9dd4108935bce88ba4f62cd18aa9892
author:avh4
committer:avh4
date:Sun Jan 22 17:47:19 2023 -0800
parents:1bdc3168f2d442a1c055f62ea146232731c109c3
Give sort priority for special gcroot names
diff --git a/sizer.hs b/sizer.hs
line changes: +13/-2
index 6d3337f..199a9e3
--- a/sizer.hs
+++ b/sizer.hs
@@ -5,7 +5,7 @@ import Control.Exception (Exception, IOException, try, throwIO)
 import Data.Aeson qualified as Aeson
 import Data.Aeson (ToJSON(..), FromJSON(..), Value(..), (.:), (.=), object)
 import Data.Aeson.Types (prependFailure, typeMismatch)
-import Data.List (stripPrefix)
+import Data.List (isPrefixOf, isSuffixOf, stripPrefix)
 import Data.Maybe (catMaybes, fromMaybe)
 import Data.Set (Set)
 import Data.Set qualified as Set
@@ -38,10 +38,21 @@ main = do
         <* ProgressBar.incProgress pb 1
 
     sortRootKey root =
-      ( negate $ totalSize $ gcrootDependencies root
+      ( negate $ sortPriority $ gcrootPath root
+      , negate $ totalSize $ gcrootDependencies root
       , gcrootPath root
       )
 
+sortPriority :: FilePath -> Int
+sortPriority root
+  | isPrefixOf "current-system" root = 51
+  | isPrefixOf "booted-system" root = 50
+  | isPrefixOf "per-user/root" root = 40
+  | isPrefixOf "per-user/" root && isSuffixOf "/current-home" root = 31
+  | isPrefixOf "per-user/" root = 30
+  | isPrefixOf "auto/" root = 0
+  | otherwise = 10
+
 findRoots :: FilePath -> IO [FilePath]
 findRoots path = do
   isLink <- pathIsSymbolicLink path