summaryrefslogtreecommitdiff
path: root/src/Text/Pandoc/PDF.hs
diff options
context:
space:
mode:
authorJohn MacFarlane <jgm@berkeley.edu>2022-06-24 17:52:39 -0700
committerJohn MacFarlane <jgm@berkeley.edu>2022-06-24 17:52:39 -0700
commitc1ccbc553fc756ffc6954574727bc4a1dd7be783 (patch)
treea7a0b7968d7f67850e18ee7c7c99297389b9cce3 /src/Text/Pandoc/PDF.hs
parent41af476a3dca797f7a6c8a31d376fddaebe37552 (diff)
PDF: use sha1 hash of filename when converting svg.
The previous code threw away the directory component of the filename in constructing a new one. This led to surprising results if you had e.g. `foo/pic.svg` and `bar/pic.svg`; in the final PDF they'd be the same image, because the latter would overwrite the former in the temp directory.
Diffstat (limited to 'src/Text/Pandoc/PDF.hs')
-rw-r--r--src/Text/Pandoc/PDF.hs6
1 files changed, 4 insertions, 2 deletions
diff --git a/src/Text/Pandoc/PDF.hs b/src/Text/Pandoc/PDF.hs
index 5833cb605..40fb8befc 100644
--- a/src/Text/Pandoc/PDF.hs
+++ b/src/Text/Pandoc/PDF.hs
@@ -52,6 +52,7 @@ import qualified Text.Pandoc.UTF8 as UTF8
import Text.Pandoc.Walk (walkM)
import Text.Pandoc.Writers.Shared (getField, metaToContext)
import Control.Monad.Catch (MonadMask)
+import Data.Digest.Pure.SHA (sha1, showDigest)
#ifdef _WINDOWS
import Data.List (intercalate)
#endif
@@ -215,8 +216,9 @@ convertImage opts tmpdir fname = do
E.catch (Right pngOut <$ JP.savePngImage pngOut img) $
\(e :: E.SomeException) -> return (Left (tshow e))
where
- pngOut = normalise $ replaceDirectory (replaceExtension fname ".png") tmpdir
- pdfOut = normalise $ replaceDirectory (replaceExtension fname ".pdf") tmpdir
+ sha = showDigest (sha1 (UTF8.fromStringLazy fname))
+ pngOut = normalise $ tmpdir </> sha <.> "png"
+ pdfOut = normalise $ tmpdir </> sha <.> "pdf"
svgIn = normalise fname
mime = getMimeType fname
doNothing = return (Right fname)