Revert "Expose packages in sandbox with their ids"
This reverts commit 46492a19b0
.
This commit is contained in:
parent
fdbd4d4ae8
commit
a25736f149
@ -145,4 +145,40 @@ extractGhcVer dir = ver
|
|||||||
|
|
||||||
-- | Obtaining packages installed in a package db directory.
|
-- | Obtaining packages installed in a package db directory.
|
||||||
getPackageDbPackages :: FilePath -> IO [Package]
|
getPackageDbPackages :: FilePath -> IO [Package]
|
||||||
getPackageDbPackages _ = return []
|
getPackageDbPackages cdir = (getPkgDb >>= listDbPackages) `E.catch` handler
|
||||||
|
where
|
||||||
|
getPkgDb = getPackageDbDir (cdir </> configFile)
|
||||||
|
handler :: SomeException -> IO [Package]
|
||||||
|
handler _ = return []
|
||||||
|
|
||||||
|
listDbPackages :: FilePath -> IO [Package]
|
||||||
|
listDbPackages pkgdir = do
|
||||||
|
files <- filter (".conf" `isSuffixOf`) <$> getDirectoryContents pkgdir
|
||||||
|
mapM extractPackage $ map (pkgdir </>) files
|
||||||
|
|
||||||
|
extractPackage :: FilePath -> IO Package
|
||||||
|
extractPackage pconf = do
|
||||||
|
contents <- lines <$> readFile pconf
|
||||||
|
-- Be strict to ensure that an error can be caught.
|
||||||
|
let !name = extractName $ parseName contents
|
||||||
|
!pid = extractId $ parseId contents
|
||||||
|
return (name, Just pid)
|
||||||
|
where
|
||||||
|
parseName = parse nameKey
|
||||||
|
extractName = extract nameKeyLength
|
||||||
|
parseId = parse idKey
|
||||||
|
extractId = extract idKeyLength
|
||||||
|
parse key = head . filter (key `isPrefixOf`)
|
||||||
|
extract keylen = fst . break isSpace . dropWhile isSpace . drop keylen
|
||||||
|
|
||||||
|
nameKey :: String
|
||||||
|
nameKey = "name:"
|
||||||
|
|
||||||
|
idKey :: String
|
||||||
|
idKey = "id:"
|
||||||
|
|
||||||
|
nameKeyLength :: Int
|
||||||
|
nameKeyLength = length nameKey
|
||||||
|
|
||||||
|
idKeyLength :: Int
|
||||||
|
idKeyLength = length idKey
|
||||||
|
Loading…
Reference in New Issue
Block a user