BaseTools: Support long file path in windows for misc functions

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 <liming.gao@intel.com>
Cc: Bob Feng <bob.c.feng@intel.com>
Signed-off-by: Steven Shi <steven.shi@intel.com>
Reviewed-by: Bob Feng <bob.c.feng@intel.com>
This commit is contained in:
Shi, Steven
2019-08-22 10:43:59 +08:00
committed by Feng, Bob C
parent 1237517b21
commit 6dd9aa4019

View File

@ -34,6 +34,8 @@ from Common.BuildToolError import *
from CommonDataClass.DataClass import * from CommonDataClass.DataClass import *
from Common.Parsing import GetSplitValueList from Common.Parsing import GetSplitValueList
from Common.LongFilePathSupport import OpenLongFilePath as open 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 Common.MultipleWorkspace import MultipleWorkspace as mws
from CommonDataClass.Exceptions import BadExpression from CommonDataClass.Exceptions import BadExpression
from Common.caching import cached_property from Common.caching import cached_property
@ -450,6 +452,9 @@ def RemoveDirectory(Directory, Recursively=False):
# #
def SaveFileOnChange(File, Content, IsBinaryFile=True, FileLock=None): def SaveFileOnChange(File, Content, IsBinaryFile=True, FileLock=None):
# Convert to long file path format
File = LongFilePath(File)
if os.path.exists(File): if os.path.exists(File):
if IsBinaryFile: if IsBinaryFile:
try: try:
@ -530,6 +535,11 @@ def SaveFileOnChange(File, Content, IsBinaryFile=True, FileLock=None):
# @retval False No copy really happen # @retval False No copy really happen
# #
def CopyFileOnChange(SrcFile, Dst, FileLock=None): def CopyFileOnChange(SrcFile, Dst, FileLock=None):
# Convert to long file path format
SrcFile = LongFilePath(SrcFile)
Dst = LongFilePath(Dst)
if not os.path.exists(SrcFile): if not os.path.exists(SrcFile):
return False 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 # copy the src to a temp file in the dst same folder firstly, then
# replace or rename the temp file to the destination file. # replace or rename the temp file to the destination file.
with tempfile.NamedTemporaryFile(dir=DirName, delete=False) as tf: with tempfile.NamedTemporaryFile(dir=DirName, delete=False) as tf:
shutil.copy(SrcFile, tf.name) CopyLong(SrcFile, tf.name)
tempname = tf.name tempname = tf.name
try: try:
if hasattr(os, 'replace'): if hasattr(os, 'replace'):