remove-old-stack-work-libs.hs: check more carefully for libdir hash

to avoid accidents, eg if run in wrong directory
This commit is contained in:
Jens Petersen 2020-05-19 11:22:37 +08:00
parent 9ba15fcde0
commit 6c6708be00

View File

@ -23,7 +23,9 @@ main = do
pkgDirName p =
if countDashes p < 2
then error $ p ++ " not in name-version-hash format"
else (removeDashSegment . removeDashSegment) p
else let nv_ = dropEnd 22 p in
if last nv_ == '-' then removeDashSegment $ init nv_
else error $ p ++ " not in name-version-hash format"
countDashes = length . filter (== '-')
@ -47,3 +49,9 @@ main = do
return $ map fst $ sortBy compareSnd fileTimes
compareSnd (_,t1) (_,t2) = compare t1 t2
-- from Data.List.Extra
dropEnd :: Int -> [a] -> [a]
dropEnd i xs = f xs (drop i xs)
where f (x:xs) (y:ys) = x : f xs ys
f _ _ = []