@@ -25,6 +25,7 @@ import Control.Monad
2525import Control.Monad.Trans
2626import qualified Data.ByteString.Lazy as BS
2727import qualified Data.Map as M
28+ import qualified Data.Set as S
2829
2930import qualified Codec.Compression.GZip as GZip
3031import qualified Codec.Archive.Tar as Tar
@@ -137,6 +138,23 @@ initialise opts uri auxUris
137138 where
138139 readMissingOpt prompt = maybe (putStrLn prompt >> getLine ) return
139140
141+
142+ -- | Parse the @00-index.cache@ file of the available package repositories.
143+ parseRepositoryIndices :: IO (S. Set PackageIdentifier )
144+ parseRepositoryIndices = do
145+ cabalDir <- getAppUserDataDirectory " cabal/packages"
146+ cacheDirs <- listDirectory cabalDir
147+ indexFiles <- filterM doesFileExist $ map (\ dir -> cabalDir </> dir </> " 00-index.cache" ) cacheDirs
148+ S. unions <$> mapM readCache indexFiles
149+ where
150+ readCache fname =
151+ S. fromList . mapMaybe parseLine . lines <$> readFile fname
152+ parseLine line
153+ | " pkg:" : name : ver : _ <- words line
154+ = PackageIdentifier <$> simpleParse name <*> simpleParse ver
155+ | otherwise
156+ = Nothing
157+
140158writeConfig :: BuildOpts -> BuildConfig -> IO ()
141159writeConfig opts BuildConfig {
142160 bc_srcURI = uri,
@@ -391,6 +409,11 @@ getDocumentationStats verbosity config didFail = do
391409buildOnce :: BuildOpts -> [PackageId ] -> IO ()
392410buildOnce opts pkgs = keepGoing $ do
393411 config <- readConfig opts
412+ -- Due to caching sometimes the package repository state may lag behind the
413+ -- documentation index. Consequently, we make sure that the packages we are
414+ -- going to build actually appear in the repository before building. See
415+ -- #543.
416+ repoIndex <- parseRepositoryIndices
394417
395418 notice verbosity " Initialising"
396419 (has_failed, mark_as_failed, persist_failed) <- mkPackageFailed opts
@@ -409,6 +432,7 @@ buildOnce opts pkgs = keepGoing $ do
409432 -- Find those files *not* marked as having documentation in our cache
410433 let toBuild :: [DocInfo ]
411434 toBuild = filter shouldBuild
435+ . filter (flip S. member repoIndex . docInfoPackage)
412436 . latestFirst
413437 . map (sortBy (flip (comparing docInfoPackageVersion)))
414438 . groupBy (equating docInfoPackageName)
0 commit comments