]> git.proxmox.com Git - mirror_edk2.git/commitdiff
BaseTools: loop to retry remove when it fails.
authorJaben Carsey <jaben.carsey@intel.com>
Thu, 10 May 2018 15:14:40 +0000 (23:14 +0800)
committerYonghong Zhu <yonghong.zhu@intel.com>
Mon, 28 May 2018 01:16:03 +0000 (09:16 +0800)
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 <michael.d.kinney@intel.com>
Cc: Liming Gao <liming.gao@intel.com>
Cc: Yonghong Zhu <yonghong.zhu@intel.com>
Contributed-under: TianoCore Contribution Agreement 1.1
Signed-off-by: Jaben Carsey <jaben.carsey@intel.com>
Reviewed-by: Yonghong Zhu <yonghong.zhu@intel.com>
BaseTools/Source/Python/Common/LongFilePathOs.py

index 2e530f9dd77487f8a98ce470ad5ba32cc6c7e2b5..2cebbb276b19f7838d90b09b8dabbadb07eb9fd2 100644 (file)
@@ -1,7 +1,7 @@
 ## @file\r
 # Override built in module os to provide support for long file path\r
 #\r
 ## @file\r
 # Override built in module os to provide support for long file path\r
 #\r
-# Copyright (c) 2014, Intel Corporation. All rights reserved.<BR>\r
+# Copyright (c) 2014 - 2018, Intel Corporation. All rights reserved.<BR>\r
 # This program and the accompanying materials\r
 # are licensed and made available under the terms and conditions of the BSD License\r
 # which accompanies this distribution.  The full text of the license may be found at\r
 # This program and the accompanying materials\r
 # are licensed and made available under the terms and conditions of the BSD License\r
 # which accompanies this distribution.  The full text of the license may be found at\r
@@ -15,6 +15,7 @@ import os
 import LongFilePathOsPath\r
 from Common.LongFilePathSupport import LongFilePath\r
 from Common.LongFilePathSupport import UniToStr\r
 import LongFilePathOsPath\r
 from Common.LongFilePathSupport import LongFilePath\r
 from Common.LongFilePathSupport import UniToStr\r
+import time\r
 \r
 path = LongFilePathOsPath\r
 \r
 \r
 path = LongFilePathOsPath\r
 \r
@@ -22,7 +23,14 @@ def access(path, mode):
     return os.access(LongFilePath(path), mode)\r
 \r
 def remove(path):\r
     return os.access(LongFilePath(path), mode)\r
 \r
 def remove(path):\r
-    return os.remove(LongFilePath(path))\r
+   Timeout = 0.0\r
+   while Timeout < 5.0:\r
+       try:\r
+           return os.remove(LongFilePath(path))\r
+       except:\r
+           time.sleep(0.1)\r
+           Timeout = Timeout + 0.1\r
+   return os.remove(LongFilePath(path))\r
 \r
 def removedirs(name):\r
     return os.removedirs(LongFilePath(name))\r
 \r
 def removedirs(name):\r
     return os.removedirs(LongFilePath(name))\r