From: Reyad Attiyat Date: Tue, 23 Jun 2026 20:38:11 +0000 (-0500) Subject: unzip: mark bsdunzip as long-path aware on Windows X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=bf0ce94fecadc762fc0717e15d4c08415ca617ef;p=thirdparty%2Flibarchive.git unzip: mark bsdunzip as long-path aware on Windows Signed-off-by: God-damnit-all <53661808+God-damnit-all@users.noreply.github.com> --- diff --git a/Makefile.am b/Makefile.am index 3e5c4a02a..dff2b32e7 100644 --- a/Makefile.am +++ b/Makefile.am @@ -1690,9 +1690,20 @@ bsdunzip_LDADD= libarchive_fe.la libarchive.la $(LTLIBICONV) bsdunzip_CPPFLAGS= -I$(top_srcdir)/libarchive -I$(top_srcdir)/libarchive_fe $(bsdunzip_ccstatic) $(PLATFORMCPPFLAGS) bsdunzip_LDFLAGS= $(bsdunzip_ldstatic) $(DEAD_CODE_REMOVAL) +if INC_WINDOWS_FILES +# Embed an application manifest marking bsdunzip as long-path aware. +unzip/bsdunzip_rc.$(OBJEXT): $(top_srcdir)/unzip/bsdunzip.rc $(top_srcdir)/unzip/bsdunzip.exe.manifest + $(AM_V_GEN)$(WINDRES) -I $(top_srcdir)/unzip -i $(top_srcdir)/unzip/bsdunzip.rc -o $@ +bsdunzip_LDADD += unzip/bsdunzip_rc.$(OBJEXT) +bsdunzip_DEPENDENCIES += unzip/bsdunzip_rc.$(OBJEXT) +CLEANFILES += unzip/bsdunzip_rc.$(OBJEXT) +endif + bsdunzip_EXTRA_DIST= \ unzip/bsdunzip_windows.h \ unzip/bsdunzip_windows.c \ + unzip/bsdunzip.rc \ + unzip/bsdunzip.exe.manifest \ unzip/bsdunzip.1 \ unzip/CMakeLists.txt diff --git a/unzip/CMakeLists.txt b/unzip/CMakeLists.txt index eb9c28f0a..496b9b368 100644 --- a/unzip/CMakeLists.txt +++ b/unzip/CMakeLists.txt @@ -28,6 +28,15 @@ IF(ENABLE_UNZIP) IF(WIN32 AND NOT CYGWIN) LIST(APPEND bsdunzip_SOURCES bsdunzip_windows.c) LIST(APPEND bsdunzip_SOURCES bsdunzip_windows.h) + IF(NOT MSVC) + # The GNU toolchains (MinGW/Clang) do not generate an application + # manifest, so we embed one through a resource script. + ENABLE_LANGUAGE(RC) + INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR}) + LIST(APPEND bsdunzip_SOURCES bsdunzip.rc) + SET_SOURCE_FILES_PROPERTIES(bsdunzip.rc PROPERTIES + OBJECT_DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/bsdunzip.exe.manifest) + ENDIF(NOT MSVC) ENDIF(WIN32 AND NOT CYGWIN) # bsdunzip documentation @@ -42,6 +51,10 @@ IF(ENABLE_UNZIP) SET_TARGET_PROPERTIES(bsdunzip PROPERTIES COMPILE_DEFINITIONS LIBARCHIVE_STATIC) ENDIF(ENABLE_UNZIP_SHARED) + IF(WIN32 AND NOT CYGWIN AND MSVC) + # MSVC merges .manifest sources into the linker's default manifest + TARGET_SOURCES(bsdunzip PRIVATE bsdunzip.exe.manifest) + ENDIF(WIN32 AND NOT CYGWIN AND MSVC) # Installation rules IF(ENABLE_INSTALL) diff --git a/unzip/bsdunzip.exe.manifest b/unzip/bsdunzip.exe.manifest new file mode 100644 index 000000000..32142e951 --- /dev/null +++ b/unzip/bsdunzip.exe.manifest @@ -0,0 +1,15 @@ + + + + + + + + + + + + true + + + diff --git a/unzip/bsdunzip.rc b/unzip/bsdunzip.rc new file mode 100644 index 000000000..6b4d9b502 --- /dev/null +++ b/unzip/bsdunzip.rc @@ -0,0 +1,19 @@ +/* + * SPDX-License-Identifier: BSD-2-Clause + * + * Embed an application manifest that marks bsdunzip as long-path aware. + * + * bsdunzip's file name handling is limited to MAX_PATH (260) characters unless + * the process opts in to long paths via a "longPathAware" manifest. + * A system-wide LongPathsEnabled registry value is not sufficient on its own; + * the executable must also carry this manifest. Without it, extracting into + * deeply nested destination directories fails. + * + * See: + * https://learn.microsoft.com/windows/win32/fileio/maximum-file-path-limitation + */ + +#define RT_MANIFEST 24 +#define CREATEPROCESS_MANIFEST_RESOURCE_ID 1 + +CREATEPROCESS_MANIFEST_RESOURCE_ID RT_MANIFEST "bsdunzip.exe.manifest"