aboutsummaryrefslogtreecommitdiff
path: root/src/Text/Pandoc/App.hs
diff options
context:
space:
mode:
authorJohn MacFarlane <jgm@berkeley.edu>2019-03-02 15:03:59 -0800
committerJohn MacFarlane <jgm@berkeley.edu>2019-03-02 15:03:59 -0800
commit0bed0ab5a308f5e72a01fa9bee76488556288862 (patch)
tree42b2e302ba259116557934166ca360e3e18bcccc /src/Text/Pandoc/App.hs
parenta99423b59c78a1f64debad7340c5bbc0259e1215 (diff)
downloadpandoc-0bed0ab5a308f5e72a01fa9bee76488556288862.tar.gz
Use XDG data directory for user data directory.
Instead of `$HOME/.pandoc`, the default user data directory is now `$XDG_DATA_HOME/pandoc`, where `XDG_DATA_HOME` defaults to `$HOME/.local/share` but can be overridden by setting the environment variable. If this directory is missing, then `$HOME/.pandoc` is searched instead, for backwards compatibility. However, we recommend moving local pandoc data files from `$HOME/.pandoc` to `$HOME/.local/share/pandoc`. On Windows the default user data directory remains the same. Closes #3582.
Diffstat (limited to 'src/Text/Pandoc/App.hs')
-rw-r--r--src/Text/Pandoc/App.hs18
1 files changed, 12 insertions, 6 deletions
diff --git a/src/Text/Pandoc/App.hs b/src/Text/Pandoc/App.hs
index 6718617e1..b0527cd79 100644
--- a/src/Text/Pandoc/App.hs
+++ b/src/Text/Pandoc/App.hs
@@ -38,7 +38,7 @@ import qualified Data.Text.Lazy.Encoding as TE
import qualified Data.Text.Encoding.Error as TE
import qualified Data.Text.Encoding.Error as TSE
import Network.URI (URI (..), parseURI)
-import System.Directory (getAppUserDataDirectory)
+import System.Directory (doesDirectoryExist)
import System.Exit (exitSuccess)
import System.FilePath
import System.IO (nativeNewline, stdout)
@@ -55,7 +55,8 @@ import Text.Pandoc.PDF (makePDF)
import Text.Pandoc.Readers.Markdown (yamlToMeta)
import Text.Pandoc.SelfContained (makeDataURI, makeSelfContained)
import Text.Pandoc.Shared (eastAsianLineBreakFilter, stripEmptyParagraphs,
- headerShift, isURI, tabFilter, uriPathToPath, filterIpynbOutput)
+ headerShift, isURI, tabFilter, uriPathToPath, filterIpynbOutput,
+ defaultUserDataDirs)
import qualified Text.Pandoc.UTF8 as UTF8
#ifndef _WINDOWS
import System.Posix.IO (stdOutput)
@@ -89,10 +90,15 @@ convertWithOpts opts = do
| otherwise -> xs
datadir <- case optDataDir opts of
- Nothing -> E.catch
- (Just <$> getAppUserDataDirectory "pandoc")
- (\e -> let _ = (e :: E.SomeException)
- in return Nothing)
+ Nothing -> do
+ ds <- defaultUserDataDirs
+ let selectUserDataDir [] = return Nothing
+ selectUserDataDir (dir:dirs) = do
+ exists <- doesDirectoryExist dir
+ if exists
+ then return (Just dir)
+ else selectUserDataDir dirs
+ selectUserDataDir ds
Just _ -> return $ optDataDir opts
-- assign reader and writer based on options and filenames