Commit 7b912ce
committed
Add comprehensive fixes and unit tests for timestamp preservation
Addresses feedback from PR #388 review comments and adds comprehensive
unit tests to validate timestamp preservation through cache operations.
Changes to CacheUtils.java:
1. Implement glob filtering for directory entries
- Track directories containing matching files during visitFile()
- Only add directory entries in postVisitDirectory() if they contain
matching files or no glob filter is active
- Preserves glob pattern contract while maintaining timestamp preservation
2. Fix Files.exists() race condition (TOCTOU vulnerability)
- Remove unnecessary Files.exists() checks before Files.createDirectories()
- Leverage idempotent behavior of createDirectories()
- Eliminates time-of-check-to-time-of-use race condition
3. Add error handling for timestamp operations
- Wrap Files.setLastModifiedTime() in try-catch blocks
- Best-effort timestamp setting with graceful degradation
- Prevents failures on filesystems without timestamp support
New Unit Tests (CacheUtilsTimestampTest.java):
- testFileTimestampPreservation: Verifies file timestamps preserved
- testDirectoryTimestampPreservation: Verifies directory timestamps preserved
- testDirectoryEntriesStoredInZip: Verifies directories stored in zip
- testTimestampsInZipEntries: Verifies zip entry timestamps correct
- testMavenWarningScenario: Reproduces Maven warning about file timestamps
- testMultipleFilesTimestampConsistency: Verifies consistent timestamps
Test Results:
- All 6 tests pass with fixes applied
- Tests are Java 8 compatible using helper methods
- Clear failure messages with timestamp diffs for debugging
Fixes #387
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude <noreply@anthropic.com>1 parent 91e8b9c commit 7b912ce
File tree
2 files changed
+455
-13
lines changed- src
- main/java/org/apache/maven/buildcache
- test/java/org/apache/maven/buildcache
2 files changed
+455
-13
lines changedLines changed: 56 additions & 13 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
32 | 32 | | |
33 | 33 | | |
34 | 34 | | |
| 35 | + | |
35 | 36 | | |
36 | 37 | | |
37 | 38 | | |
| 39 | + | |
38 | 40 | | |
39 | 41 | | |
40 | 42 | | |
| |||
165 | 167 | | |
166 | 168 | | |
167 | 169 | | |
| 170 | + | |
| 171 | + | |
| 172 | + | |
| 173 | + | |
| 174 | + | |
| 175 | + | |
168 | 176 | | |
169 | 177 | | |
170 | 178 | | |
171 | 179 | | |
172 | | - | |
173 | | - | |
174 | | - | |
175 | | - | |
176 | | - | |
177 | | - | |
178 | | - | |
| 180 | + | |
| 181 | + | |
179 | 182 | | |
180 | 183 | | |
181 | 184 | | |
| |||
184 | 187 | | |
185 | 188 | | |
186 | 189 | | |
| 190 | + | |
| 191 | + | |
| 192 | + | |
| 193 | + | |
| 194 | + | |
| 195 | + | |
| 196 | + | |
187 | 197 | | |
188 | 198 | | |
189 | 199 | | |
| |||
194 | 204 | | |
195 | 205 | | |
196 | 206 | | |
| 207 | + | |
| 208 | + | |
| 209 | + | |
| 210 | + | |
| 211 | + | |
| 212 | + | |
| 213 | + | |
| 214 | + | |
| 215 | + | |
| 216 | + | |
| 217 | + | |
| 218 | + | |
| 219 | + | |
| 220 | + | |
| 221 | + | |
| 222 | + | |
| 223 | + | |
| 224 | + | |
| 225 | + | |
| 226 | + | |
| 227 | + | |
| 228 | + | |
| 229 | + | |
197 | 230 | | |
198 | 231 | | |
199 | 232 | | |
| |||
209 | 242 | | |
210 | 243 | | |
211 | 244 | | |
212 | | - | |
213 | | - | |
214 | | - | |
| 245 | + | |
215 | 246 | | |
216 | 247 | | |
217 | 248 | | |
218 | | - | |
| 249 | + | |
219 | 250 | | |
220 | 251 | | |
221 | 252 | | |
222 | | - | |
| 253 | + | |
| 254 | + | |
| 255 | + | |
| 256 | + | |
| 257 | + | |
| 258 | + | |
| 259 | + | |
| 260 | + | |
223 | 261 | | |
224 | 262 | | |
225 | 263 | | |
| |||
228 | 266 | | |
229 | 267 | | |
230 | 268 | | |
231 | | - | |
| 269 | + | |
| 270 | + | |
| 271 | + | |
| 272 | + | |
| 273 | + | |
| 274 | + | |
232 | 275 | | |
233 | 276 | | |
234 | 277 | | |
| |||
0 commit comments