Skip directory entries when unpacking (fixes mcpb unpack on standard ZIP archives)#268
Open
aosmcleod wants to merge 1 commit into
Open
Conversation
ZIP archives produced by standard tooling (e.g. `zip -r`) include explicit directory entries (keys ending in "/") with empty data. unpackExtension wrote every entry unconditionally, so the trailing-slash path write failed and aborted the entire unpack — making `mcpb unpack` unusable on most real-world .mcpb files not produced by `mcpb pack` itself. Skip directory entries; needed parents are already created. Adds a regression test using a zip with a directory entry. Fixes modelcontextprotocol#261
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
mcpb unpackaborts on any archive containing explicit directory entries (keys ending in/). Standard ZIP tooling (zip -r, most language libraries) emits these, so unpack fails on the majority of real-world.mcpbfiles not produced bymcpb packitself: the trailing-slash write fails withENOENT/EISDIRand the throw aborts the whole extraction.Fixes #261.
Fix
Skip directory entries in the extraction loop (
src/cli/unpack.ts). Needed parent directories are already created by the existingmkdirSync, so no functionality is lost.Test
Adds
test/unpack.test.ts: builds a ZIP with aserver/directory entry via fflate'szipSyncand asserts unpack succeeds and extracts the nested file. Verified the test fails against the old code and passes with the fix.yarn lintandyarn testpass.