Skip to content

fix: preserve file permissions during unpack operation#1

Open
erik-at-flipside wants to merge 1 commit intomainfrom
unpack-preserve-file-permissions
Open

fix: preserve file permissions during unpack operation#1
erik-at-flipside wants to merge 1 commit intomainfrom
unpack-preserve-file-permissions

Conversation

@erik-at-flipside
Copy link
Collaborator

Summary

  • Fixes executable file permissions being lost during pack/unpack operations
  • Adds ZIP central directory parsing to extract Unix file permissions from packed archives
  • Restores file permissions using chmodSync() after unpacking files
  • Includes comprehensive test coverage for both executable and regular file permission preservation

Problem

When packing extensions that contain executable files (like binary executables or shell scripts), the unpack operation was not preserving the original file permissions. This meant that executable files would lose their execute permissions (-rwxr-xr-x-rw-r--r--), breaking functionality for extensions that depend on executable binaries.

Solution

The fix involves:

  1. ZIP metadata parsing: Parse the ZIP central directory to extract file attributes stored during the pack operation
  2. Permission restoration: Use fs.chmodSync() to restore Unix file permissions after writing each file
  3. Platform-specific handling: Only attempt permission restoration on Unix-like systems (skip on Windows)
  4. Error handling: Silently ignore permission restoration errors to avoid breaking the unpack process

Test Plan

  • Added unit test that verifies executable permissions (0o755) are preserved
  • Added unit test that verifies regular file permissions (0o644) are preserved
  • Test automatically skips on Windows where Unix permissions don't apply
  • Manual testing with real executable files confirms permissions are restored
  • Fixed existing test setup to use npm instead of yarn for consistency

Technical Details

The pack operation already correctly stores Unix permissions in the ZIP file's external attributes field (implemented in modelcontextprotocol#14). This PR completes the round-trip by extracting and restoring those permissions during unpack.

The ZIP central directory format stores file permissions in the upper 16 bits of the external attributes field. The fix parses this metadata and maps it back to the original file paths for restoration.

🤖 Generated with Claude Code

@erik-at-flipside erik-at-flipside force-pushed the unpack-preserve-file-permissions branch from c1bbdc7 to 21185e8 Compare July 3, 2025 16:56
- Parse ZIP central directory to extract Unix file permissions
- Restore executable permissions using chmodSync after unpacking files
- Skip permission restoration on Windows (Unix-only feature)
- Add comprehensive test to verify executable and regular file permissions are preserved
- Fix test setup to use npm instead of yarn for consistent build process

Fixes issue where executable files lose their execute permissions after being packed and unpacked, which is critical for extensions containing binary executables or shell scripts.

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
@erik-at-flipside erik-at-flipside force-pushed the unpack-preserve-file-permissions branch from 21185e8 to c8f7931 Compare July 9, 2025 15:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant