You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@netbeans.apache.org by lk...@apache.org on 2022/04/05 20:41:39 UTC
[netbeans] branch master updated: Janitor shall remove abandoned cache dirs
This is an automated email from the ASF dual-hosted git repository.
lkishalmi pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/netbeans.git
The following commit(s) were added to refs/heads/master by this push:
new ab32c030c5 Janitor shall remove abandoned cache dirs
ab32c030c5 is described below
commit ab32c030c5ecb2e948252b0469391b832f9b2665
Author: Laszlo Kishalmi <la...@gmail.com>
AuthorDate: Tue Mar 29 16:35:56 2022 -0700
Janitor shall remove abandoned cache dirs
---
.../src/org/netbeans/modules/janitor/Janitor.java | 26 +++++++++++++++++++++-
1 file changed, 25 insertions(+), 1 deletion(-)
diff --git a/platform/janitor/src/org/netbeans/modules/janitor/Janitor.java b/platform/janitor/src/org/netbeans/modules/janitor/Janitor.java
index f93d60ee27..0d2ee6fe4a 100644
--- a/platform/janitor/src/org/netbeans/modules/janitor/Janitor.java
+++ b/platform/janitor/src/org/netbeans/modules/janitor/Janitor.java
@@ -30,9 +30,11 @@ import java.nio.file.attribute.BasicFileAttributes;
import java.time.Duration;
import java.time.Instant;
import java.time.temporal.ChronoUnit;
+import java.util.HashSet;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
+import java.util.Set;
import java.util.WeakHashMap;
import java.util.concurrent.atomic.AtomicLong;
import java.util.prefs.Preferences;
@@ -70,6 +72,7 @@ public class Janitor {
public static final String PROP_UNUSED_DAYS = "UnusedDays"; //NOI18N
private static final String LOGFILE_NAME = "var/log/messages.log"; //NOI18N
+ private static final String ALL_CHECKSUM_NAME = "lastModified/all-checksum.txt"; //NOI18N
@StaticResource
private static final String CLEAN_ICON = "org/netbeans/modules/janitor/resources/clean.gif"; //NOI18N
@@ -177,7 +180,7 @@ public class Janitor {
}
static void deleteDir(File dir) {
- if (dir == null) return;
+ if ((dir == null) || !dir.exists()) return;
Path path = dir.toPath();
try {
Files.walkFileTree(path, new SimpleFileVisitor<Path>() {
@@ -233,10 +236,12 @@ public class Janitor {
static List<Pair<String, Integer>> getOtherVersions() {
File userDir = Places.getUserDirectory();
List<Pair<String, Integer>> ret = new LinkedList<>();
+ Set<String> availableUserDirs = new HashSet<>();
Instant now = Instant.now();
if (userDir != null) {
File userParent = userDir.getParentFile();
for (File f : userParent.listFiles()) {
+ availableUserDirs.add(f.getName());
Path logFile = new File(f, LOGFILE_NAME).toPath();
if (!f.equals(userDir) && Files.isRegularFile(logFile)) {
try {
@@ -251,6 +256,25 @@ public class Janitor {
}
}
}
+
+ //Search for abandoned cache dirs (cache dirs with no user dir)
+ File cacheDir = Places.getCacheDirectory();
+ if (cacheDir != null) {
+ File cacheParent = cacheDir.getParentFile();
+ for (File f : cacheParent.listFiles()) {
+ if (f.isDirectory() && !availableUserDirs.contains(f.getName())) {
+ if (new File(f, ALL_CHECKSUM_NAME).exists() && !cacheDir.equals(f)) {
+ try {
+ Instant lastModified = Files.getLastModifiedTime(f.toPath()).toInstant();
+ Integer age = (int) Duration.between(lastModified, now).toDays();
+ ret.add(Pair.of(f.getName(), age));
+ } catch (IOException ex) {
+ //Just ignore what we can't process
+ }
+ }
+ }
+ }
+ }
return ret;
}
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@netbeans.apache.org
For additional commands, e-mail: commits-help@netbeans.apache.org
For further information about the NetBeans mailing lists, visit:
https://cwiki.apache.org/confluence/display/NETBEANS/Mailing+lists