git.iko.soy/typeable/pandoc
on master help sign in
PDF: Better detection of a Cygwin environment.

Should close #5451. Unlike the earlier fix, this one doesn't spill out to stderr when 'uname -o' fails.

commitb6f9318c9bd2117de7f567dc8f50c56260015cc8 authorJohn MacFarlane <jgm@berkeley.edu> dateSat 20 Jul 2019, 16:45 (7 years ago) parentfb73b5c
1 file changed+8−1
src/Text/Pandoc/PDF.hs+8−1
src/Text/Pandoc/PDF.hs+8−1
@@ -42,6 +42,7 @@ import Text.Pandoc.Error (PandocError (PandocPDFProgramNotFoundError))
4242import Text.Pandoc.MIME (getMimeType)
4343import Text.Pandoc.Options (HTMLMathMethod (..), WriterOptions (..))
4444import Text.Pandoc.Process (pipeProcess)
45+import System.Process (readProcessWithExitCode)
4546import Text.Pandoc.Shared (inDirectory, stringify)
4647import qualified Text.Pandoc.UTF8 as UTF8
4748import Text.Pandoc.Walk (walkM)
@@ -89,7 +90,13 @@ makePDF program pdfargs writer opts doc =
8990 -- user names (see #777)
9091 let withTempDir templ action = do
9192 tmp <- getTemporaryDirectory
92− if '~' `elem` tmp
93+ uname <- E.catch
94+ (do (ec, sout, _) <- readProcessWithExitCode "uname" ["-o"] ""
95+ if ec == ExitSuccess
96+ then return $ Just sout
97+ else return Nothing)
98+ (\(_ :: E.SomeException) -> return Nothing)
99+ if '~' `elem` tmp || uname == Just "Cygwin" -- see #5451
93100 then withTempDirectory "." templ action
94101 else withSystemTempDirectory templ action
95102 (newCommonState, res) <- liftIO $ withTempDir "tex2pdf." $ \tmpdir' -> do