From a07e5eaf7e9c87c796289ba42da987a09b7e2f36 Mon Sep 17 00:00:00 2001 From: Rok Mandeljc Date: Fri, 19 Feb 2021 13:37:19 +0100 Subject: [PATCH] archive: fix stored paths when building under MSYS When building CArchive package under MSYS, os.path.sep is Unix-style forward clash separator that is incompatible with bootloader (which on Windows expects back slash separators). Therefore, if we are on Windows and os.path.sep is forward slash, os.path.normpath() in CTOC.add() needs to be followed by explicit replacement of forward slashes with back slashes. Otherwise, bootloader fails to extract nested files from archive in onefile builds that are created in MSYS environment. --- PyInstaller/archive/writers.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/PyInstaller/archive/writers.py b/PyInstaller/archive/writers.py index b7b1af2ee3f..258cf606646 100644 --- a/PyInstaller/archive/writers.py +++ b/PyInstaller/archive/writers.py @@ -35,7 +35,7 @@ fake_pyc_timestamp from PyInstaller.loader.pyimod02_archive import PYZ_TYPE_MODULE, PYZ_TYPE_PKG, \ PYZ_TYPE_DATA, PYZ_TYPE_NSPKG -from ..compat import BYTECODE_MAGIC, is_py37 +from ..compat import BYTECODE_MAGIC, is_py37, is_win class ArchiveWriter(object): @@ -283,6 +283,10 @@ def add(self, dpos, dlen, ulen, flag, typcd, nm): # slashes '\\' since on Windows the bootloader works only with back # slashes. nm = os.path.normpath(nm) + if is_win and os.path.sep == '/': + # When building under MSYS, the above path normalization + # uses Unix-style separators, so replace them manually. + nm = nm.replace(os.path.sep, '\\') self.data.append((dpos, dlen, ulen, flag, typcd, nm))