X-Git-Url: http://source.bookstackapp.com/bookstack/blobdiff_plain/5164375b18f0af6dfb6b3bd35542e40bf2406176..refs/pull/5681/head:/app/Exports/PdfGenerator.php diff --git a/app/Exports/PdfGenerator.php b/app/Exports/PdfGenerator.php index 0524e063f..f31d8aad0 100644 --- a/app/Exports/PdfGenerator.php +++ b/app/Exports/PdfGenerator.php @@ -90,18 +90,28 @@ class PdfGenerator $process = Process::fromShellCommandline($command); $process->setTimeout($timeout); + $cleanup = function () use ($inputHtml, $outputPdf) { + foreach ([$inputHtml, $outputPdf] as $file) { + if (file_exists($file)) { + unlink($file); + } + } + }; + try { $process->run(); } catch (ProcessTimedOutException $e) { + $cleanup(); throw new PdfExportException("PDF Export via command failed due to timeout at {$timeout} second(s)"); } if (!$process->isSuccessful()) { + $cleanup(); throw new PdfExportException("PDF Export via command failed with exit code {$process->getExitCode()}, stdout: {$process->getOutput()}, stderr: {$process->getErrorOutput()}"); } $pdfContents = file_get_contents($outputPdf); - unlink($outputPdf); + $cleanup(); if ($pdfContents === false) { throw new PdfExportException("PDF Export via command failed, unable to read PDF output file");