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>
## @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
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
\r
path = LongFilePathOsPath\r
\r
\r
path = LongFilePathOsPath\r
\r
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