From 2bafa1838fd580369af65308d95f4d4afd48a8f8 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 +++++- news/5569.bugfix.rst | 2 ++ 2 files changed, 7 insertions(+), 1 deletion(-) create mode 100644 news/5569.bugfix.rst diff --git a/PyInstaller/archive/writers.py b/PyInstaller/archive/writers.py index b7b1af2ee3..258cf60664 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)) diff --git a/news/5569.bugfix.rst b/news/5569.bugfix.rst new file mode 100644 index 0000000000..9c13e731c9 --- /dev/null +++ b/news/5569.bugfix.rst @@ -0,0 +1,2 @@ +Fix extraction of nested files in ``onefile`` builds created in MSYS +environments.