@@ -27,27 +27,30 @@ public LibraryCachingCleanup() {
27
27
@ Override protected void execute (TaskListener listener ) throws IOException , InterruptedException {
28
28
FilePath globalCacheDir = LibraryCachingConfiguration .getGlobalLibrariesCacheDir ();
29
29
for (FilePath library : globalCacheDir .list ()) {
30
- if (!removeIfOldCacheDirectory (library , TimeUnit . DAYS . toMillis ( EXPIRE_AFTER_READ_DAYS ) )) {
31
- // Prior to SECURITY-2586 security fixes , library caches had a two-level directory structure.
30
+ if (!removeIfExpiredCacheDirectory (library )) {
31
+ // Prior to the SECURITY-2586 fix , library caches had a two-level directory structure.
32
32
// These caches will never be used again, so we delete any that we find.
33
33
for (FilePath version : library .list ()) {
34
- removeIfOldCacheDirectory (version , 0 );
34
+ if (version .child (LibraryCachingConfiguration .LAST_READ_FILE ).exists ()) {
35
+ library .deleteRecursive ();
36
+ break ;
37
+ }
35
38
}
36
39
}
37
40
}
38
41
}
39
42
40
43
/**
41
- * Delete cache directories for the given library if they are outdated.
44
+ * Delete the specified cache directory if it is outdated.
42
45
* @return true if specified directory is a cache directory, regardless of whether it was outdated. Used to detect
43
46
* whether the cache was created before or after the fix for SECURITY-2586.
44
47
*/
45
- private boolean removeIfOldCacheDirectory (FilePath library , long maxDurationSinceLastReadMillis ) throws IOException , InterruptedException {
48
+ private boolean removeIfExpiredCacheDirectory (FilePath library ) throws IOException , InterruptedException {
46
49
final FilePath lastReadFile = new FilePath (library , LibraryCachingConfiguration .LAST_READ_FILE );
47
50
if (lastReadFile .exists ()) {
48
- if (( System .currentTimeMillis () - lastReadFile .lastModified ()) > maxDurationSinceLastReadMillis ) {
51
+ if (System .currentTimeMillis () - lastReadFile .lastModified () > TimeUnit . DAYS . toMillis ( EXPIRE_AFTER_READ_DAYS ) ) {
49
52
library .deleteRecursive ();
50
- library .withSuffix ("-name.txt" ).delete (); // Harmless if this is a pre-SECURITY-2586 cache directory.
53
+ library .withSuffix ("-name.txt" ).delete ();
51
54
}
52
55
return true ;
53
56
}
0 commit comments