Commit 298f064
committed
Preserve Unix file permissions when caching attachedOutputs
Fixes apache#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
- 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)
- Error-prone and hard to maintain
- Platform-specific quirks
- No standard API - would need reflection or custom binary encoding
## 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)1 parent 8615880 commit 298f064
File tree
2 files changed
+117
-10
lines changed- src/main/java/org/apache/maven/buildcache
2 files changed
+117
-10
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
139 | 139 | | |
140 | 140 | | |
141 | 141 | | |
| 142 | + | |
| 143 | + | |
| 144 | + | |
| 145 | + | |
| 146 | + | |
142 | 147 | | |
143 | 148 | | |
144 | 149 | | |
| |||
Lines changed: 112 additions & 10 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
29 | 29 | | |
30 | 30 | | |
31 | 31 | | |
| 32 | + | |
| 33 | + | |
32 | 34 | | |
33 | 35 | | |
| 36 | + | |
34 | 37 | | |
35 | 38 | | |
| 39 | + | |
36 | 40 | | |
37 | | - | |
38 | | - | |
39 | | - | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
40 | 45 | | |
41 | 46 | | |
42 | 47 | | |
| |||
159 | 164 | | |
160 | 165 | | |
161 | 166 | | |
162 | | - | |
| 167 | + | |
163 | 168 | | |
164 | 169 | | |
165 | 170 | | |
| |||
170 | 175 | | |
171 | 176 | | |
172 | 177 | | |
173 | | - | |
174 | | - | |
175 | | - | |
| 178 | + | |
| 179 | + | |
| 180 | + | |
| 181 | + | |
| 182 | + | |
| 183 | + | |
| 184 | + | |
| 185 | + | |
| 186 | + | |
| 187 | + | |
| 188 | + | |
| 189 | + | |
176 | 190 | | |
177 | 191 | | |
178 | | - | |
| 192 | + | |
179 | 193 | | |
180 | 194 | | |
181 | 195 | | |
| |||
185 | 199 | | |
186 | 200 | | |
187 | 201 | | |
188 | | - | |
189 | | - | |
| 202 | + | |
| 203 | + | |
190 | 204 | | |
191 | 205 | | |
192 | 206 | | |
| |||
200 | 214 | | |
201 | 215 | | |
202 | 216 | | |
| 217 | + | |
| 218 | + | |
| 219 | + | |
| 220 | + | |
| 221 | + | |
| 222 | + | |
| 223 | + | |
| 224 | + | |
| 225 | + | |
| 226 | + | |
| 227 | + | |
| 228 | + | |
203 | 229 | | |
204 | 230 | | |
205 | 231 | | |
| |||
217 | 243 | | |
218 | 244 | | |
219 | 245 | | |
| 246 | + | |
| 247 | + | |
| 248 | + | |
| 249 | + | |
| 250 | + | |
| 251 | + | |
| 252 | + | |
| 253 | + | |
| 254 | + | |
| 255 | + | |
| 256 | + | |
| 257 | + | |
| 258 | + | |
| 259 | + | |
| 260 | + | |
| 261 | + | |
| 262 | + | |
| 263 | + | |
| 264 | + | |
| 265 | + | |
| 266 | + | |
| 267 | + | |
| 268 | + | |
| 269 | + | |
| 270 | + | |
| 271 | + | |
| 272 | + | |
| 273 | + | |
| 274 | + | |
| 275 | + | |
| 276 | + | |
| 277 | + | |
| 278 | + | |
| 279 | + | |
| 280 | + | |
| 281 | + | |
| 282 | + | |
| 283 | + | |
| 284 | + | |
| 285 | + | |
| 286 | + | |
| 287 | + | |
| 288 | + | |
| 289 | + | |
| 290 | + | |
| 291 | + | |
| 292 | + | |
| 293 | + | |
| 294 | + | |
| 295 | + | |
| 296 | + | |
| 297 | + | |
| 298 | + | |
| 299 | + | |
| 300 | + | |
| 301 | + | |
| 302 | + | |
| 303 | + | |
| 304 | + | |
| 305 | + | |
| 306 | + | |
| 307 | + | |
| 308 | + | |
| 309 | + | |
| 310 | + | |
| 311 | + | |
| 312 | + | |
| 313 | + | |
| 314 | + | |
| 315 | + | |
| 316 | + | |
| 317 | + | |
| 318 | + | |
| 319 | + | |
| 320 | + | |
| 321 | + | |
220 | 322 | | |
0 commit comments