From f841c0826b4e5f70a4067718d1e8b4252859244c Mon Sep 17 00:00:00 2001 From: Federico Ressi Date: Wed, 3 Nov 2021 13:50:51 +0100 Subject: [PATCH] Handle file removal concurrency Change-Id: I976faf0f5f66403bdd4f0a01e7d9aef451db5003 --- tools/common.py | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/tools/common.py b/tools/common.py index 74e529ed9..23512fb6c 100644 --- a/tools/common.py +++ b/tools/common.py @@ -124,10 +124,14 @@ def make_dir(dirname): def remove_file(filename): if os.path.isfile(filename): LOG.debug("Remove file: '%s'", filename) - os.unlink(filename) - return True - else: - return False + try: + os.unlink(filename) + except FileNotFoundError: + LOG.debug("File concurrently removed: '%s'", filename) + else: + LOG.debug("File removed: '%s'", filename) + return True + return False @contextlib.contextmanager