Commit 763d2855 authored by Gauvain Roussel-Tarbouriech's avatar Gauvain Roussel-Tarbouriech Committed by Marge Bot

directory: ensure xdg compliance (Fix #6077)

parent 2adfb404
......@@ -867,7 +867,7 @@ opt_i dflags= toolSettings_opt_i $ toolSettings dflags
versionedAppDir :: String -> ArchOS -> MaybeT IO FilePath
versionedAppDir appname platform = do
-- Make sure we handle the case the HOME isn't set (see #11678)
appdir <- tryMaybeT $ getAppUserDataDirectory appname
appdir <- tryMaybeT $ getXdgDirectory XdgData appname
return $ appdir </> versionedFilePath platform
versionedFilePath :: ArchOS -> FilePath
......
......@@ -101,6 +101,10 @@ GHCi
:envvar:`EDITOR`, following UNIX convention.
(:ghc-ticket:`19030`)
- GHC now follows by default the XDG Base Directory Specification. If
``$HOME/.ghc`` is found it will fallback to the old paths to give you
time to migrate. This fallback will be removed in three releases.
Runtime system
~~~~~~~~~~~~~~
......
......@@ -2063,7 +2063,7 @@ mostly obvious.
:reverse: -fno-local-ghci-history
:category:
By default, GHCi keeps global history in ``~/.ghc/ghci_history`` or
By default, GHCi keeps global history in ``$XDG_DATA_HOME/ghc/ghci_history`` or
``%APPDATA%/<app>/ghci_history``, but you can use current directory, e.g.:
.. code-block:: none
......@@ -3248,7 +3248,7 @@ they exist:
Unix or :file:`C:/Documents and Settings/user/Application
Data/ghc` on Windows.
2. :file:`$HOME/.ghci`
2. :file:`$XDG_CONFIG_HOME/.ghci`
3. :file:`./.ghci`
......
......@@ -393,7 +393,7 @@ GHC knows about two package databases in particular:
e.g. ``/usr/lib/ghc-6.12.1/package.conf.d``.
- The *user package database* private to each user. On Unix systems this will
be ``$HOME/.ghc/arch-os-version/package.conf.d``, and on Windows it will
be ``$XDG_DATA_HOME/ghc/arch-os-version/package.conf.d``, and on Windows it will
be something like
``C:\Documents And Settings\user\ghc\package.conf.d``. The
``ghc-pkg`` tool knows where this file should be located, and will
......@@ -515,7 +515,7 @@ The ``GHC_PACKAGE_PATH`` environment variable
.. code-block:: none
$ export GHC_PACKAGE_PATH=$HOME/.my-ghc-packages.conf:
$ export GHC_PACKAGE_PATH=$XDG_DATA_HOME/.my-ghc-packages.conf:
To check whether your `GHC_PACKAGE_PATH` setting is doing the right
thing, ``ghc-pkg list`` will list all the databases in use, in the
......@@ -578,7 +578,7 @@ must be relative to the location of the package environment file.
:category:
Use the package environment in file, or in
``$HOME/.ghc/arch-os-version/environments/name``
``$XDG_DATA_HOME/ghc/arch-os-version/environments/name``
If set to ``-`` no package environment is read.
.. envvar:: GHC_ENVIRONMENT
......@@ -591,13 +591,13 @@ locations:
- File file if you pass the option :ghc-flag:`-package-env file|name`.
- File ``$HOME/.ghc/arch-os-version/environments/name`` if you pass the
- File ``$XDG_DATA_HOME/ghc/arch-os-version/environments/name`` if you pass the
option ``-package-env name``.
- File file if the environment variable :envvar:`GHC_ENVIRONMENT` is set to
file.
- File ``$HOME/.ghc/arch-os-version/environments/name`` if the
- File ``$XDG_DATA_HOME/ghc/arch-os-version/environments/name`` if the
environment variable :envvar:`GHC_ENVIRONMENT` is set to name.
Additionally, unless ``-hide-all-packages`` is specified ``ghc`` will also
......@@ -606,7 +606,7 @@ look for the package environment in the following locations:
- File ``.ghc.environment.arch-os-version`` if it exists in the current
directory or any parent directory (but not the user's home directory).
- File ``$HOME/.ghc/arch-os-version/environments/default`` if it
- File ``$XDG_DATA_HOME/ghc/arch-os-version/environments/default`` if it
exists.
Package environments can be modified by further command line arguments;
......
......@@ -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)
......
......@@ -58,8 +58,8 @@ import Distribution.Simple.Utils (toUTF8BS, writeUTF8File, readUTF8File)
import qualified Data.Version as Version
import System.FilePath as FilePath
import qualified System.FilePath.Posix as FilePath.Posix
import System.Directory ( getAppUserDataDirectory, createDirectoryIfMissing,
getModificationTime )
import System.Directory ( getXdgDirectory, createDirectoryIfMissing,
getModificationTime, XdgDirectory ( XdgData ) )
import Text.Printf
import Prelude
......@@ -634,8 +634,8 @@ getPkgDatabases verbosity mode use_user use_cache expand_vars my_flags = do
let no_user_db = FlagNoUserDb `elem` my_flags
-- get the location of the user package database, and create it if necessary
-- getAppUserDataDirectory can fail (e.g. if $HOME isn't set)
e_appdir <- tryIO $ getAppUserDataDirectory "ghc"
-- getXdgDirectory can fail (e.g. if $HOME isn't set)
e_appdir <- tryIO $ getXdgDirectory XdgData "ghc"
mb_user_conf <-
case [ f | FlagUserConfig f <- my_flags ] of
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment