From: "Bob Feng" <bob.c.feng@intel.com>
To: devel@edk2.groups.io
Cc: Liming Gao <liming.gao@intel.com>,
Bob Feng <bob.c.feng@intel.com>,
"Zhiju . Fan" <zhijux.fan@intel.com>
Subject: [Patch 3/3] BaseTools:Remove the unnecessary operation of renaming a file.
Date: Tue, 10 Sep 2019 17:17:23 +0800 [thread overview]
Message-ID: <20190910091723.26520-1-bob.c.feng@intel.com> (raw)
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>
---
BaseTools/Source/Python/Common/Misc.py | 23 +++--------------------
1 file changed, 3 insertions(+), 20 deletions(-)
diff --git a/BaseTools/Source/Python/Common/Misc.py b/BaseTools/Source/Python/Common/Misc.py
index 15ae6a9e408f..714eb840ea66 100755
--- a/BaseTools/Source/Python/Common/Misc.py
+++ b/BaseTools/Source/Python/Common/Misc.py
@@ -490,17 +490,13 @@ def SaveFileOnChange(File, Content, IsBinaryFile=True, FileLock=None):
if FileLock:
FileLock.acquire()
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))
else:
EdkLogger.error(None, FILE_CREATE_FAILURE, ExtraData='IOError %s' % X)
@@ -564,25 +560,12 @@ def CopyFileOnChange(SrcFile, Dst, FileLock=None):
if not FileLock:
FileLock = GlobalData.file_lock
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))
else:
EdkLogger.error(None, FILE_COPY_FAILURE, ExtraData='IOError %s' % X)
--
2.20.1.windows.1
reply other threads:[~2019-09-10 9:17 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-list from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20190910091723.26520-1-bob.c.feng@intel.com \
--to=devel@edk2.groups.io \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox