From 0495855d91f80b3cd4539400539e652560e13dda Mon Sep 17 00:00:00 2001 From: trivernis Date: Tue, 13 Apr 2021 15:22:48 +0200 Subject: [PATCH] Fix problems with creating temp file for pdf rendering Signed-off-by: trivernis --- src/format/chromium_pdf/mod.rs | 7 ++++++- src/utils/caching.rs | 1 + 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/src/format/chromium_pdf/mod.rs b/src/format/chromium_pdf/mod.rs index 5fa260d..5a5a5d5 100644 --- a/src/format/chromium_pdf/mod.rs +++ b/src/format/chromium_pdf/mod.rs @@ -26,8 +26,13 @@ pub mod result; /// Renders the document to pdf and returns the resulting bytes pub fn render_to_pdf(document: Document) -> PdfRenderingResult> { let cache = CacheStorage::new(); - let mut file_path = PathBuf::from(format!("tmp-document.html")); + let mut file_path = PathBuf::from("tmp-document.html"); file_path = cache.get_file_path(&file_path); + + if !file_path.parent().map(|p| p.exists()).unwrap_or(false) { + file_path = PathBuf::from(".tmp-document.html") + } + let config = document.config.clone(); let mathjax = config.lock().features.include_mathjax; diff --git a/src/utils/caching.rs b/src/utils/caching.rs index 2114f60..fc3c4f9 100644 --- a/src/utils/caching.rs +++ b/src/utils/caching.rs @@ -35,6 +35,7 @@ impl CacheStorage { if let Some(extension) = path.extension() { file_name.set_extension(extension); } + log::trace!("Cache path is {:?}", path); return self.location.join(PathBuf::from(file_name)); }