From c747047f0be63af991c0175829220411302e7e62 Mon Sep 17 00:00:00 2001 From: Daniel Gröber Date: Fri, 26 Oct 2018 04:16:46 +0200 Subject: Fix listCabalVersions logic bug The 'mdb' argument is supposed to be interpreted as "use the global db" when it's 'Nothing'. --- src/CabalHelper/Compiletime/Compile.hs | 22 ++++++++++------------ 1 file changed, 10 insertions(+), 12 deletions(-) (limited to 'src/CabalHelper/Compiletime') diff --git a/src/CabalHelper/Compiletime/Compile.hs b/src/CabalHelper/Compiletime/Compile.hs index 431043b..6403aca 100644 --- a/src/CabalHelper/Compiletime/Compile.hs +++ b/src/CabalHelper/Compiletime/Compile.hs @@ -681,18 +681,16 @@ errorInstallCabal cabalVer = panicIO $ printf "\ listCabalVersions' :: Env => Maybe PackageDbDir -> MaybeT IO [Version] listCabalVersions' mdb = do - case mdb of - Nothing -> mzero - Just (PackageDbDir db_path) -> do - exists <- liftIO $ doesDirectoryExist db_path - case exists of - False -> mzero - True -> MaybeT $ logIOError "listCabalVersions'" $ Just <$> do - let mdbopt = ("--package-conf="++) <$> unPackageDbDir <$> mdb - args = ["list", "--simple-output", "Cabal"] ++ maybeToList mdbopt - - catMaybes . map (fmap snd . parsePkgId . fromString) . words - <$> readProcess' (ghcProgram ?cprogs) args "" + let mdb_path = unPackageDbDir <$> mdb + exists <- fromMaybe True <$> + traverse (liftIO . doesDirectoryExist) mdb_path + case exists of + True -> MaybeT $ logIOError "listCabalVersions" $ Just <$> do + let mdbopt = ("--package-conf="++) <$> mdb_path + args = ["list", "--simple-output", "Cabal"] ++ maybeToList mdbopt + catMaybes . map (fmap snd . parsePkgId . fromString) . words + <$> readProcess' (ghcPkgProgram ?cprogs) args "" + _ -> mzero cabalVersionExistsInPkgDb :: Env => Version -> PackageDbDir -> IO Bool cabalVersionExistsInPkgDb cabalVer db@(PackageDbDir db_path) = do -- cgit v1.2.3