Skip to content

Commit bf3d15c

Browse files
Debug messages for libarchive
1 parent bb86700 commit bf3d15c

1 file changed

Lines changed: 22 additions & 0 deletions

File tree

src/CMakeLists.txt

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -237,9 +237,31 @@ set(ENABLE_LZMA ON CACHE BOOL "")
237237
set(POSIX_REGEX_LIB "libc" CACHE STRING "Regex library for libarchive")
238238
set(LIBARCHIVE_VERSION "3.8.1")
239239

240+
# Create patch for LZMA debugging
241+
set(LIBARCHIVE_LZMA_PATCH_FILE "${CMAKE_CURRENT_BINARY_DIR}/libarchive_lzma_debug_patch.cmake")
242+
file(WRITE ${LIBARCHIVE_LZMA_PATCH_FILE} "
243+
file(READ \"\${CMAKE_CURRENT_SOURCE_DIR}/libarchive/archive_read_support_filter_xz.c\" CONTENT)
244+
245+
# Add LZMA debug messages for LZMA_DATA_ERROR
246+
string(REPLACE
247+
\"case LZMA_DATA_ERROR:\\n\\t\\tarchive_set_error(&self->archive->archive,\\n\\t\\t ARCHIVE_ERRNO_MISC,\\n\\t\\t \\\"Lzma library error: Corrupted input data\\\");\\n\\t\\tbreak;\"
248+
\"case LZMA_DATA_ERROR:\\n\\t\\t/* Enhanced debug information for LZMA_DATA_ERROR */\\n\\t\\tfprintf(stderr, \\\"LZMA DEBUG: Corrupted input data detected\\\\n\\\");\\n\\t\\tfprintf(stderr, \\\"LZMA DEBUG: - Available input bytes: %zu\\\\n\\\", self->stream.avail_in);\\n\\t\\tarchive_set_error(&self->archive->archive,\\n\\t\\t ARCHIVE_ERRNO_MISC,\\n\\t\\t \\\"Lzma library error: Corrupted input data (see debug output)\\\");\\n\\t\\tbreak;\"
249+
CONTENT \"\${CONTENT}\")
250+
251+
# Add LZMA debug messages for LZMA_FORMAT_ERROR
252+
string(REPLACE
253+
\"case LZMA_FORMAT_ERROR:\\n\\t\\tarchive_set_error(&self->archive->archive,\\n\\t\\t ARCHIVE_ERRNO_MISC,\\n\\t\\t \\\"Lzma library error: format not recognized\\\");\\n\\t\\tbreak;\"
254+
\"case LZMA_FORMAT_ERROR:\\n\\t\\t/* Enhanced debug information for LZMA_FORMAT_ERROR */\\n\\t\\tfprintf(stderr, \\\"LZMA DEBUG: Format not recognized\\\\n\\\");\\n\\t\\tfprintf(stderr, \\\"LZMA DEBUG: - Available input bytes: %zu\\\\n\\\", self->stream.avail_in);\\n\\t\\tfprintf(stderr, \\\"LZMA DEBUG: - First 8 bytes: \\\");\\n\\t\\tfor (int i = 0; i < 8 && i < self->stream.avail_in; i++) {\\n\\t\\t\\tfprintf(stderr, \\\"%02x \\\", self->stream.next_in[i]);\\n\\t\\t}\\n\\t\\tfprintf(stderr, \\\"\\\\n\\\");\\n\\t\\tarchive_set_error(&self->archive->archive,\\n\\t\\t ARCHIVE_ERRNO_MISC,\\n\\t\\t \\\"Lzma library error: format not recognized (see debug output)\\\");\\n\\t\\tbreak;\"
255+
CONTENT \"\${CONTENT}\")
256+
257+
file(WRITE \"\${CMAKE_CURRENT_SOURCE_DIR}/libarchive/archive_read_support_filter_xz.c\" \"\${CONTENT}\")
258+
message(STATUS \"Patched libarchive with LZMA debug messages\")
259+
")
260+
240261
FetchContent_Declare(libarchive
241262
GIT_REPOSITORY https://github.com/libarchive/libarchive.git
242263
GIT_TAG v${LIBARCHIVE_VERSION}
264+
PATCH_COMMAND ${CMAKE_COMMAND} -P ${LIBARCHIVE_LZMA_PATCH_FILE}
243265
${USE_OVERRIDE_FIND_PACKAGE}
244266
)
245267
FetchContent_MakeAvailable(libarchive)

0 commit comments

Comments
 (0)