Commit 3d534ee
committed
Add preservePermissions config and include permissions in cache checksum
When preservePermissions=true (default), Unix file permissions are stored in
ZIP entry headers, making them part of the ZIP file's binary content. This
ensures that hashing the ZIP file (for cache keys) includes permission
information, providing proper cache invalidation when file permissions change.
This addresses the architectural correctness concern raised in PR apache#392 review:
permissions should be in the checksum if they're being preserved, similar to
how Git includes file mode in tree hashes.
Changes:
- Added preservePermissions boolean parameter to CacheUtils.zip() and unzip()
- Added preservePermissions config option to build-cache-config.mdo (default: true)
- Added isPreservePermissions() method to CacheConfig interface and implementation
- Updated CacheControllerImpl to pass preservePermissions config to zip/unzip
- Made permission preservation conditional based on the config flag
- Fixed permissionsToMode() to include file type bits (0100000 for regular files)
- Added comprehensive tests:
* testPermissionsAffectFileHashWhenEnabled() - Verifies different permissions
produce different ZIP hashes when preservation is enabled
* testPermissionsDoNotAffectHashWhenDisabled() - Verifies permissions are NOT
preserved when the flag is disabled
- Added JavaDoc explaining that permissions become part of cache checksum
Behavior:
- preservePermissions=true: Permissions stored in ZIP, affect cache key (default)
- preservePermissions=false: Permissions not preserved, files use system umask
This is analogous to Git's treatment of file mode in tree hashes, ensuring
that metadata included in cache restoration is also part of cache key computation.
Optimize filesystem capability check to avoid repeated exceptions
Addresses reviewer feedback: check once if filesystem supports POSIX file
attributes instead of throwing and catching UnsupportedOperationException
for every file during zip/unzip operations.
Changes:
- Added single filesystem capability check at the beginning of zip() and unzip()
- Removed try-catch blocks from inside the file iteration loops
- Improved performance on non-POSIX filesystems (e.g., Windows)
Before: UnsupportedOperationException thrown and caught for every file
After: Single supportedFileAttributeViews() check per zip/unzip operation
This is more efficient and cleaner code while maintaining identical behavior.1 parent 298f064 commit 3d534ee
File tree
6 files changed
+209
-17
lines changed- src
- main
- java/org/apache/maven/buildcache
- xml
- mdo
- test/java/org/apache/maven/buildcache
6 files changed
+209
-17
lines changedLines changed: 2 additions & 2 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
881 | 881 | | |
882 | 882 | | |
883 | 883 | | |
884 | | - | |
| 884 | + | |
885 | 885 | | |
886 | 886 | | |
887 | 887 | | |
| |||
896 | 896 | | |
897 | 897 | | |
898 | 898 | | |
899 | | - | |
| 899 | + | |
900 | 900 | | |
901 | 901 | | |
902 | 902 | | |
| |||
Lines changed: 28 additions & 15 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
159 | 159 | | |
160 | 160 | | |
161 | 161 | | |
| 162 | + | |
| 163 | + | |
| 164 | + | |
| 165 | + | |
| 166 | + | |
| 167 | + | |
162 | 168 | | |
163 | 169 | | |
164 | 170 | | |
165 | | - | |
| 171 | + | |
166 | 172 | | |
| 173 | + | |
| 174 | + | |
| 175 | + | |
| 176 | + | |
167 | 177 | | |
168 | 178 | | |
169 | 179 | | |
| |||
178 | 188 | | |
179 | 189 | | |
180 | 190 | | |
181 | | - | |
182 | | - | |
| 191 | + | |
| 192 | + | |
183 | 193 | | |
184 | 194 | | |
185 | | - | |
186 | | - | |
187 | 195 | | |
188 | 196 | | |
189 | 197 | | |
| |||
198 | 206 | | |
199 | 207 | | |
200 | 208 | | |
201 | | - | |
| 209 | + | |
| 210 | + | |
| 211 | + | |
| 212 | + | |
| 213 | + | |
202 | 214 | | |
203 | 215 | | |
204 | 216 | | |
| |||
215 | 227 | | |
216 | 228 | | |
217 | 229 | | |
218 | | - | |
219 | | - | |
220 | | - | |
221 | | - | |
| 230 | + | |
| 231 | + | |
| 232 | + | |
| 233 | + | |
222 | 234 | | |
223 | 235 | | |
224 | | - | |
225 | | - | |
226 | 236 | | |
227 | 237 | | |
228 | 238 | | |
| |||
248 | 258 | | |
249 | 259 | | |
250 | 260 | | |
251 | | - | |
| 261 | + | |
252 | 262 | | |
253 | 263 | | |
254 | | - | |
| 264 | + | |
| 265 | + | |
| 266 | + | |
255 | 267 | | |
256 | 268 | | |
257 | 269 | | |
| |||
285 | 297 | | |
286 | 298 | | |
287 | 299 | | |
288 | | - | |
| 300 | + | |
289 | 301 | | |
290 | 302 | | |
291 | 303 | | |
292 | 304 | | |
| 305 | + | |
293 | 306 | | |
294 | 307 | | |
295 | 308 | | |
| |||
Lines changed: 2 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
108 | 108 | | |
109 | 109 | | |
110 | 110 | | |
| 111 | + | |
| 112 | + | |
111 | 113 | | |
112 | 114 | | |
113 | 115 | | |
| |||
Lines changed: 7 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
578 | 578 | | |
579 | 579 | | |
580 | 580 | | |
| 581 | + | |
| 582 | + | |
| 583 | + | |
| 584 | + | |
| 585 | + | |
| 586 | + | |
| 587 | + | |
581 | 588 | | |
582 | 589 | | |
583 | 590 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
376 | 376 | | |
377 | 377 | | |
378 | 378 | | |
| 379 | + | |
| 380 | + | |
| 381 | + | |
| 382 | + | |
| 383 | + | |
| 384 | + | |
379 | 385 | | |
380 | 386 | | |
381 | 387 | | |
| |||
Lines changed: 164 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
| 117 | + | |
| 118 | + | |
| 119 | + | |
| 120 | + | |
| 121 | + | |
| 122 | + | |
| 123 | + | |
| 124 | + | |
| 125 | + | |
| 126 | + | |
| 127 | + | |
| 128 | + | |
| 129 | + | |
| 130 | + | |
| 131 | + | |
| 132 | + | |
| 133 | + | |
| 134 | + | |
| 135 | + | |
| 136 | + | |
| 137 | + | |
| 138 | + | |
| 139 | + | |
| 140 | + | |
| 141 | + | |
| 142 | + | |
| 143 | + | |
| 144 | + | |
| 145 | + | |
| 146 | + | |
| 147 | + | |
| 148 | + | |
| 149 | + | |
| 150 | + | |
| 151 | + | |
| 152 | + | |
| 153 | + | |
| 154 | + | |
| 155 | + | |
| 156 | + | |
| 157 | + | |
| 158 | + | |
| 159 | + | |
| 160 | + | |
| 161 | + | |
| 162 | + | |
| 163 | + | |
| 164 | + | |
0 commit comments