]> cygwin.com Git - cygwin-apps/setup.git/commitdiff
* choose.h (hasManualSelections): Declare new variable.
authorCorinna Vinschen <corinna@vinschen.de>
Thu, 25 Jul 2013 12:03:49 +0000 (12:03 +0000)
committerCorinna Vinschen <corinna@vinschen.de>
Thu, 25 Jul 2013 12:03:49 +0000 (12:03 +0000)
* choose.cc (ChooserPage::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 reinstalled
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 (packagemeta::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.

ChangeLog
choose.cc
choose.h
package_meta.cc
package_meta.h

index 7559c965741527cd000892c14f574f46709950bc..88273fbfd0135e3cbd4174f823c4c2f51d755182 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,29 @@
+2013-07-25  Achim Gratz <Stromeko@Stromeko.DE>
+
+       * choose.h (hasManualSelections): Declare new variable.
+       * choose.cc (ChooserPage::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 reinstalled
+       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 (packagemeta::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.
+
 2013-07-25  Achim Gratz <Stromeko@Stromeko.DE>
 
        * choose.cc (ChooserPage::createListview): Remove superflous and
index df44a6f2cb669f60238e1202d60f8a4c80400d60..8e5382a94caef57afaa429f3ddd86ad01ec1df85 100644 (file)
--- 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 ();
index b24aefc0845962f6370c6dd9078f632d41b6bb7b..9dc5882a53f8d30ce0ec76e71ae8f1a475ecf298 100644 (file)
--- a/choose.h
+++ b/choose.h
@@ -21,6 +21,7 @@
 #include "package_meta.h"
 #include "PickView.h"
 
+extern bool hasManualSelections;
 
 class ChooserPage:public PropertyPage
 {
index 33e19f164db8e779519d3e2655c00ddd5a1158a2..03942b30b8ae2b99e8285142f58da1de1f6e2a15 100644 (file)
@@ -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
 {
index 64a77d96a3e3a6356005be01e3d854efbae69003..2da4a65024844dce788cc2f5142f0c33fbcdfa48 100644 (file)
@@ -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;
This page took 0.04339 seconds and 5 git commands to generate.