make /usr/lib consolidation more robust

Directory enumeration could happen in either order, and also there could
be some other directories so the two to combine are not adjacent.
This commit is contained in:
Joey Hess 2020-08-10 12:20:32 -04:00
parent 5feaef773d
commit 6cb08876f0
No known key found for this signature in database
GPG key ID: DB12DB0FF05F8F38

View file

@ -68,24 +68,19 @@ mklibs top _installedbins = do
- and improves startup time.
-}
consolidateUsrLib :: FilePath -> [FilePath] -> IO [FilePath]
consolidateUsrLib top libdirs = map reverse <$> go [] (map reverse libdirs)
consolidateUsrLib top libdirs = go [] libdirs
where
go c [] = return c
go c (x:[]) = return (x:c)
go c (x:y:rest)
| x == y ++ reverse ("/usr") = do
let x' = reverse x
let y' = reverse y
fs <- getDirectoryContents (inTop top x')
go c (x:rest) = case filter (\d -> ("/usr" ++ d) == x) libdirs of
(d:_) -> do
fs <- getDirectoryContents (inTop top x)
forM_ fs $ \f ->
unless (dirCruft f) $
renameFile
(inTop top (x' </> f))
(inTop top (y' </> f))
go (y:c) rest
| otherwise = do
print (x,y)
go (x:c) (y:rest)
(inTop top (x </> f))
(inTop top (d </> f))
go c rest
_ -> go (x:c) rest
{- Installs a linker shim script around a binary.
-