summaryrefslogtreecommitdiff
path: root/BaseTools
diff options
context:
space:
mode:
authorFeng, Bob C <bob.c.feng@intel.com>2019-09-04 13:09:00 +0800
committerFeng, Bob C <bob.c.feng@intel.com>2019-09-17 10:19:05 +0800
commit22e75231aee6361c9c13c0be7f3dd083db8f308e (patch)
tree3cc427e988d225acdc788599243eb0b9f67773d4 /BaseTools
parent0075ab2cec500fc679c6b2e4990142b4a2e51050 (diff)
downloadedk2-22e75231aee6361c9c13c0be7f3dd083db8f308e.zip
edk2-22e75231aee6361c9c13c0be7f3dd083db8f308e.tar.gz
edk2-22e75231aee6361c9c13c0be7f3dd083db8f308e.tar.bz2
BaseTools:Remove the unnecessary operation of renaming a file.
REF: https://bugzilla.tianocore.org/show_bug.cgi?id=2183 This patch is going to remove rename call to reduce unnecessary io operation so that saving build time. Cc: Liming Gao <liming.gao@intel.com> Cc: Bob Feng <bob.c.feng@intel.com> Signed-off-by: Zhiju.Fan <zhijux.fan@intel.com> Reviewed-by: Liming Gao <liming.gao@intel.com>
Diffstat (limited to 'BaseTools')
-rwxr-xr-xBaseTools/Source/Python/Common/Misc.py23
1 files changed, 3 insertions, 20 deletions
diff --git a/BaseTools/Source/Python/Common/Misc.py b/BaseTools/Source/Python/Common/Misc.py
index 15ae6a9..714eb84 100755
--- a/BaseTools/Source/Python/Common/Misc.py
+++ b/BaseTools/Source/Python/Common/Misc.py
@@ -492,13 +492,9 @@ def SaveFileOnChange(File, Content, IsBinaryFile=True, FileLock=None):
if GlobalData.gIsWindows and not os.path.exists(File):
- # write temp file, then rename the temp file to the real file
- # to make sure the file be immediate saved to disk
- with tempfile.NamedTemporaryFile(OpenMode, dir=os.path.dirname(File), delete=False) as tf:
- tf.write(Content)
- tempname = tf.name
try:
- os.rename(tempname, File)
+ with open(File, OpenMode) as tf:
+ tf.write(Content)
except IOError as X:
if GlobalData.gBinCacheSource:
EdkLogger.quiet("[cache error]:fails to save file with error: %s" % (X))
@@ -566,21 +562,8 @@ def CopyFileOnChange(SrcFile, Dst, FileLock=None):
if FileLock:
FileLock.acquire()
- # os.replace and os.rename are the atomic operations in python 3 and 2.
- # we use these two atomic operations to ensure the file copy is atomic:
- # copy the src to a temp file in the dst same folder firstly, then
- # replace or rename the temp file to the destination file.
- with tempfile.NamedTemporaryFile(dir=DirName, delete=False) as tf:
- CopyLong(SrcFile, tf.name)
- tempname = tf.name
try:
- if hasattr(os, 'replace'):
- os.replace(tempname, DstFile)
- else:
- # os.rename reqire to remove the dst on Windows, otherwise OSError will be raised.
- if GlobalData.gIsWindows and os.path.exists(DstFile):
- os.remove(DstFile)
- os.rename(tempname, DstFile)
+ CopyLong(SrcFile, DstFile)
except IOError as X:
if GlobalData.gBinCacheSource:
EdkLogger.quiet("[cache error]:fails to copy file with error: %s" % (X))