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]

[PATCH 2/2] When packages are selected on the command line in unattended mode, just install those packages


When packages are selected on the command line in unattended mode,
just install those packages.
(Except that packages in the 'Base' and 'Misc' categories are always installed.)

When no packages are selected on the command line in unattended mode, upgrade
all installed packages to the current version.

This whole mechanism of putting the command line specified packages into the 'Base'
category so they get installed, rather than just setting them to be installed seems
less than ideal.

Also, reading the code, there's probably bug: if we install from scratch
and then choose 'Keep', nothing gets installed, whereas 'Base' and 'Misc'
"should" get installed?

Also, a command line option like '--packages <nonexistent-misspelt-package>' is silently
ignored at the moment.  This is doubly bad now, as we will upgrade everything else to
the current version while the user curses us for not installing <correctly-spelt-package> :-)

Also, since initializing the default list of packages to install is no longer a
side effect of building the GUI elements for the package picker window, we can
probably now bypass the package picker window entirely in unattended mode...

Signed-off-by: Jon TURNEY <jon.turney@dronecode.org.uk>

2011-07-21  Jon TURNEY  <jon.turney@dronecode.org.uk>

	* choose.cc (OnInit, createListview): Build the initial list of packages
	to install in OnInit() not in CreateListView().  If packages were selected
	on command line in unattended mode, just install those packages.
	* package_db.h (packagedb):Add addCommandLinePackages() method
	* package_db.cc (addCommandLinePackages): Add separate method to add these
	so we can indicate if packages were added on the command line
---
 choose.cc     |   30 ++++++++++++++++++++++++++++--
 package_db.cc |   16 +++++++++++++++-
 package_db.h  |    1 +
 3 files changed, 44 insertions(+), 3 deletions(-)

diff --git a/choose.cc b/choose.cc
index 8f038d8..054ad7b 100644
--- a/choose.cc
+++ b/choose.cc
@@ -143,8 +143,6 @@ ChooserPage::createListview ()
     exit (11);
   chooser->init(PickView::views::Category);
   chooser->Show(SW_SHOW);
-
-  chooser->defaultTrust (TRUST_CURR);
   chooser->setViewMode (PickView::views::Category);
   if (!SetDlgItemText (GetHWND (), IDC_CHOOSE_VIEWCAPTION, chooser->mode_caption ()))
     log (LOG_BABBLE) << "Failed to set View button caption %ld" <<
@@ -246,6 +244,34 @@ 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);
+            }
+        }
+    }
+  else
+    {
+      db.defaultTrust (TRUST_CURR);
+    }
+
   ClearBusy ();
 
   if (source == IDC_SOURCE_DOWNLOAD)
diff --git a/package_db.cc b/package_db.cc
index 8c8644f..b60d095 100644
--- a/package_db.cc
+++ b/package_db.cc
@@ -419,10 +419,24 @@ packagedb::fillMissingCategory ()
         i->second->setDefaultCategories();
 
       i->second->addToCategoryAll();
+    }
+}
 
+bool
+packagedb::addCommandLinePackages ()
+{
+  bool bReturn = false;
+
+  for (packagedb::packagecollection::iterator i = packages.begin(); i != packages.end(); i++)
+    {
       if (i->second->isManuallyWanted())
-        i->second->addToCategoryBase();
+        {
+          i->second->addToCategoryBase();
+          bReturn = true;
+        }
     }
+
+  return bReturn;
 }
 
 void
diff --git a/package_db.h b/package_db.h
index bc828a1..63753aa 100644
--- a/package_db.h
+++ b/package_db.h
@@ -70,6 +70,7 @@ public:
   PackageDBConnectedIterator connectedBegin();
   PackageDBConnectedIterator connectedEnd();
   void fillMissingCategory();
+  bool addCommandLinePackages();
   void defaultTrust (trusts trust);
   void markUnVisited();
   void setExistence();
-- 
1.7.5.1


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