From f04e3b5f1560cd033afebee626adf15c47ffd5c2 Mon Sep 17 00:00:00 2001 From: Adrian Cochrane Date: Thu, 9 Apr 2020 10:35:24 +1200 Subject: [PATCH] Don't delete downloads, was happening before use. --- src/Input.hs | 16 ++++++++++------ src/Render.hs | 3 ++- 2 files changed, 12 insertions(+), 7 deletions(-) diff --git a/src/Input.hs b/src/Input.hs index 71996a6..dd10433 100644 --- a/src/Input.hs +++ b/src/Input.hs @@ -57,18 +57,22 @@ parseDocument _ ("application/xhtml+xml", Left text) | Right doc <- XML.parseTex parseDocument _ ("application/xhtml+xml", Right bytes) | Right doc <- XML.parseLBS def bytes = return doc | otherwise = return $ docForText "Unreadable webpage!" parseDocument session (mime, download) = do - localURI <- withSystemTempFile "rhapsode-download" $ writeDownloadToFile download + localURI <- writeDownloadToFile download result <- dispatchByMIME session mime localURI + -- I'm not sure when I can delete this file. case result of Just text -> return $ docForText $ Txt.pack text Nothing -> parseDocument session ("application/xhtml+xml", download) -writeDownloadToFile (Left text) file handle = do - hPutStr handle $ Txt.unpack text - return $ URI "file:" Nothing file "" "" -writeDownloadToFile (Right bytes) file handle = do +writeDownloadToFile (Left text) = do + path <- writeSystemTempFile "rhapsode-download" $ Txt.unpack text + return $ URI "file:" (Just $ URIAuth "" "" "") path "" "" + +writeDownloadToFile (Right bytes) = do + temp <- getCanonicalTemporaryDirectory + (path, handle) <- openBinaryTempFile temp "rhapsode-download" B.hPut handle bytes - return $ URI "file:" Nothing file "" "" + return $ URI "file:" (Just $ URIAuth "" "" "") path "" "" docForText txt = XML.Document { XML.documentPrologue = XML.Prologue [] Nothing [], diff --git a/src/Render.hs b/src/Render.hs index d9930e9..4cd0952 100644 --- a/src/Render.hs +++ b/src/Render.hs @@ -121,6 +121,7 @@ instance CSS.StyleSheet StyleAssets where ) downloadAssets session mimes (StyleAssets _ assets) = + -- FIXME delete these temp files. forConcurrently assets (\uri -> fetchURL' session mimes uri >>= saveAsset mimes) >>= return . zip assets @@ -134,7 +135,7 @@ fetchURL' s m u = fetchURL s m u saveAsset mimes (mime, download) | mime `notElem` mimes = return nullURI - | otherwise = withSystemTempFile "rhapsode-asset" $ writeDownloadToFile download + | otherwise = writeDownloadToFile download rewritePropertyVal rewrites (CSSTok.Url text:vals) | Just uri <- parseURIReference $ Txt.unpack text, Just rewrite <- uri `M.lookup` rewrites = -- 2.30.2