From b84554880d8cc2f8ea83e1f77febee13c50b829d Mon Sep 17 00:00:00 2001 From: Tissevert Date: Sat, 11 Jan 2025 12:25:41 +0100 Subject: [PATCH] A suggestion to turn defaultUserDataDir :: IO FilePath into defaultUserDataDirs :: IO [FilePath] --- src/Text/Pandoc/Shared.hs | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/src/Text/Pandoc/Shared.hs b/src/Text/Pandoc/Shared.hs index 35a854bf6..c1a55930c 100644 --- a/src/Text/Pandoc/Shared.hs +++ b/src/Text/Pandoc/Shared.hs @@ -92,7 +92,7 @@ module Text.Pandoc.Shared ( safeRead, safeStrRead, -- * User data directory - defaultUserDataDir, + defaultUserDataDirs, -- * Version pandocVersion ) where @@ -1017,13 +1017,15 @@ safeStrRead s = case reads s of -- 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 +defaultUserDataDirs :: IO [FilePath] +defaultUserDataDirs = do xdgDir <- E.catch (getXdgDirectory XdgData "pandoc") (\(_ :: E.SomeException) -> return mempty) legacyDir <- getAppUserDataDirectory "pandoc" xdgExists <- doesDirectoryExist xdgDir legacyDirExists <- doesDirectoryExist legacyDir - if not xdgExists && legacyDirExists - then return legacyDir - else return xdgDir + let mainDir = if not xdgExists && legacyDirExists then legacyDir else xdgDir + xdgDirs <- E.catch (getXdgDirectoryList XdgDataDirs) + (\(_ :: E.SomeException) -> return mempty) + return (mainDir:xdgDirs) +