cowwoc opened a new pull request, #392:
URL: https://github.com/apache/maven-build-cache-extension/pull/392
Fixes #214
## Problem
When using `attachedOutputs`, executable file permissions are lost during
cache restoration. This is because the standard `java.util.zip` classes do not
preserve Unix file permissions.
## Solution
Switch from `java.util.zip` to **Apache Commons Compress's ZipArchive
classes** which support Unix permissions via `setUnixMode()` and
`getUnixMode()` methods.
## Changes
1. **Add Apache Commons Compress 1.28.0 dependency** (was already transitive
test dependency, now direct compile dependency)
2. **Replace java.util.zip with Commons Compress in CacheUtils**:
- `ZipEntry` → `ZipArchiveEntry`
- `ZipOutputStream` → `ZipArchiveOutputStream`
- `ZipInputStream` → `ZipArchiveInputStream`
3. **Preserve permissions during zip**:
- Read POSIX permissions with `Files.getPosixFilePermissions()`
- Convert to Unix mode integer (e.g., `0755`)
- Store via `zipEntry.setUnixMode()`
4. **Restore permissions during unzip**:
- Read Unix mode from `zipEntry.getUnixMode()`
- Convert to POSIX permissions
- Apply via `Files.setPosixFilePermissions()`
5. **Platform safety**:
- Wrap permission operations in try-catch for
`UnsupportedOperationException`
- Gracefully handle non-POSIX filesystems (Windows, FAT32, etc.)
## Why Apache Commons Compress?
Apache Commons Compress was already a transitive test dependency. Using it
provides a clean, simple solution compared to alternatives:
### With Commons Compress (this PR):
- ✅ 2 lines to preserve permissions: `entry.setUnixMode()` /
`entry.getUnixMode()`
- ✅ Well-tested, maintained by Apache
- ✅ Handles all edge cases and platform differences
- ✅ Same Apache 2.0 license
### Without Commons Compress (JDK-only approach):
- ❌ Would require manually encoding Unix permissions in `ZipEntry` extra
field
- ❌ Complex binary format ([InfoZIP extra field
specification](https://fossies.org/linux/zip/proginfo/extrafld.txt))
- ❌ Error-prone and hard to maintain
- ❌ Platform-specific quirks
- ❌ No standard API - would need reflection or custom binary encoding
**The standard `java.util.zip.ZipEntry` class provides no methods to access
or modify external file attributes that store Unix permissions. Attempting this
with JDK-only code would require:**
1. **Manual binary encoding** of the InfoZIP extra field format
2. **Platform-specific logic** to handle different ZIP implementations
3. **Extensive testing** across different operating systems
4. **Maintenance burden** to keep up with ZIP format changes
In contrast, Apache Commons Compress provides a battle-tested,
well-documented API that handles all this complexity for us.
## Testing
The changes preserve backward compatibility:
- Files without Unix mode (`mode=0`) are unchanged
- Non-POSIX systems gracefully skip permission operations
- Existing zip files without permission data work as before
Tested scenarios:
- ✅ Executable shell scripts (`rwxr-xr-x` / `0755`)
- ✅ Read-only files (`r--r--r--` / `0444`)
- ✅ Regular files (`rw-r--r--` / `0644`)
- ✅ Windows filesystems (permissions skipped gracefully)
## Related Issues
- #214 - Permissions lost when using attachedOutputs
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]