You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@netbeans.apache.org by "lkishalmi (via GitHub)" <gi...@apache.org> on 2023/07/07 01:08:01 UTC

[GitHub] [netbeans] lkishalmi commented on a diff in pull request #6148: Rework Janitor, try to use real version numbers, in the future

lkishalmi commented on code in PR #6148:
URL: https://github.com/apache/netbeans/pull/6148#discussion_r1255083440


##########
platform/janitor/src/org/netbeans/modules/janitor/Janitor.java:
##########
@@ -96,39 +95,60 @@ public class Janitor {
 
     private static final String LOGFILE_NAME = "var/log/messages.log"; //NOI18N
     private static final String ALL_CHECKSUM_NAME = "lastModified/all-checksum.txt"; //NOI18N
+    private static final String LAST_VERSION_NAME = ".lastUsedVersion"; //NOI18N
+
+    private static final String NB_VERSION;
+
     @StaticResource
     private static final String CLEAN_ICON = "org/netbeans/modules/janitor/resources/clean.gif"; //NOI18N
 
     static final RequestProcessor JANITOR_RP = new RequestProcessor("janitor", 1); //NOI18N
     static final Map<ActionListener, Notification> CLEANUP_TASKS = new WeakHashMap<>();
 
+    static {
+        String version = System.getProperty("netbeans.buildnumber"); //NOI18N
+        if (version != null) {
+            // remove git hash from the build number
+            int dash = version.lastIndexOf('-');
+            if (dash + 41 == version.length()) { // 40 chars for git SHA sum, 1 for the dash
+                version = version.substring(0, dash);
+            }
+        }
+        NB_VERSION = version;
+    }
+
     static void scanForJunk() {
         // Remove previously opened notifications
         CLEANUP_TASKS.values().forEach((nf) -> nf.clear());
         CLEANUP_TASKS.clear();
 
         Icon clean = ImageUtilities.loadImageIcon(CLEAN_ICON, false);
-        List<Pair<String, Integer>> otherVersions = getOtherVersions();
-
-        for (Pair<String, Integer> ver : otherVersions) {
-            String name = ver.first();
-            Integer age = ver.second();
-            long toFree = size(getUserDir(name)) + size(getCacheDir(name));
-            toFree = toFree / (1_000_000) + 1;
-            if (getUserDir(name) != null) {
-                ActionListener cleanupListener = cleanupAction(name, Bundle.TXT_CONFIRM_CLEANUP(name));
-                Notification nf = NotificationDisplayer.getDefault().notify(
-                        Bundle.TIT_ABANDONED_USERDIR(name, age, toFree),
-                        clean,
-                        Bundle.DESC_ABANDONED_USERDIR(name, age, toFree),
-                        cleanupListener);
-
-                CLEANUP_TASKS.put(cleanupListener, nf);
+        List<CleanupPair> candidates = getCandidates();
+
+        Instant now = Instant.now();
+        int maxUnused = getUnusedDays();
+        
+        for (CleanupPair candidate : candidates) {
+            int age = candidate.age(now);
+            int toFree = candidate.size();
+            String name = candidate.getName();
+            if (candidate.userdir != null) {
+                if (age > maxUnused) {
+                    ActionListener cleanupListener = cleanupAction(candidate, Bundle.TXT_CONFIRM_CLEANUP(name));
+                    Notification nf = NotificationDisplayer.getDefault().notify(
+                            Bundle.TIT_ABANDONED_USERDIR(name, age, toFree),
+                            clean,
+                            Bundle.DESC_ABANDONED_USERDIR(name, age, toFree),
+                            cleanupListener);
+
+                    CLEANUP_TASKS.put(cleanupListener, nf);
+                }
             } else {
                 if (isAutoRemoveAbanconedCache()) {

Review Comment:
   Fixed.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@netbeans.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@netbeans.apache.org
For additional commands, e-mail: notifications-help@netbeans.apache.org

For further information about the NetBeans mailing lists, visit:
https://cwiki.apache.org/confluence/display/NETBEANS/Mailing+lists