-
-
Notifications
You must be signed in to change notification settings - Fork 157
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
hackage-db: support cabal-install 3.10.1.0 XDG paths. #597
Merged
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
fa3c42d
hackage-db: support cabal-install 3.10.1.0 XDG paths.
athas cf92430
hackage-db: Distribution.Hackage.DB.Path: document cabalStateDir
sternenseemann bbc9f1f
hackage-db: Distribution.Hackage.DB.Path: support CABAL_DIR env var
sternenseemann 56bcf79
hackage-db: bump version to 2.1.3 and prepare changelog
sternenseemann File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -15,10 +15,37 @@ import Distribution.Hackage.DB.Errors | |
|
||
import Control.Exception | ||
import System.Directory | ||
import System.Environment (lookupEnv) | ||
import System.FilePath | ||
|
||
-- | | ||
-- Determines the /state/ directory (which e.g. holds the hackage tarball) | ||
-- cabal-install uses via the following logic: | ||
-- | ||
-- 1. If the @CABAL_DIR@ environment variable is set, its content is used as the | ||
-- cabal state directory | ||
-- 2. If @~/.cabal@ (see 'getAppUserDataDirectory') exists, use that. | ||
-- 3. Otherwise, use @${XDG_CACHE_HOME}/cabal@ (see @'getXdgDirectory' 'XdgCache'@) | ||
-- which is the new directory cabal-install can use starting with | ||
-- version @3.10.*@. | ||
-- | ||
-- This logic is mostly equivalent to what upstream cabal-install is | ||
-- [doing](https://github.com/haskell/cabal/blob/0ed12188525335ac9759dc957d49979ab09382a1/cabal-install/src/Distribution/Client/Config.hs#L594-L610) | ||
-- with the following exception: | ||
-- The state directory can freely be configured to use a different location | ||
-- in the cabal-install configuration file. hackage-db doesn't parse this | ||
-- configuration file, so differing state directories are ignored. | ||
cabalStateDir :: IO FilePath | ||
cabalStateDir = getAppUserDataDirectory "cabal" | ||
cabalStateDir = do | ||
envCabal <- lookupEnv "CABAL_DIR" | ||
dotCabal <- getAppUserDataDirectory "cabal" | ||
dotCabalExists <- doesDirectoryExist dotCabal | ||
case envCabal of | ||
Just dir -> pure dir | ||
Nothing -> | ||
if dotCabalExists | ||
then pure dotCabal | ||
else getXdgDirectory XdgCache "cabal" | ||
|
||
cabalTarballDir :: String -> IO FilePath | ||
cabalTarballDir repo = do | ||
|
@@ -29,9 +56,11 @@ hackageTarballDir :: IO FilePath | |
hackageTarballDir = cabalTarballDir "hackage.haskell.org" | ||
|
||
-- | Determine the default path of the Hackage database, which typically | ||
-- resides at @"$HOME\/.cabal\/packages\/hackage.haskell.org\/00-index.tar"@. | ||
-- Running the command @"cabal update"@ will keep that file up-to-date. | ||
|
||
-- resides in @$HOME\/.cabal\/packages\/hackage.haskell.org\/@. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Do we want to adapt this path to the new default? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't think it's necessary. |
||
-- Running the command @cabal update@ or @cabal v2-update@ will keep the index | ||
-- up-to-date. | ||
-- | ||
-- See 'cabalStateDir' on how @hackage-db@ searches for the cabal state directory. | ||
hackageTarball :: IO FilePath | ||
hackageTarball = do | ||
htd <- hackageTarballDir | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Really unimportant. Just suggesting it to learn whether you also like it better and if not, why not.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This was copy-pasted from the cabal source code which doesn't seem to use guards much.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think having the control flow more explicit is more readable here (at least to me) and it also makes the diff easier to discern. If you'd want to make the code nice, you'd probably use
Alternative
or something, but can't be bothered, really :)