]>
git.proxmox.com Git - mirror_edk2.git/blob - BaseTools/Source/Python/Common/LongFilePathSupport.py
2 # Override built in function file.open to provide support for long file path
4 # Copyright (c) 2014 - 2015, Intel Corporation. All rights reserved.<BR>
5 # SPDX-License-Identifier: BSD-2-Clause-Patent
15 # Convert a file path to a long file path
17 def LongFilePath(FileName
):
18 FileName
= os
.path
.normpath(FileName
)
19 if platform
.system() == 'Windows':
20 if FileName
.startswith('\\\\?\\'):
22 if FileName
.startswith('\\\\'):
23 return '\\\\?\\UNC\\' + FileName
[2:]
24 if os
.path
.isabs(FileName
):
25 return '\\\\?\\' + FileName
30 # wrap open to support opening a long file path
32 def OpenLongFilePath(FileName
, Mode
='r', Buffer
= -1):
33 return open(LongFilePath(FileName
), Mode
, Buffer
)
35 def CodecOpenLongFilePath(Filename
, Mode
='rb', Encoding
=None, Errors
='strict', Buffering
=1):
36 return codecs
.open(LongFilePath(Filename
), Mode
, Encoding
, Errors
, Buffering
)
40 # wrap copyfile to support copy a long file path
42 def CopyLongFilePath(src
, dst
):
43 with
open(LongFilePath(src
), 'rb') as fsrc
:
44 with
open(LongFilePath(dst
), 'wb') as fdst
:
45 shutil
.copyfileobj(fsrc
, fdst
)