Ensure header/footer temp files are closed before wkhtmltopdf uses them #1054
+20
−15
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Recently was applied the PR #1039 but it was failing on windows environment causing
permission denied
error on created headers and footers temp files. This was caused in my case because the new way to handle temp files does not.close
the files, causing an access error on windows env whenwkhtmltopdf
attempts to use them later. This PR fix the problem closing the files after creation and let them free to be used by another process on windows (and also linux).On the other hand, the new variable used to hold the temp files objects prevents that files were destroyed by garbage collector (the original issue), but when one reuse the same
WickedPdf
instance, the variablehf_tempfiles
onOptionParser
class is not cleared resulting on failiures when it tries to delete files that dont exists anymore (because there was information created on a previous use of theWickedPdf
class). This fix that situation moving the logic of cleaning tempfiles atOptionParser
class, and clearing thehf_tempfiles
after remove the files, letting it clean for a new call of its methods.And the last change that I made is using
URI
to create local filesurl
(File:///) to follow the convention ofruby
and make it more secure and standarized.