Fix usages of NamedTemporaryFiles on Windows
- [x] I have reviewed the OFRAK contributor guide and attest that this pull request is in accordance with it.
Fixed usages of NamedTemporaryFiles on Windows to avoid permissions errors.
Please describe the changes in your request.
A common pattern in the OFRAK codebase is opening a tempfile.NamedTemporaryFile, writing some data to it, calling flush(), then calling an external tool on the temporary file. Unfortunately, this always causes a permissions error on Windows because two processes can't have the same file open at the same time. The solution is to close the temporary file, without deleting it, before handing it off to the external tool. This behavior wasn't supported by tempfile.NamedTemporaryFile before Python 3.12 introduced the delete_on_close parameter (python/cpython#58451).
This PR
- copies
tempfile.pyfrom Python 3.12 toofrak/tempfile.pyand setsdelete_on_closeto default toFalseinNamedTemporaryFile. - changes imports of standard library
tempfiletoofrak.tempfile - changes
.flush()to.close()insidewith NamedTemporaryFile()blocks - safely reopens files for reading when required
- Changes
ZstdPackerandZstdUnpackerto use stdin/stdout directly instead of writing to temporary files
Anyone you think should look at this, specifically? @whyitfor