diff options
author | Daniel Hartwig <mandyke@gmail.com> | 2012-06-08 17:11:48 +0800 |
---|---|---|
committer | Daniel Hartwig <mandyke@gmail.com> | 2012-06-08 17:11:48 +0800 |
commit | 24e4c8dab029ac59437f9392a8d3732c6893a3e3 (patch) | |
tree | 65da6aa7aef3c16ac40b3c5a4536a025172d8272 /src/cmdline/cmdline_extract_cache_subset.cc | |
parent | 85d6f30683f6ede36e7a6a0e78e6e7efa079e056 (diff) | |
download | aptitude-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_extract_cache_subset.cc')
-rw-r--r-- | src/cmdline/cmdline_extract_cache_subset.cc | 56 |
1 files changed, 6 insertions, 50 deletions
diff --git a/src/cmdline/cmdline_extract_cache_subset.cc b/src/cmdline/cmdline_extract_cache_subset.cc index a5cc2086..e4620534 100644 --- a/src/cmdline/cmdline_extract_cache_subset.cc +++ b/src/cmdline/cmdline_extract_cache_subset.cc @@ -72,7 +72,7 @@ namespace aptitude } bool ok = true; - std::set<pkgCache::PkgIterator> packages; + pkgset packages; if(argc == 2) { for(pkgCache::PkgIterator pIt = (*apt_cache_file)->PkgBegin(); @@ -82,58 +82,14 @@ namespace aptitude else { for(int i = 2; i < argc; ++i) - { - std::string arg(argv[i]); - - if(!aptitude::matching::is_pattern(arg)) - { - pkgCache::PkgIterator pIt = (*apt_cache_file)->FindPkg(arg); - if(pIt.end()) - { - std::cerr << ssprintf(_("No such package \"%s\""), arg.c_str()) - << std::endl; - ok = false; - } - else - packages.insert(pIt); - } - else - { - using namespace aptitude::matching; - using cwidget::util::ref_ptr; - - ref_ptr<pattern> p = parse(arg); - - if(p.valid()) - { - _error->DumpErrors(); - } - else - { - pkg_results_list matches; - 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) - packages.insert(it->first); - } - } - } + ok &= pkgset_from_string(&packages, argv[i]); } if(!ok) - return 2; - - if(packages.size() == 0) - { - printf(_("No packages were selected by the given search pattern; nothing to do.\n")); - return 0; - } + { + _error->DumpErrors(); + return 2; + } aptitude::apt::make_truncated_state_copy(out_dir, packages); |