From a0a69f78b4c263a9236140adc1480183c46d61c3 Mon Sep 17 00:00:00 2001 From: Mustafa Kemal Gilor Date: Mon, 13 May 2024 15:12:12 +0300 Subject: [PATCH] SearchTask::_run_search: small refactor replace read() seek() with peek(), move regular open to else block, and also move flush_results_buffer to finally block. Signed-off-by: Mustafa Kemal Gilor --- searchkit/search.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/searchkit/search.py b/searchkit/search.py index 5fbda7a..74519fe 100755 --- a/searchkit/search.py +++ b/searchkit/search.py @@ -1179,14 +1179,14 @@ def execute(self): with gzip.open(path, 'rb') as fd: try: # test if file is gzip - fd.read(1) - fd.seek(0) - stats = self._run_search(fd) - self._flush_results_buffer() + fd.peek(1) except OSError: with open(path, 'rb') as fd: stats = self._run_search(fd) - self._flush_results_buffer() + else: + stats = self._run_search(fd) + finally: + self._flush_results_buffer() except UnicodeDecodeError: log.exception("caught UnicodeDecodeError while searching %s", path) raise