diff options
author | John MacFarlane <jgm@berkeley.edu> | 2015-09-26 22:40:58 -0700 |
---|---|---|
committer | John MacFarlane <jgm@berkeley.edu> | 2015-09-26 22:40:58 -0700 |
commit | 6532950b26a7dfc61818c73376a14d90ba79a631 (patch) | |
tree | 92e51c16553283ae9e571694265b0d88067d1c8a /src | |
parent | 90914d2d16cc0389759b398032c56bbe24cb9ca0 (diff) | |
download | pandoc-6532950b26a7dfc61818c73376a14d90ba79a631.tar.gz |
MediaBag: ensure that / is always used as path separator.
Diffstat (limited to 'src')
-rw-r--r-- | src/Text/Pandoc/MediaBag.hs | 10 | ||||
-rw-r--r-- | src/Text/Pandoc/Shared.hs | 7 |
2 files changed, 10 insertions, 7 deletions
diff --git a/src/Text/Pandoc/MediaBag.hs b/src/Text/Pandoc/MediaBag.hs index 1246cdc8f..220ea7df9 100644 --- a/src/Text/Pandoc/MediaBag.hs +++ b/src/Text/Pandoc/MediaBag.hs @@ -37,9 +37,11 @@ module Text.Pandoc.MediaBag ( extractMediaBag ) where import System.FilePath +import qualified System.FilePath.Posix as Posix import System.Directory (createDirectoryIfMissing) import qualified Data.Map as M import qualified Data.ByteString.Lazy as BL +import Data.List (intercalate) import Data.Monoid (Monoid) import Control.Monad (when) import Text.Pandoc.MIME (MimeType, getMimeTypeDef) @@ -67,7 +69,7 @@ insertMedia :: FilePath -- ^ relative path and canonical name of resource -> MediaBag -> MediaBag insertMedia fp mbMime contents (MediaBag mediamap) = - MediaBag (M.insert (splitPath fp) (mime, contents) mediamap) + MediaBag (M.insert (splitDirectories fp) (mime, contents) mediamap) where mime = fromMaybe fallback mbMime fallback = case takeExtension fp of ".gz" -> getMimeTypeDef $ dropExtension fp @@ -77,14 +79,14 @@ insertMedia fp mbMime contents (MediaBag mediamap) = lookupMedia :: FilePath -> MediaBag -> Maybe (MimeType, BL.ByteString) -lookupMedia fp (MediaBag mediamap) = M.lookup (splitPath fp) mediamap +lookupMedia fp (MediaBag mediamap) = M.lookup (splitDirectories fp) mediamap -- | Get a list of the file paths stored in a 'MediaBag', with -- their corresponding mime types and the lengths in bytes of the contents. mediaDirectory :: MediaBag -> [(String, MimeType, Int)] mediaDirectory (MediaBag mediamap) = M.foldWithKey (\fp (mime,contents) -> - (((joinPath fp), mime, fromIntegral $ BL.length contents):)) [] mediamap + (((Posix.joinPath fp), mime, fromIntegral $ BL.length contents):)) [] mediamap -- | Extract contents of MediaBag to a given directory. Print informational -- messages if 'verbose' is true. @@ -95,7 +97,7 @@ extractMediaBag :: Bool extractMediaBag verbose dir (MediaBag mediamap) = do sequence_ $ M.foldWithKey (\fp (_ ,contents) -> - ((writeMedia verbose dir (joinPath fp, contents)):)) [] mediamap + ((writeMedia verbose dir (Posix.joinPath fp, contents)):)) [] mediamap writeMedia :: Bool -> FilePath -> (FilePath, BL.ByteString) -> IO () writeMedia verbose dir (subpath, bs) = do diff --git a/src/Text/Pandoc/Shared.hs b/src/Text/Pandoc/Shared.hs index c44133e12..50bc31a9e 100644 --- a/src/Text/Pandoc/Shared.hs +++ b/src/Text/Pandoc/Shared.hs @@ -111,7 +111,8 @@ import Network.URI ( escapeURIString, isURI, nonStrictRelativeTo, unEscapeString, parseURIReference, isAllowedInURI ) import qualified Data.Set as Set import System.Directory -import System.FilePath (joinPath, splitDirectories, pathSeparator, isPathSeparator) +import System.FilePath (joinPath, splitDirectories, isPathSeparator) +import qualified System.FilePath.Posix as Posix import Text.Pandoc.MIME (MimeType, getMimeType) import System.FilePath ( (</>), takeExtension, dropExtension) import Data.Generics (Typeable, Data) @@ -967,14 +968,14 @@ hush (Right x) = Just x -- > collapseFilePath "parent/foo/.." == "parent" -- > collapseFilePath "/parent/foo/../../bar" == "/bar" collapseFilePath :: FilePath -> FilePath -collapseFilePath = joinPath . reverse . foldl go [] . splitDirectories +collapseFilePath = Posix.joinPath . reverse . foldl go [] . splitDirectories where go rs "." = rs go r@(p:rs) ".." = case p of ".." -> ("..":r) (checkPathSeperator -> Just True) -> ("..":r) _ -> rs - go _ (checkPathSeperator -> Just True) = [[pathSeparator]] + go _ (checkPathSeperator -> Just True) = [[Posix.pathSeparator]] go rs x = x:rs isSingleton [] = Nothing isSingleton [x] = Just x |