From 3217ed10bb9371ff25cb04e194e0250d42f89206 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Michal=20=C4=8Ciha=C5=99?= Date: Tue, 7 Nov 2023 08:42:56 +0100 Subject: [PATCH] optrecurse: properly close opened files This avoids leaking file descriptors in the tests and makes sure the content is written at the end of conversion. Fixes #5071 --- translate/misc/optrecurse.py | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/translate/misc/optrecurse.py b/translate/misc/optrecurse.py index d69666b8e8..9337c7c4ff 100644 --- a/translate/misc/optrecurse.py +++ b/translate/misc/optrecurse.py @@ -684,10 +684,17 @@ def processfile( tempoutput = False templatefile = self.opentemplatefile(options, fulltemplatepath) passthroughoptions = self.getpassthroughoptions(options) - if fileprocessor(inputfile, outputfile, templatefile, **passthroughoptions): + result = fileprocessor( + inputfile, outputfile, templatefile, **passthroughoptions + ) + if fullinputpath is not None: + inputfile.close() + if result: if tempoutput: self.warning("writing to temporary output...") self.finalizetempoutputfile(options, outputfile, fulloutputpath) + if fulloutputpath and os.path.isfile(fulloutputpath): + outputfile.close() return True else: # remove the file if it is a file (could be stdout etc)