on master help sign in
remove-old-stack-work-libs.hs: check hash length for more safety
c69a73cJens Petersen
etc/diskspace/remove-old-stack-work-libs.hs+8−6
@@ -21,22 +21,24 @@ main = do
21 samePkgLibDir l1 l2 = pkgDirName l1 == pkgDirName l2
21 samePkgLibDir l1 l2 = pkgDirName l1 == pkgDirName l2
22 where
22 where
23 pkgDirName p =
23 pkgDirName p =
24− if countDashes p < 2
24+ if length p < 26 || countDashes p < 2
25 then error $ p ++ " not in name-version-hash format"
25 then error $ p ++ " not in name-version-hash format"
26− else let nv_ = dropEnd 22 p in
27− if last nv_ == '-' then removeDashSegment $ init nv_
26+ else (removeDashSegment . removeHashSegment) p
28− else error $ p ++ " not in name-version-hash format"
29
27
30 countDashes = length . filter (== '-')
28 countDashes = length . filter (== '-')
31
29
32 removeDashSegment = init . dropWhileEnd (/= '-')
30 removeDashSegment = init . dropWhileEnd (/= '-')
33
31
32+ removeHashSegment p = let nv_ = dropEnd 22 p in
33+ if last nv_ == '-' then init nv_
34+ else error $ p ++ " has incorrect hash format"
35+
34 samePkgDynLib d1 d2 = pkgDynName d1 == pkgDynName d2
36 samePkgDynLib d1 d2 = pkgDynName d1 == pkgDynName d2
35 where
37 where
36 pkgDynName p =
38 pkgDynName p =
37− if countDashes p < 3
39+ if length p < 43 || countDashes p < 3
38 then error $ p ++ " not in libHSname-version-hash-ghc*.so format"
40 then error $ p ++ " not in libHSname-version-hash-ghc*.so format"
39− else (removeDashSegment . removeDashSegment . removeDashSegment) p
41+ else (removeDashSegment . removeHashSegment . removeDashSegment) p
40
42
41 removeOlder remover files = do
43 removeOlder remover files = do
42 -- keep 2 latest builds
44 -- keep 2 latest builds