From d0aee4f72bac9ee320177e7f08a98728a0330e08 Mon Sep 17 00:00:00 2001 From: Roberto Rosario Date: Mon, 27 Jun 2016 19:21:42 -0400 Subject: [PATCH] Add parameter to fs_cleanup function to close a file descriptor before closing it. GitLab issue #309. --- mayan/apps/common/utils.py | 5 ++++- mayan/apps/ocr/parsers.py | 4 ++-- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/mayan/apps/common/utils.py b/mayan/apps/common/utils.py index 56889d2774..1f03bc2e23 100644 --- a/mayan/apps/common/utils.py +++ b/mayan/apps/common/utils.py @@ -45,10 +45,13 @@ def encapsulate(function): return lambda: function -def fs_cleanup(filename, suppress_exceptions=True): +def fs_cleanup(filename, file_descriptor=None, suppress_exceptions=True): """ Tries to remove the given filename. Ignores non-existent files """ + if file_descriptor: + os.close(file_descriptor) + try: os.remove(filename) except OSError: diff --git a/mayan/apps/ocr/parsers.py b/mayan/apps/ocr/parsers.py index 16f8539abd..861f4c212d 100644 --- a/mayan/apps/ocr/parsers.py +++ b/mayan/apps/ocr/parsers.py @@ -155,12 +155,12 @@ class PopplerParser(Parser): return_code = proc.wait() if return_code != 0: logger.error(proc.stderr.readline()) - fs_cleanup(temp_filepath) + fs_cleanup(temp_filepath, file_descriptor=destination_descriptor) raise ParserError output = proc.stdout.read() - fs_cleanup(temp_filepath) + fs_cleanup(temp_filepath, file_descriptor=destination_descriptor) if output == b'\x0c': logger.debug('Parser didn\'t return any output')