diff options
author | Andrzej Rybczak <electricityispower@gmail.com> | 2017-03-02 11:26:09 -0500 |
---|---|---|
committer | Ben Gamari <ben@smart-cactus.org> | 2017-03-02 12:25:06 -0500 |
commit | 5f7b45a51f3736ad5a5046ba2fe4155446a2c467 (patch) | |
tree | 62136502a10415788ff853af3c95e048e561413f /compiler/main | |
parent | 55f6353f7adc4d947aac8dfea227fdc4f54ac6d7 (diff) | |
download | haskell-5f7b45a51f3736ad5a5046ba2fe4155446a2c467.tar.gz |
Properly acquire locks on not yet existing package databases
Reviewers: austin, bgamari, angerman
Reviewed By: bgamari, angerman
Subscribers: angerman, thomie
Differential Revision: https://phabricator.haskell.org/D3259
Diffstat (limited to 'compiler/main')
-rw-r--r-- | compiler/main/Packages.hs | 29 |
1 files changed, 27 insertions, 2 deletions
diff --git a/compiler/main/Packages.hs b/compiler/main/Packages.hs index 5f1a7d5d30..06678317e7 100644 --- a/compiler/main/Packages.hs +++ b/compiler/main/Packages.hs @@ -549,8 +549,33 @@ readPackageConfig dflags conf_file = do where readDirStylePackageConfig conf_dir = do let filename = conf_dir </> "package.cache" - debugTraceMsg dflags 2 (text "Using binary package database:" <+> text filename) - readPackageDbForGhc filename + cache_exists <- doesFileExist filename + if cache_exists + then do + debugTraceMsg dflags 2 $ text "Using binary package database:" + <+> text filename + readPackageDbForGhc filename + else do + -- If there is no package.cache file, we check if the database is not + -- empty by inspecting if the directory contains any .conf file. If it + -- does, something is wrong and we fail. Otherwise we assume that the + -- database is empty. + debugTraceMsg dflags 2 $ text "There is no package.cache in" + <+> text conf_dir + <> text ", checking if the database is empty" + db_empty <- all (not . isSuffixOf ".conf") + <$> getDirectoryContents conf_dir + if db_empty + then do + debugTraceMsg dflags 3 $ text "There are no .conf files in" + <+> text conf_dir <> text ", treating" + <+> text "package database as empty" + return [] + else do + throwGhcExceptionIO $ InstallationError $ + "there is no package.cache in " ++ conf_dir ++ + " even though package database is not empty" + -- Single-file style package dbs have been deprecated for some time, but -- it turns out that Cabal was using them in one place. So this is a |