Skip to content

Commit 9a54aaa

Browse files
jokesperBodigrim
authored andcommitted
Follow XDG Base Directory Specification with legacy path as fallback
1 parent 7693578 commit 9a54aaa

File tree

2 files changed

+21
-1
lines changed

2 files changed

+21
-1
lines changed

CHANGES.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
Changelog for Hoogle (* = API change, @ = database format change)
22

3+
#411, switched to xdg directory and deprecated legacy location
34
Require and support crypton-connection >= 0.4.1
45
5.0.18.4, released 2024-01-14
56
Don't test on GHC 9.2 or earlier

src/Action/CmdLine.hs

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ import System.Console.CmdArgs
1616
import System.Directory
1717
import System.Environment
1818
import System.FilePath
19+
import System.IO
1920

2021
data Language = Haskell | Frege deriving (Data,Typeable,Show,Eq,Enum,Bounded)
2122

@@ -80,7 +81,25 @@ data CmdLine
8081

8182
defaultDatabaseLang :: Language -> IO FilePath
8283
defaultDatabaseLang lang = do
83-
dir <- getAppUserDataDirectory "hoogle"
84+
xdgLocation <- getXdgDirectory XdgData "hoogle"
85+
legacyLocation <- getAppUserDataDirectory "hoogle"
86+
doesXdgPathExist <- doesPathExist xdgLocation
87+
doesLegacyPathExist <- doesPathExist legacyLocation
88+
89+
dir <- case (doesXdgPathExist, doesLegacyPathExist) of
90+
-- On Windows XDG location and legacy location are identical
91+
_ | xdgLocation == legacyLocation -> pure xdgLocation
92+
(_, False) -> pure xdgLocation
93+
(True, True) -> do
94+
hPutStrLn stderr $
95+
"Warning: Legacy location ignored (" ++ legacyLocation ++ "),"
96+
++ "since xdg location is available (" ++ xdgLocation ++")."
97+
pure xdgLocation
98+
(False, True) -> do
99+
-- TODO: renable after release
100+
--hPutStrLn stderr $ "Warning: " ++ legacyLocation ++ " is deprecated."
101+
-- ++ "Consider moving it to $XDG_DATA_HOME/hoogle (" ++ xdgLocation ++ ")"
102+
pure legacyLocation
84103
pure $ dir </> "default-" ++ lower (show lang) ++ "-" ++ showVersion (trimVersion 3 version) ++ ".hoo"
85104

86105
getCmdLine :: [String] -> IO CmdLine

0 commit comments

Comments
 (0)