From efa88d51da7163200f13dfc796a328847c45a058 Mon Sep 17 00:00:00 2001 From: Jaben Carsey Date: Thu, 10 May 2018 23:14:40 +0800 Subject: [PATCH] BaseTools: loop to retry remove when it fails. There is a common race condition when the OS fails to release a file fast enough. this adds a retry loop. v2 - Add a timeout. Cc: Mike Kinney Cc: Liming Gao Cc: Yonghong Zhu Contributed-under: TianoCore Contribution Agreement 1.1 Signed-off-by: Jaben Carsey Reviewed-by: Yonghong Zhu --- BaseTools/Source/Python/Common/LongFilePathOs.py | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/BaseTools/Source/Python/Common/LongFilePathOs.py b/BaseTools/Source/Python/Common/LongFilePathOs.py index 2e530f9dd7..2cebbb276b 100644 --- a/BaseTools/Source/Python/Common/LongFilePathOs.py +++ b/BaseTools/Source/Python/Common/LongFilePathOs.py @@ -1,7 +1,7 @@ ## @file # Override built in module os to provide support for long file path # -# Copyright (c) 2014, Intel Corporation. All rights reserved.
+# Copyright (c) 2014 - 2018, Intel Corporation. All rights reserved.
# This program and the accompanying materials # are licensed and made available under the terms and conditions of the BSD License # which accompanies this distribution. The full text of the license may be found at @@ -15,6 +15,7 @@ import os import LongFilePathOsPath from Common.LongFilePathSupport import LongFilePath from Common.LongFilePathSupport import UniToStr +import time path = LongFilePathOsPath @@ -22,7 +23,14 @@ def access(path, mode): return os.access(LongFilePath(path), mode) def remove(path): - return os.remove(LongFilePath(path)) + Timeout = 0.0 + while Timeout < 5.0: + try: + return os.remove(LongFilePath(path)) + except: + time.sleep(0.1) + Timeout = Timeout + 0.1 + return os.remove(LongFilePath(path)) def removedirs(name): return os.removedirs(LongFilePath(name)) -- 2.39.2