]>
Commit | Line | Data |
---|---|---|
453b82a3 DK |
1 | #include <config.h> |
2 | ||
b9179170 MV |
3 | #include <apt-pkg/cachefile.h> |
4 | #include <apt-pkg/pkgcache.h> | |
5 | #include <apt-pkg/depcache.h> | |
453b82a3 DK |
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> | |
b9179170 | 14 | |
453b82a3 | 15 | #include <apti18n.h> |
b9179170 MV |
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 | { | |
d059cc26 MV |
58 | pkgPolicy *policy = CacheFile.GetPolicy(); |
59 | if(P.CurrentVer() && | |
60 | state.Upgradable() && | |
61 | policy->GetCandidateVer(P) != P.CurrentVer()) | |
b9179170 MV |
62 | { |
63 | pkgPolicy *policy = CacheFile.GetPolicy(); | |
64 | output_set.insert(policy->GetCandidateVer(P)); | |
65 | } | |
66 | } | |
3bdf7da5 MV |
67 | else if (_config->FindB("APT::Cmd::Manual-Installed") == true) |
68 | { | |
69 | if (P.CurrentVer() && | |
70 | ((*DepCache)[P].Flags & pkgCache::Flag::Auto) == false) | |
71 | { | |
72 | pkgPolicy *policy = CacheFile.GetPolicy(); | |
73 | output_set.insert(policy->GetCandidateVer(P)); | |
74 | } | |
75 | } | |
b9179170 MV |
76 | else |
77 | { | |
78 | pkgPolicy *policy = CacheFile.GetPolicy(); | |
c8259fcd MV |
79 | if (policy->GetCandidateVer(P).IsGood()) |
80 | output_set.insert(policy->GetCandidateVer(P)); | |
81 | else | |
82 | // no candidate, this may happen for packages in | |
83 | // dpkg "deinstall ok config-file" state - we pick the first ver | |
84 | // (which should be the only one) | |
85 | output_set.insert(P.VersionList()); | |
b9179170 MV |
86 | } |
87 | } | |
88 | progress.Done(); | |
89 | return true; | |
90 | } |