# Common routines used by all tools\r
#\r
# Copyright (c) 2007 - 2019, 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
-# http://opensource.org/licenses/bsd-license.php\r
-#\r
-# THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
-# WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
+# SPDX-License-Identifier: BSD-2-Clause-Patent\r
#\r
\r
##\r
from struct import pack\r
import uuid\r
import subprocess\r
+import tempfile\r
from collections import OrderedDict\r
\r
import Common.LongFilePathOs as os\r
from CommonDataClass.Exceptions import BadExpression\r
from Common.caching import cached_property\r
\r
+ArrayIndex = re.compile("\[\s*[0-9a-fA-FxX]*\s*\]")\r
## Regular expression used to find out place holders in string template\r
gPlaceholderPattern = re.compile("\$\{([^$()\s]+)\}", re.MULTILINE | re.UNICODE)\r
\r
#\r
RtPath.Path = TempFullPath\r
RtPath.BaseName = BaseName\r
+ RtPath.OriginalPath = Path\r
#\r
# If file exists, compare contents\r
#\r
if not os.access(DirName, os.W_OK):\r
EdkLogger.error(None, PERMISSION_FAILURE, "Do not have write permission on directory %s" % DirName)\r
\r
+ OpenMode = "w"\r
if IsBinaryFile:\r
+ OpenMode = "wb"\r
+\r
+ if GlobalData.gIsWindows and not os.path.exists(File):\r
+ # write temp file, then rename the temp file to the real file\r
+ # to make sure the file be immediate saved to disk\r
+ with tempfile.NamedTemporaryFile(OpenMode, dir=os.path.dirname(File), delete=False) as tf:\r
+ tf.write(Content)\r
+ tempname = tf.name\r
try:\r
- with open(File, "wb") as Fd:\r
- Fd.write(Content)\r
- except IOError as X:\r
+ os.rename(tempname, File)\r
+ except:\r
EdkLogger.error(None, FILE_CREATE_FAILURE, ExtraData='IOError %s' % X)\r
else:\r
try:\r
- with open(File, 'w') as Fd:\r
+ with open(File, OpenMode) as Fd:\r
Fd.write(Content)\r
except IOError as X:\r
EdkLogger.error(None, FILE_CREATE_FAILURE, ExtraData='IOError %s' % X)\r
p.stderr.close()\r
if err:\r
raise BadExpression("DevicePath: %s" % str(err))\r
- out = out.decode()\r
+ out = out.decode(encoding='utf-8', errors='ignore')\r
Size = len(out.split())\r
out = ','.join(out.split())\r
return '{' + out + '}', Size\r
self.TagName = TagName\r
self.ToolCode = ToolCode\r
self.ToolChainFamily = ToolChainFamily\r
+ self.OriginalPath = self\r
\r
## Convert the object of this class to a string\r
#\r