Give sort priority for special gcroot names
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
<* 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