You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Add comprehensive fixes and unit tests for timestamp preservation
Addresses feedback from PR apache#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
Fixesapache#387
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude <noreply@anthropic.com>
0 commit comments