]> git.saurik.com Git - apt.git/blob - apt-private/private-cacheset.cc
fix screen width detection for apt/apt-get lists
[apt.git] / apt-private / private-cacheset.cc
1 #include <config.h>
2
3 #include <apt-pkg/cachefile.h>
4 #include <apt-pkg/pkgcache.h>
5 #include <apt-pkg/depcache.h>
6 #include <apt-pkg/cacheiterators.h>
7 #include <apt-pkg/configuration.h>
8 #include <apt-pkg/progress.h>
9 #include <apt-pkg/policy.h>
10
11 #include <apt-private/private-cacheset.h>
12
13 #include <stddef.h>
14
15 #include <apti18n.h>
16
17 bool GetLocalitySortedVersionSet(pkgCacheFile &CacheFile,
18 LocalitySortedVersionSet &output_set,
19 OpProgress &progress)
20 {
21 Matcher null_matcher = Matcher();
22 return GetLocalitySortedVersionSet(CacheFile, output_set,
23 null_matcher, progress);
24 }
25
26 bool GetLocalitySortedVersionSet(pkgCacheFile &CacheFile,
27 LocalitySortedVersionSet &output_set,
28 Matcher &matcher,
29 OpProgress &progress)
30 {
31 pkgCache *Cache = CacheFile.GetPkgCache();
32 pkgDepCache *DepCache = CacheFile.GetDepCache();
33
34 int Done=0;
35 progress.SubProgress(Cache->Head().PackageCount, _("Sorting"));
36 for (pkgCache::PkgIterator P = Cache->PkgBegin(); P.end() == false; ++P)
37 {
38 if (Done%500 == 0)
39 progress.Progress(Done);
40 Done++;
41
42 if ((matcher)(P) == false)
43 continue;
44
45 // exclude virtual pkgs
46 if (P.VersionList() == 0)
47 continue;
48 pkgDepCache::StateCache &state = (*DepCache)[P];
49 if (_config->FindB("APT::Cmd::Installed") == true)
50 {
51 if (P.CurrentVer() != NULL)
52 {
53 output_set.insert(P.CurrentVer());
54 }
55 }
56 else if (_config->FindB("APT::Cmd::Upgradable") == true)
57 {
58 if(P.CurrentVer() && state.Upgradable())
59 {
60 pkgPolicy *policy = CacheFile.GetPolicy();
61 output_set.insert(policy->GetCandidateVer(P));
62 }
63 }
64 else if (_config->FindB("APT::Cmd::Manual-Installed") == true)
65 {
66 if (P.CurrentVer() &&
67 ((*DepCache)[P].Flags & pkgCache::Flag::Auto) == false)
68 {
69 pkgPolicy *policy = CacheFile.GetPolicy();
70 output_set.insert(policy->GetCandidateVer(P));
71 }
72 }
73 else
74 {
75 pkgPolicy *policy = CacheFile.GetPolicy();
76 if (policy->GetCandidateVer(P).IsGood())
77 output_set.insert(policy->GetCandidateVer(P));
78 else
79 // no candidate, this may happen for packages in
80 // dpkg "deinstall ok config-file" state - we pick the first ver
81 // (which should be the only one)
82 output_set.insert(P.VersionList());
83 }
84 }
85 progress.Done();
86 return true;
87 }