T.P.Class.IO: normalise path in writeMedia.

This ensures that we get `\` separators on Windows.
This commit is contained in:
John MacFarlane 2021-06-03 18:34:38 -06:00
parent a54a19cca5
commit b6c04383e4

View file

@ -211,13 +211,12 @@ writeMedia :: (PandocMonad m, MonadIO m)
=> FilePath -> MediaBag -> FilePath
-> m ()
writeMedia dir mediabag subpath = do
-- we join and split to convert a/b/c to a\b\c on Windows;
-- in zip containers all paths use /
let mbcontents = lookupMedia subpath mediabag
case mbcontents of
Nothing -> throwError $ PandocResourceNotFound $ pack subpath
Just item -> do
let fullpath = dir </> mediaPath item
-- we normalize to get proper path separators for the platform
let fullpath = dir </> normalise (mediaPath item)
liftIOError (createDirectoryIfMissing True) (takeDirectory fullpath)
logIOError $ BL.writeFile fullpath $ mediaContents item