@@ -16,6 +16,7 @@ import System.Console.CmdArgs
1616import System.Directory
1717import System.Environment
1818import System.FilePath
19+ import System.IO
1920
2021data Language = Haskell | Frege deriving (Data ,Typeable ,Show ,Eq ,Enum ,Bounded )
2122
@@ -80,7 +81,25 @@ data CmdLine
8081
8182defaultDatabaseLang :: Language -> IO FilePath
8283defaultDatabaseLang 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
86105getCmdLine :: [String ] -> IO CmdLine
0 commit comments