This is the mail archive of the cygwin-apps mailing list for the Cygwin project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: [PATCH 2/4 setup] package re-/de-installation from CLI


>From baab3c913d87a06b62dd14c442a15dc8c2aa9361 Mon Sep 17 00:00:00 2001
From: Achim Gratz <Stromeko@Stromeko.DE>
Date: Wed, 24 Jul 2013 22:00:36 +0200
Subject: [PATCH 2/4] Allow deletion of packages and categories from CLI,
 re-implement install from CLI

	* choose.h (hasManualSelections): Declare new variable.
	* choose.cc (OnInit): Re-implement package handling depending on
	  options given on CLI using package actions instead of
	  package_meta low-level functions.  When no CLI package or
	  category options have been given, upgrade installed packages.
	  Do not check for updates when packages are to be added or
	  removed from the CLI, but this behaviour can be requested with
	  --upgrade-also.  A package that is requested to be removed and
	  also added at the same time gets re-installed or upgraded (when
	  version curr != installed).  Uninstalled packages in categories
	  "Base" or "Misc" are always selected for installation; installed
	  packages in these categories are not eligible for deletion and
	  will be reinstalled or upgraded instead.
	* package_meta.h (ismanuallyDeleted): Declare new method.
	* package_meta.cc (DeletePackageOption): Add new CLI option
	  -x/--remove-packages, packages listed here are considered
	  candidates for deletion.
	  (DeleteCategoryOption): Add new CLI option
	  -c/--remove-categories, packages belonging to categories listed
	  here are considered candidates for deletion.
	  (hasManualSelections): Additional boolean to record if any
	  manual installations or deletions have been requested.
	  (packagemeta::isManuallyDeleted): Implement along the same lines
	  as isManuallyWanted, but for deletion candidates.
---
 choose.cc       | 43 ++++++++++++++++++++-----------------------
 choose.h        |  1 +
 package_meta.cc | 55 +++++++++++++++++++++++++++++++++++++++++++++++++++++++
 package_meta.h  |  2 ++
 4 files changed, 78 insertions(+), 23 deletions(-)

diff --git a/choose.cc b/choose.cc
index 4e0bcd4..fd75790 100644
--- a/choose.cc
+++ b/choose.cc
@@ -239,31 +239,28 @@ ChooserPage::OnInit ()
   packagedb db;
   db.setExistence ();
   db.fillMissingCategory ();
-  bool bCommandLineAddedPackages = db.addCommandLinePackages();
 
-  // in unattended mode, if packages were selected on the command line using the --packages
-  // or --categories options, just install those selected packages and don't upgrade all others
-  // (we always install all packages in the Base or Misc categories; packages selected on the
-  // command line are added to the Base category)
-  if ((unattended_mode == unattended) && bCommandLineAddedPackages)
-    {
-      for (packagedb::packagecollection::iterator i = db.packages.begin ();
-           i != db.packages.end (); ++i)
-        {
-          packagemeta & pkg = *(i->second);
-          if (pkg.installed)
-	    pkg.desired = pkg.installed;
-          else if (pkg.categories.find ("Base") != pkg.categories.end ()
-                   || pkg.categories.find ("Misc") != pkg.categories.end ())
-            {
-              pkg.desired = pkg.trustp(TRUST_CURR);
-              pkg.desired.pick(TRUE, &pkg);
-            }
-        }
-    }
-  else
+  for (packagedb::packagecollection::iterator i = db.packages.begin ();
+       i != db.packages.end (); ++i)
     {
-      db.defaultTrust (TRUST_CURR);
+      packagemeta & pkg = *(i->second);
+      bool wanted    = pkg.isManuallyWanted();
+      bool deleted   = pkg.isManuallyDeleted();
+      bool basemisc  = (pkg.categories.find ("Base") != pkg.categories.end ()
+		     || pkg.categories.find ("Misc") != pkg.categories.end ());
+      bool current   = pkg.curr;
+      bool upgrade   =  wanted  || (!pkg.installed && basemisc) || !hasManualSelections;
+      bool install   =   wanted  && !deleted && !pkg.installed;
+      bool reinstall =  (wanted  || basemisc ) && deleted;
+      bool uninstall = !(wanted  || basemisc ) && deleted;
+      if (install)
+	pkg.set_action( packagemeta::Install_action, pkg.curr );
+      else if (reinstall)
+	pkg.set_action( packagemeta::Reinstall_action, pkg.curr );
+      else if (uninstall)
+	pkg.set_action( packagemeta::Uninstall_action, packageversion() );
+      else
+	pkg.set_action( packagemeta::Default_action, ((upgrade && current) ? pkg.curr : pkg.installed) );
     }
 
   ClearBusy ();
diff --git a/choose.h b/choose.h
index b24aefc..9dc5882 100644
--- a/choose.h
+++ b/choose.h
@@ -21,6 +21,7 @@
 #include "package_meta.h"
 #include "PickView.h"
 
+extern bool hasManualSelections;
 
 class ChooserPage:public PropertyPage
 {
diff --git a/package_meta.cc b/package_meta.cc
index ee4cb45..ed7a9bf 100644
--- a/package_meta.cc
+++ b/package_meta.cc
@@ -51,8 +51,11 @@ using namespace std;
 
 using namespace std;
 
+static StringArrayOption DeletePackageOption ('x', "remove-packages", "Specify packages to uninstall");
+static StringArrayOption DeleteCategoryOption ('c', "remove-categories", "Specify categories to uninstall");
 static StringArrayOption PackageOption ('P', "packages", "Specify packages to install");
 static StringArrayOption CategoryOption ('C', "categories", "Specify entire categories to install");
+bool hasManualSelections = 0;
 
 /*****************/
 
@@ -275,7 +278,9 @@ bool packagemeta::isManuallyWanted() const
 {
   static bool parsed_yet = false;
   static std::set<string> parsed_names;
+  hasManualSelections |= parsed_names.size ();
   static std::set<string> parsed_categories;
+  hasManualSelections |= parsed_categories.size ();
   bool bReturn = false;
 
   /* First time through, we parse all the names out from the 
@@ -319,6 +324,56 @@ bool packagemeta::isManuallyWanted() const
   return bReturn;
 }
 
+bool packagemeta::isManuallyDeleted() const
+{
+  static bool parsed_yet = false;
+  static std::set<string> parsed_delete;
+  hasManualSelections |= parsed_delete.size ();
+  static std::set<string> parsed_delete_categories;
+  hasManualSelections |= parsed_delete_categories.size ();
+  bool bReturn = false;
+
+  /* First time through, we parse all the names out from the
+    option string and store them away in an STL set.  */
+  if (!parsed_yet)
+  {
+    vector<string> delete_options   = DeletePackageOption;
+    vector<string> categories_options = DeleteCategoryOption;
+    for (vector<string>::iterator n = delete_options.begin ();
+		n != delete_options.end (); ++n)
+      {
+	parseNames (parsed_delete, *n);
+      }
+    for (vector<string>::iterator n = categories_options.begin ();
+		n != categories_options.end (); ++n)
+      {
+	parseNames (parsed_delete_categories, *n);
+      }
+    parsed_yet = true;
+  }
+
+  /* Once we've already parsed the option string, just do
+    a lookup in the cache of already-parsed names.  */
+  bReturn = parsed_delete.find(name) != parsed_delete.end();
+
+  /* If we didn't select the package manually, did we select any
+     of the categories it is in? */
+  if (!bReturn && parsed_delete_categories.size ())
+    {
+      std::set<std::string, casecompare_lt_op>::iterator curcat;
+      for (curcat = categories.begin (); curcat != categories.end (); curcat++)
+	if (parsed_delete_categories.find (*curcat) != parsed_delete_categories.end ())
+	  {
+	    log (LOG_PLAIN) << "Found category " << *curcat << " in package " << name << endLog;
+	    bReturn = true;
+	  }
+    }
+
+  if (bReturn)
+    log (LOG_PLAIN) << "Deleted manual package " << name << endLog;
+  return bReturn;
+}
+
 const std::string
 packagemeta::SDesc () const
 {
diff --git a/package_meta.h b/package_meta.h
index 64a77d9..2da4a65 100644
--- a/package_meta.h
+++ b/package_meta.h
@@ -106,6 +106,8 @@ public:
   std::string installed_from;
   /* true if package was selected on command-line. */
   bool isManuallyWanted() const;
+  /* true if package was deleted on command-line. */
+  bool isManuallyDeleted() const;
   /* SDesc is global in theory, across all package versions. 
      LDesc is not: it can be different per version */
   const std::string SDesc () const;
-- 
1.8.3.1

Achim.
-- 
+<[Q+ Matrix-12 WAVE#46+305 Neuron microQkb Andromeda XTk Blofeld]>+

Factory and User Sound Singles for Waldorf rackAttack:
http://Synth.Stromeko.net/Downloads.html#WaldorfSounds

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]