@@ -7,6 +7,7 @@
77-- work/*/unpack-dir/.stack-work/install/x86_64-linux/*/*/lib/x86_64-linux-ghc-*
88
99import Data.List
10+import Data.List.Extra
1011import System.Directory
1112import System.FilePath
1213
@@ -21,23 +22,25 @@ main = do
2122 samePkgLibDir l1 l2 = pkgDirName l1 == pkgDirName l2
2223 where
2324 pkgDirName p =
24− if length p < 26 || countDashes p < 2
25− then error $ p ++ " not in name-version-hash format"
25+ if length p < 25
26+ then error $ p ++ " too short to be in correct name-version-hash format"
2627 else (removeDashSegment . removeHashSegment) p
2728
28− countDashes = length . filter (== '-')
29+ removeHashSegment p =
30+ let dashes = elemIndices '-' p in
31+ if length dashes < 2
32+ then error $ p ++ " not in name-version-hash format"
33+ else let final = last dashes in
34+ if length p - final `elem` [22,23] then take final p
35+ else error $ p ++ " has incorrect hash length"
2936
3037 removeDashSegment = init . dropWhileEnd (/= '-')
3138
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−
3639 samePkgDynLib d1 d2 = pkgDynName d1 == pkgDynName d2
3740 where
3841 pkgDynName p =
39− if length p < 43 || countDashes p < 3
40− then error $ p ++ " not in libHSname-version-hash-ghc*.so format"
42+ if length p < 42
43+ then error $ p ++ " too short to be libHSname-version-hash-ghc*.so format"
4144 else (removeDashSegment . removeHashSegment . removeDashSegment) p
4245
4346 removeOlder remover files = do
@@ -51,9 +54,3 @@ main = do
5154 return $ map fst $ sortBy compareSnd fileTimes
5255
5356 compareSnd (_,t1) (_,t2) = compare t1 t2
54−
55−-- from Data.List.Extra
56−dropEnd :: Int -> [a] -> [a]
57−dropEnd i xs = f xs (drop i xs)
58− where f (x:xs) (y:ys) = x : f xs ys
59− f _ _ = []