@@ -31,6 +31,8 @@ import Control.Monad.Catch
3131import Control.Monad.IO.Class
3232import Control.Monad.Logger (MonadLogger )
3333import Control.Monad.Trans.Control
34+ import Data.Attoparsec.Args
35+ import Data.Attoparsec.Text as P
3436import Data.Binary (Binary )
3537import Data.Binary.VersionTagged (taggedDecodeOrLoad , taggedEncodeFile , BinarySchema (.. ))
3638import Data.ByteString (ByteString )
@@ -46,6 +48,7 @@ import Data.Map (Map)
4648import qualified Data.Map as Map
4749import Data.Maybe (catMaybes )
4850import qualified Data.Set as Set
51+ import qualified Data.Text.Encoding as T
4952import Data.Typeable (Typeable )
5053import GHC.Generics (Generic )
5154import Path
@@ -190,7 +193,7 @@ addProfiling (InstalledCache ref) =
190193 Nothing -> do
191194 let loop [] = return False
192195 loop (dir: dirs) = do
193- econtents <- tryIO $ getDirectoryContents $ S8. unpack dir
196+ econtents <- tryIO $ getDirectoryContents dir
194197 let contents = either (const [] ) id econtents
195198 if or [isProfiling content lib
196199 | content <- contents
@@ -235,7 +238,7 @@ addHaddock (InstalledCache ref) =
235238-- | Dump information for a single package
236239data DumpPackage profiling haddock = DumpPackage
237240 { dpGhcPkgId :: ! GhcPkgId
238- , dpLibDirs :: ! [ByteString ]
241+ , dpLibDirs :: ! [FilePath ]
239242 , dpLibraries :: ! [ByteString ]
240243 , dpDepends :: ! [GhcPkgId ]
241244 , dpHaddockInterfaces :: ! [ByteString ]
@@ -247,6 +250,7 @@ data DumpPackage profiling haddock = DumpPackage
247250data PackageDumpException
248251 = MissingSingleField ByteString (Map ByteString [Line ])
249252 | MismatchedId PackageName Version GhcPkgId
253+ | Couldn'tParseField ByteString [Line ]
250254 deriving Typeable
251255instance Exception PackageDumpException
252256instance Show PackageDumpException where
@@ -261,6 +265,8 @@ instance Show PackageDumpException where
261265 show (MismatchedId name version gid) =
262266 " Invalid id/name/version in ghc-pkg dump output: " ++
263267 show (name, version, gid)
268+ show (Couldn'tParseField name ls) =
269+ " Couldn't parse the field " ++ show name ++ " from lines: " ++ show ls
264270
265271-- | Convert a stream of bytes into a stream of @DumpPackage@s
266272conduitDumpPackage :: MonadThrow m
@@ -301,14 +307,20 @@ conduitDumpPackage = (=$= CL.catMaybes) $ eachSection $ do
301307 $ throwM $ MismatchedId name version ghcPkgId
302308
303309 -- if a package has no modules, these won't exist
304- let libDirs = parseM " library-dirs"
310+ let libDirKey = " library-dirs"
311+ libDirs = parseM libDirKey
305312 libraries = parseM " hs-libraries"
306313 haddockInterfaces = parseM " haddock-interfaces"
307314 depends <- mapM parseDepend $ parseM " depends"
308315
316+ libDirPaths <-
317+ case mapM (P. parseOnly (argsParser NoEscaping ) . T. decodeUtf8) libDirs of
318+ Left {} -> throwM (Couldn'tParseField libDirKey libDirs)
319+ Right dirs -> return (concat dirs)
320+
309321 return $ Just DumpPackage
310322 { dpGhcPkgId = ghcPkgId
311- , dpLibDirs = libDirs
323+ , dpLibDirs = libDirPaths
312324 , dpLibraries = S8. words $ S8. unwords libraries
313325 , dpDepends = catMaybes (depends :: [Maybe GhcPkgId ])
314326 , dpHaddockInterfaces = S8. words $ S8. unwords haddockInterfaces
0 commit comments