T.P.Shared.defaultUserDataDir: behavior change.

If the XDG data directory is not defined (e.g. because
it's not supported in the OS or HOME isn't defined), we
return the empty string instead of raising an exception.

Closes #7842.
This commit is contained in:
John MacFarlane 2022-01-17 19:52:27 -08:00
parent 5811baf80f
commit a92ae0a58a

View file

@ -965,10 +965,13 @@ safeStrRead s = case reads s of
-- XDG_DATA_HOME (or its default value), but for backwards compatibility,
-- we fall back to the legacy user data directory ($HOME/.pandoc on *nix)
-- if the XDG_DATA_HOME is missing and this exists. If neither directory
-- is present, we return the XDG data directory.
-- is present, we return the XDG data directory. If the XDG data directory
-- is not defined (e.g. because we are in an environment where $HOME is
-- not defined), we return the empty string.
defaultUserDataDir :: IO FilePath
defaultUserDataDir = do
xdgDir <- getXdgDirectory XdgData "pandoc"
xdgDir <- E.catch (getXdgDirectory XdgData "pandoc")
(\(_ :: E.SomeException) -> return mempty)
legacyDir <- getAppUserDataDirectory "pandoc"
xdgExists <- doesDirectoryExist xdgDir
legacyDirExists <- doesDirectoryExist legacyDir