Shared: Change defaultUserDataDirs -> defaultUserDataDir.

Rationale: the manual says that the XDG data directory will
be used if it exists, otherwise the legacy data directory.
So we should just determine this and use this directory,
rather than having a search path which could cause some
things to be taken from one data directory and others from
others.

[API change]
This commit is contained in:
John MacFarlane 2021-03-05 10:20:16 -08:00
parent 030209fc29
commit 5f9327cfc8
2 changed files with 18 additions and 14 deletions

View file

@ -361,15 +361,15 @@ header when requesting a document from a URL:
will be used. On \*nix and macOS systems this will be the `pandoc` will be used. On \*nix and macOS systems this will be the `pandoc`
subdirectory of the XDG data directory (by default, subdirectory of the XDG data directory (by default,
`$HOME/.local/share`, overridable by setting the `XDG_DATA_HOME` `$HOME/.local/share`, overridable by setting the `XDG_DATA_HOME`
environment variable). If that directory does not exist, environment variable). If that directory does not exist and
`$HOME/.pandoc` will be used (for backwards compatibility). `$HOME/.pandoc` exists, it will be used (for backwards compatibility).
In Windows the default user data directory is On Windows the default user data directory is
`C:\Users\USERNAME\AppData\Roaming\pandoc`. `C:\Users\USERNAME\AppData\Roaming\pandoc`.
You can find the default user data directory on your system by You can find the default user data directory on your system by
looking at the output of `pandoc --version`. looking at the output of `pandoc --version`.
A `reference.odt`, `reference.docx`, `epub.css`, `templates`, Data files placed in this directory (for example, `reference.odt`,
`slidy`, `slideous`, or `s5` directory `reference.docx`, `epub.css`, `templates`) will override
placed in this directory will override pandoc's normal defaults. pandoc's normal defaults.
`-d` *FILE*, `--defaults=`*FILE* `-d` *FILE*, `--defaults=`*FILE*

View file

@ -95,7 +95,7 @@ module Text.Pandoc.Shared (
safeRead, safeRead,
safeStrRead, safeStrRead,
-- * User data directory -- * User data directory
defaultUserDataDirs, defaultUserDataDir,
-- * Version -- * Version
pandocVersion pandocVersion
) where ) where
@ -1012,12 +1012,16 @@ safeStrRead s = case reads s of
-- --
-- | Return appropriate user data directory for platform. We use -- | Return appropriate user data directory for platform. We use
-- XDG_DATA_HOME (or its default value), but fall back to the -- XDG_DATA_HOME (or its default value), but for backwards compatibility,
-- legacy user data directory ($HOME/.pandoc on *nix) if this is -- we fall back to the legacy user data directory ($HOME/.pandoc on *nix)
-- missing. -- if the XDG_DATA_HOME is missing and this exists. If neither directory
defaultUserDataDirs :: IO [FilePath] -- is present, we return the XDG data directory.
defaultUserDataDirs = E.catch (do defaultUserDataDir :: IO FilePath
defaultUserDataDir = do
xdgDir <- getXdgDirectory XdgData "pandoc" xdgDir <- getXdgDirectory XdgData "pandoc"
legacyDir <- getAppUserDataDirectory "pandoc" legacyDir <- getAppUserDataDirectory "pandoc"
return $ ordNub [xdgDir, legacyDir]) xdgExists <- doesDirectoryExist xdgDir
(\(_ :: E.SomeException) -> return []) legacyDirExists <- doesDirectoryExist legacyDir
if not xdgExists && legacyDirExists
then return legacyDir
else return xdgDir