public inbox for cygwin-apps@cygwin.com
 help / color / mirror / Atom feed
From: Christian Franke <Christian.Franke@t-online.de>
To: cygwin-apps@cygwin.com
Subject: [PATCH setup] Add view mode "Unneeded"
Date: Tue, 2 Aug 2022 14:17:26 +0200	[thread overview]
Message-ID: <68d66187-7b70-9fb0-fd12-e1dca7e08399@t-online.de> (raw)

[-- Attachment #1: Type: text/plain, Size: 500 bytes --]

In long standing cygwin installations, many no longer needed 
automatically installed packages (e.g. libicuNN) accumulate. This patch 
adds a new view which is possibly helpful to cleanup packages manually.

Some possible later enhancements:
- automatically refresh this view (a few seconds) after the user changed 
a package status as this may add or remove entries.
- add a keyboard shortcut (^U) to the list view for "Uninstall this 
package and then select next package"

-- 
Regards,
Christian


[-- Attachment #2: 0001-Add-view-mode-Unneeded.patch --]
[-- Type: text/plain, Size: 4818 bytes --]

From 07a2e561b7ba19817a0bebb2cbf542a9b18a6d4e Mon Sep 17 00:00:00 2001
From: Christian Franke <christian.franke@t-online.de>
Date: Tue, 2 Aug 2022 13:54:30 +0200
Subject: [PATCH] Add view mode "Unneeded"

This view shows installed packages which could be safely removed.
---
 PickView.cc   | 47 ++++++++++++++++++++++++++++++++++++++++++++++-
 PickView.h    |  1 +
 res/en/res.rc |  1 +
 res/fr/res.rc |  1 +
 resource.h    |  1 +
 5 files changed, 50 insertions(+), 1 deletion(-)

diff --git a/PickView.cc b/PickView.cc
index c961b9f..b7a37b5 100644
--- a/PickView.cc
+++ b/PickView.cc
@@ -17,6 +17,7 @@
 #include "PickPackageLine.h"
 #include "PickCategoryLine.h"
 #include <algorithm>
+#include <set>
 #include <limits.h>
 #include <shlwapi.h>
 
@@ -28,6 +29,40 @@
 #include "LogSingleton.h"
 #include "Exception.h"
 
+// Scan installed or desired packages and collect the names of packages
+// which provide the dependencies of other packages or are member of
+// category "Base".
+static void FindNeededPackages (const packagedb & db, std::set<std::string> & needed)
+{
+  std::map<std::string, std::string> providedBy;
+  for (const auto & p : db.packages)
+    {
+      const packagemeta & pkg = *p.second;
+      if (!pkg.isBinary ())
+        continue;
+      if (!(pkg.desired && (pkg.installed || pkg.picked ())))
+        continue;
+      for (const PackageSpecification *s : pkg.desired.provides ())
+        providedBy.insert ({s->packageName (), pkg.name});
+    }
+  for (const auto & p : db.packages)
+    {
+      const packagemeta & pkg = *p.second;
+      if (!pkg.isBinary ())
+        continue;
+      if (pkg.categories.count ("Base"))
+        needed.insert (pkg.name);
+      if (!(pkg.desired && (pkg.installed || pkg.picked ())))
+        continue;
+      for (const PackageSpecification *s : pkg.desired.depends ()) {
+        const auto i = providedBy.find (s->packageName ());
+        if (i == providedBy.end ())
+          continue;
+        needed.insert (i->second);
+      }
+    }
+}
+
 void
 PickView::setViewMode (views mode)
 {
@@ -47,6 +82,10 @@ PickView::setViewMode (views mode)
     }
   else
     {
+      std::set<std::string> needed;
+      if (view_mode == PickView::views::PackageUnneeded)
+        FindNeededPackages (db, needed);
+
       // iterate through every package
       for (packagedb::packagecollection::iterator i = db.packages.begin ();
             i != db.packages.end (); ++i)
@@ -77,7 +116,11 @@ PickView::setViewMode (views mode)
 
               // "UserPick" : installed packages that were picked by user
               || (view_mode == PickView::views::PackageUserPicked &&
-                  (pkg.installed && pkg.user_picked)))
+                  (pkg.installed && pkg.user_picked))
+
+              // "Unneeded" : installed packages which could be safely removed
+              || (view_mode == PickView::views::PackageUnneeded &&
+                  (pkg.installed && !needed.count (pkg.name))))
             {
               // Filter by package name
               if (packageFilterString.empty ()
@@ -111,6 +154,8 @@ PickView::mode_caption (views mode)
       return IDS_VIEW_NOTINSTALLED;
     case views::PackageUserPicked:
       return IDS_VIEW_PICKED;
+    case views::PackageUnneeded:
+      return IDS_VIEW_UNNEEDED;
     case views::Category:
       return IDS_VIEW_CATEGORY;
     default:
diff --git a/PickView.h b/PickView.h
index 1e14a74..f2dbfa9 100644
--- a/PickView.h
+++ b/PickView.h
@@ -36,6 +36,7 @@ public:
     PackageKeeps,
     PackageSkips,
     PackageUserPicked,
+    PackageUnneeded,
     Category,
   };
 
diff --git a/res/en/res.rc b/res/en/res.rc
index 644b252..9517bb2 100644
--- a/res/en/res.rc
+++ b/res/en/res.rc
@@ -578,6 +578,7 @@ BEGIN
     IDS_VIEW_UPTODATE "Up To Date"
     IDS_VIEW_NOTINSTALLED "Not Installed"
     IDS_VIEW_PICKED "Picked"
+    IDS_VIEW_UNNEEDED "Unneeded"
     IDS_VIEW_CATEGORY "Category"
     IDS_COLUMN_PACKAGE "Package"
     IDS_COLUMN_CURRENT "Current"
diff --git a/res/fr/res.rc b/res/fr/res.rc
index a0a7909..d787fdb 100644
--- a/res/fr/res.rc
+++ b/res/fr/res.rc
@@ -564,6 +564,7 @@ BEGIN
     IDS_VIEW_UPTODATE "À jour"
     IDS_VIEW_NOTINSTALLED "Non installé"
     IDS_VIEW_PICKED "Sélectionné"
+    // IDS_VIEW_UNNEEDED "XXX: missing translation"
     IDS_VIEW_CATEGORY  "Catégorie"
     IDS_COLUMN_PACKAGE "Paquet"
     IDS_COLUMN_CURRENT "Actuel"
diff --git a/resource.h b/resource.h
index 2668dd9..8c33794 100644
--- a/resource.h
+++ b/resource.h
@@ -105,6 +105,7 @@
 #define IDS_FILE_INUSE_MSG               1208
 #define IDS_DEPRECATED_WINDOWS_VERSION   1209
 #define IDS_DEPRECATED_WINDOWS_ARCH      1210
+#define IDS_VIEW_UNNEEDED                1211
 
 #define IDS_HELPTEXT_COMPACTOS           1500
 #define IDS_HELPTEXT_PUBKEY              1501
-- 
2.37.1


             reply	other threads:[~2022-08-02 12:17 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-08-02 12:17 Christian Franke [this message]
2022-08-14 13:55 ` Jon Turney
2022-08-15 13:04   ` Christian Franke
2022-08-16 19:57     ` Jon Turney

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=68d66187-7b70-9fb0-fd12-e1dca7e08399@t-online.de \
    --to=christian.franke@t-online.de \
    --cc=cygwin-apps@cygwin.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).