summaryrefslogtreecommitdiff
path: root/src/cmdline/cmdline_action.cc
diff options
context:
space:
mode:
authorDaniel Hartwig <mandyke@gmail.com>2012-06-08 17:11:48 +0800
committerDaniel Hartwig <mandyke@gmail.com>2012-06-08 17:11:48 +0800
commit24e4c8dab029ac59437f9392a8d3732c6893a3e3 (patch)
tree65da6aa7aef3c16ac40b3c5a4536a025172d8272 /src/cmdline/cmdline_action.cc
parent85d6f30683f6ede36e7a6a0e78e6e7efa079e056 (diff)
downloadaptitude-24e4c8dab029ac59437f9392a8d3732c6893a3e3.tar.gz
Add pkgset helpers
Ported some code from apt cacheset.cc to populate a pkgset. The function pkgset_from_string will fill a given pkgset with either the exactly named package, or the packages matched by a string predicated by is_pattern. In the future, we should look to directly use the apt cacheset infrastructure. This is currently blocked by our custom implementation of pkgCacheFile (see aptcache.h). Errors that occur in looking up the package (such as no package with that name, or an invalid search pattern) are pushed to the global error list with a customizable error_type (default: ERROR).
Diffstat (limited to 'src/cmdline/cmdline_action.cc')
-rw-r--r--src/cmdline/cmdline_action.cc188
1 files changed, 84 insertions, 104 deletions
diff --git a/src/cmdline/cmdline_action.cc b/src/cmdline/cmdline_action.cc
index 574a0efe..8fa2eb62 100644
--- a/src/cmdline/cmdline_action.cc
+++ b/src/cmdline/cmdline_action.cc
@@ -520,114 +520,94 @@ bool cmdline_applyaction(string s,
return false;
}
- if(!aptitude::matching::is_pattern(package))
+ pkgset pkgset;
+ if(aptitude::cmdline::pkgset_from_string(&pkgset, package) == false)
{
- pkgCache::PkgIterator pkg=(*apt_cache_file)->FindPkg(package.c_str());
- if(pkg.end())
- {
- // Assume the user asked for a source package.
- if(action == cmdline_build_depends)
- return cmdline_do_build_depends(package,
- seen_virtual_packages,
- source,
- sourcestr,
- arch_only,
- policy,
- to_install, to_hold,
- to_remove, to_purge,
- verbose,
- allow_auto,
- term_metrics);
-
- // Maybe they misspelled the package name?
- pkgvector possible;
-
- for(pkgCache::PkgIterator j=(*apt_cache_file)->PkgBegin();
- !j.end(); ++j)
- {
- if(!(j.VersionList().end() && j.ProvidesList().end()) &&
- strstr(j.Name(), package.c_str()) != NULL)
- possible.push_back(j);
- }
-
- if(!possible.empty())
- {
- // Don't overwhelm the user.
- if(possible.size()>40)
- printf(_("Couldn't find package \"%s\", and more than 40\npackages contain \"%s\" in their name.\n"), package.c_str(), package.c_str());
- else
- {
- printf(_("Couldn't find package \"%s\". However, the following\npackages contain \"%s\" in their name:\n"), package.c_str(), package.c_str());
- cmdline_show_pkglist(possible, term_metrics);
- }
- }
- else
- {
- for(pkgCache::PkgIterator j=(*apt_cache_file)->PkgBegin();
- !j.end(); ++j)
- {
- for(pkgCache::VerIterator v = j.VersionList();
- !v.end(); ++v)
- {
- std::wstring desc = get_long_description(v, apt_package_records);
- if(desc.find(cw::util::transcode(package)) != desc.npos)
- {
- possible.push_back(j);
- break;
- }
- }
- }
-
- if(possible.empty())
- printf(_("Couldn't find any package whose name or description matched \"%s\"\n"), package.c_str());
- else if(possible.size()>40)
- printf(_("Couldn't find any package matching \"%s\", and more than 40\npackages contain \"%s\" in their description.\n"), package.c_str(), package.c_str());
- else
- {
- printf(_("Couldn't find any package matching \"%s\". However, the following\npackages contain \"%s\" in their description:\n"), package.c_str(), package.c_str());
- cmdline_show_pkglist(possible, term_metrics);
- }
- }
-
- return false;
- }
+ // Assume the user asked for a source package.
+ if(action == cmdline_build_depends)
+ return cmdline_do_build_depends(package,
+ seen_virtual_packages,
+ source,
+ sourcestr,
+ arch_only,
+ policy,
+ to_install, to_hold,
+ to_remove, to_purge,
+ verbose,
+ allow_auto,
+ term_metrics);
+
+ // Maybe they misspelled the package name?
+ pkgvector possible;
+
+ for(pkgCache::PkgIterator j=(*apt_cache_file)->PkgBegin();
+ !j.end(); ++j)
+ {
+ if(!(j.VersionList().end() && j.ProvidesList().end()) &&
+ strstr(j.Name(), package.c_str()) != NULL)
+ possible.push_back(j);
+ }
+
+ if(!possible.empty())
+ {
+ // Don't overwhelm the user.
+ if(possible.size()>40)
+ printf(_("Couldn't find package \"%s\", and more than 40\n"
+ "packages contain \"%s\" in their name.\n"),
+ package.c_str(), package.c_str());
+ else
+ {
+ printf(_("Couldn't find package \"%s\". However, the following\n"
+ "packages contain \"%s\" in their name:\n"),
+ package.c_str(), package.c_str());
+ cmdline_show_pkglist(possible, term_metrics);
+ }
+ }
+ else
+ {
+ for(pkgCache::PkgIterator j=(*apt_cache_file)->PkgBegin();
+ !j.end(); ++j)
+ {
+ for(pkgCache::VerIterator v = j.VersionList();
+ !v.end(); ++v)
+ {
+ std::wstring desc = get_long_description(v, apt_package_records);
+ if(desc.find(cw::util::transcode(package)) != desc.npos)
+ {
+ possible.push_back(j);
+ break;
+ }
+ }
+ }
+
+ if(possible.empty())
+ printf(_("Couldn't find any package whose name or description matched \"%s\"\n"),
+ package.c_str());
+ else if(possible.size()>40)
+ printf(_("Couldn't find any package matching \"%s\", and more than 40\n"
+ "packages contain \"%s\" in their description.\n"),
+ package.c_str(), package.c_str());
+ else
+ {
+ printf(_("Couldn't find any package matching \"%s\". However, the following\n"
+ "packages contain \"%s\" in their description:\n"),
+ package.c_str(), package.c_str());
+ cmdline_show_pkglist(possible, term_metrics);
+ }
+ }
- rval = cmdline_applyaction(action, pkg,
- seen_virtual_packages,
- to_install, to_hold, to_remove, to_purge,
- verbose, source,
- sourcestr, policy, arch_only, allow_auto,
- term_metrics);
+ return false;
}
- else
- {
- cw::util::ref_ptr<pattern> p(parse(package.c_str()));
- if(!p.valid())
- {
- _error->DumpErrors();
- return false;
- }
- pkg_results_list matches;
- cw::util::ref_ptr<search_cache> search_info(search_cache::create());
- search(p, search_info, matches,
- *apt_cache_file,
- *apt_package_records);
- for(pkg_results_list::const_iterator it = matches.begin();
- it != matches.end();
- ++it)
- {
- if(!cmdline_applyaction(action, it->first,
- seen_virtual_packages,
- to_install, to_hold, to_remove, to_purge,
- verbose, source,
- sourcestr,
- policy, arch_only,
- allow_auto,
- term_metrics))
- rval = false;
- }
- }
+ for(pkgset::const_iterator it = pkgset.begin();
+ it != pkgset.end();
+ ++it)
+ rval &= cmdline_applyaction(action, *it,
+ seen_virtual_packages,
+ to_install, to_hold, to_remove, to_purge,
+ verbose, source,
+ sourcestr, policy, arch_only, allow_auto,
+ term_metrics);
return rval;
}