+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
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 ();
#include "package_meta.h"
#include "PickView.h"
+extern bool hasManualSelections;
class ChooserPage:public PropertyPage
{
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;
/*****************/
{
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
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
{
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;