]> git.proxmox.com Git - mirror_edk2.git/blame - BaseTools/Source/Python/Common/LongFilePathSupport.py
UefiCpuPkg: Move AsmRelocateApLoopStart from Mpfuncs.nasm to AmdSev.nasm
[mirror_edk2.git] / BaseTools / Source / Python / Common / LongFilePathSupport.py
CommitLineData
1be2ed90
HC
1## @file\r
2# Override built in function file.open to provide support for long file path\r
3#\r
1ccc4d89 4# Copyright (c) 2014 - 2015, Intel Corporation. All rights reserved.<BR>\r
2e351cbe 5# SPDX-License-Identifier: BSD-2-Clause-Patent\r
1be2ed90
HC
6#\r
7\r
8import os\r
9import platform\r
10import shutil\r
1b2467c5 11import codecs\r
1be2ed90
HC
12\r
13##\r
14# OpenLongPath\r
15# Convert a file path to a long file path\r
16#\r
17def LongFilePath(FileName):\r
18 FileName = os.path.normpath(FileName)\r
19 if platform.system() == 'Windows':\r
20 if FileName.startswith('\\\\?\\'):\r
21 return FileName\r
22 if FileName.startswith('\\\\'):\r
23 return '\\\\?\\UNC\\' + FileName[2:]\r
24 if os.path.isabs(FileName):\r
25 return '\\\\?\\' + FileName\r
26 return FileName\r
27\r
28##\r
29# OpenLongFilePath\r
30# wrap open to support opening a long file path\r
31#\r
32def OpenLongFilePath(FileName, Mode='r', Buffer= -1):\r
33 return open(LongFilePath(FileName), Mode, Buffer)\r
34\r
1b2467c5
HC
35def CodecOpenLongFilePath(Filename, Mode='rb', Encoding=None, Errors='strict', Buffering=1):\r
36 return codecs.open(LongFilePath(Filename), Mode, Encoding, Errors, Buffering)\r
37\r
1be2ed90
HC
38##\r
39# CopyLongFilePath\r
40# wrap copyfile to support copy a long file path\r
41#\r
42def CopyLongFilePath(src, dst):\r
43 with open(LongFilePath(src), 'rb') as fsrc:\r
44 with open(LongFilePath(dst), 'wb') as fdst:\r
45 shutil.copyfileobj(fsrc, fdst)\r