summaryrefslogtreecommitdiff
path: root/ghc
diff options
context:
space:
mode:
authorGauvain 'GovanifY' Roussel-Tarbouriech <gauvain@govanify.com>2020-12-05 23:02:44 +0100
committerMarge Bot <ben+marge-bot@smart-cactus.org>2021-02-18 13:46:19 -0500
commit763d28551de32377a1dca8bdde02979e3686f400 (patch)
treeb96de6da511d3fc2f7b29260d8250afb787df758 /ghc
parent2adfb404111c220ef4df0206d9cda20c2fe5db46 (diff)
downloadhaskell-763d28551de32377a1dca8bdde02979e3686f400.tar.gz
directory: ensure xdg compliance (Fix #6077)
Diffstat (limited to 'ghc')
-rw-r--r--ghc/GHCi/UI.hs18
1 files changed, 16 insertions, 2 deletions
diff --git a/ghc/GHCi/UI.hs b/ghc/GHCi/UI.hs
index 97b5f57447..18a6e6eeae 100644
--- a/ghc/GHCi/UI.hs
+++ b/ghc/GHCi/UI.hs
@@ -587,7 +587,21 @@ ghciLogAction lastErrLocations old_log_action
withGhcAppData :: (FilePath -> IO a) -> IO a -> IO a
withGhcAppData right left = do
- either_dir <- tryIO (getAppUserDataDirectory "ghc")
+ either_dir <- tryIO (getXdgDirectory XdgData "ghc")
+ case either_dir of
+ Right dir ->
+ do createDirectoryIfMissing False dir `catchIO` \_ -> return ()
+ right dir
+ _ -> left
+
+withGhcConfig :: (FilePath -> IO a) -> IO a -> IO a
+withGhcConfig right left = do
+ old_path <- getAppUserDataDirectory "ghc"
+ use_old_path <- doesPathExist old_path
+ let path = (if use_old_path
+ then getAppUserDataDirectory "ghc"
+ else getXdgDirectory XdgConfig "ghc")
+ either_dir <- tryIO (path)
case either_dir of
Right dir ->
do createDirectoryIfMissing False dir `catchIO` \_ -> return ()
@@ -600,7 +614,7 @@ runGHCi paths maybe_exprs = do
let
ignore_dot_ghci = gopt Opt_IgnoreDotGhci dflags
- app_user_dir = liftIO $ withGhcAppData
+ app_user_dir = liftIO $ withGhcConfig
(\dir -> return (Just (dir </> "ghci.conf")))
(return Nothing)