diff options
author | John MacFarlane <jgm@berkeley.edu> | 2019-03-02 15:03:51 -0800 |
---|---|---|
committer | John MacFarlane <jgm@berkeley.edu> | 2019-03-02 15:03:51 -0800 |
commit | a99423b59c78a1f64debad7340c5bbc0259e1215 (patch) | |
tree | eb61ce0dfbe8ada3bde9594ede98c333d8f620e0 | |
parent | 068fff202398aa51ca5424284a754df9949e5c03 (diff) | |
download | pandoc-a99423b59c78a1f64debad7340c5bbc0259e1215.tar.gz |
Add new exported function defaultUserDataDirs
-rw-r--r-- | src/Text/Pandoc/Shared.hs | 18 |
1 files changed, 17 insertions, 1 deletions
diff --git a/src/Text/Pandoc/Shared.hs b/src/Text/Pandoc/Shared.hs index 069fde23e..cf92a1fda 100644 --- a/src/Text/Pandoc/Shared.hs +++ b/src/Text/Pandoc/Shared.hs @@ -3,7 +3,6 @@ {-# LANGUAGE DeriveDataTypeable #-} {-# LANGUAGE FlexibleContexts #-} {-# LANGUAGE MultiParamTypeClasses #-} - {-# LANGUAGE ScopedTypeVariables #-} {-# LANGUAGE ViewPatterns #-} {-# LANGUAGE FlexibleInstances #-} @@ -90,6 +89,8 @@ module Text.Pandoc.Shared ( safeRead, -- * Temp directory withTempDir, + -- * User data directory + defaultUserDataDirs, -- * Version pandocVersion ) where @@ -910,3 +911,18 @@ withTempDir = #else withSystemTempDirectory #endif + +-- +-- User data directory +-- + +-- | Return appropriate user data directory for platform. We use +-- XDG_DATA_HOME (or its default value), but fall back to the +-- legacy user data directory ($HOME/.pandoc on *nix) if this is +-- missing. +defaultUserDataDirs :: IO [FilePath] +defaultUserDataDirs = E.catch (do + xdgDir <- getXdgDirectory XdgData "pandoc" + legacyDir <- getAppUserDataDirectory "pandoc" + return $ ordNub [xdgDir, legacyDir]) + (\(_ :: E.SomeException) -> return []) |