From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: mx.groups.io; dkim=missing; spf=pass (domain: intel.com, ip: 134.134.136.100, mailfrom: steven.shi@intel.com) Received: from mga07.intel.com (mga07.intel.com [134.134.136.100]) by groups.io with SMTP; Wed, 21 Aug 2019 10:26:59 -0700 X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from fmsmga002.fm.intel.com ([10.253.24.26]) by orsmga105.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 21 Aug 2019 10:26:59 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.64,412,1559545200"; d="scan'208";a="207810227" Received: from jshi19-mobl.ccr.corp.intel.com ([10.249.173.65]) by fmsmga002.fm.intel.com with ESMTP; 21 Aug 2019 10:26:57 -0700 From: "Steven Shi" To: devel@edk2.groups.io Cc: liming.gao@intel.com, bob.c.feng@intel.com, "Shi, Steven" Subject: [PATCH] BaseTools: Support long file path in windows for misc functions Date: Thu, 22 Aug 2019 01:26:20 +0800 Message-Id: <20190821172620.16396-1-steven.shi@intel.com> X-Mailer: git-send-email 2.17.1.windows.2 From: "Shi, Steven" BZ: https://bugzilla.tianocore.org/show_bug.cgi?id=2103 Current CopyFileOnChange() and SaveFileOnChange() in BaseTools\Source\Python\Common\Misc.py don't use the dedicated long file path API to handle the file path strings and cannot support the long file path copy and save in windows. This patch enhances them to support the long file path copy and save correctly. Cc: Liming Gao Cc: Bob Feng Signed-off-by: Steven Shi --- BaseTools/Source/Python/Common/Misc.py | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/BaseTools/Source/Python/Common/Misc.py b/BaseTools/Source/Python/Common/Misc.py index 4799635cc4..15ae6a9e40 100755 --- a/BaseTools/Source/Python/Common/Misc.py +++ b/BaseTools/Source/Python/Common/Misc.py @@ -34,6 +34,8 @@ from Common.BuildToolError import * from CommonDataClass.DataClass import * from Common.Parsing import GetSplitValueList from Common.LongFilePathSupport import OpenLongFilePath as open +from Common.LongFilePathSupport import CopyLongFilePath as CopyLong +from Common.LongFilePathSupport import LongFilePath as LongFilePath from Common.MultipleWorkspace import MultipleWorkspace as mws from CommonDataClass.Exceptions import BadExpression from Common.caching import cached_property @@ -450,6 +452,9 @@ def RemoveDirectory(Directory, Recursively=False): # def SaveFileOnChange(File, Content, IsBinaryFile=True, FileLock=None): + # Convert to long file path format + File = LongFilePath(File) + if os.path.exists(File): if IsBinaryFile: try: @@ -530,6 +535,11 @@ def SaveFileOnChange(File, Content, IsBinaryFile=True, FileLock=None): # @retval False No copy really happen # def CopyFileOnChange(SrcFile, Dst, FileLock=None): + + # Convert to long file path format + SrcFile = LongFilePath(SrcFile) + Dst = LongFilePath(Dst) + if not os.path.exists(SrcFile): return False @@ -561,7 +571,7 @@ def CopyFileOnChange(SrcFile, Dst, FileLock=None): # 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: - shutil.copy(SrcFile, tf.name) + CopyLong(SrcFile, tf.name) tempname = tf.name try: if hasattr(os, 'replace'): -- 2.17.1