]>
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 | 16 | |
25594bb5 DK |
17 | bool GetLocalitySortedVersionSet(pkgCacheFile &CacheFile, |
18 | APT::VersionContainerInterface * const vci, | |
19 | OpProgress * const progress) | |
b9179170 MV |
20 | { |
21 | Matcher null_matcher = Matcher(); | |
25594bb5 | 22 | return GetLocalitySortedVersionSet(CacheFile, vci, |
b9179170 MV |
23 | null_matcher, progress); |
24 | } | |
25 | ||
25594bb5 DK |
26 | bool GetLocalitySortedVersionSet(pkgCacheFile &CacheFile, |
27 | APT::VersionContainerInterface * const vci, | |
b9179170 | 28 | Matcher &matcher, |
25594bb5 | 29 | OpProgress * const progress) |
b9179170 MV |
30 | { |
31 | pkgCache *Cache = CacheFile.GetPkgCache(); | |
32 | pkgDepCache *DepCache = CacheFile.GetDepCache(); | |
25594bb5 | 33 | APT::CacheSetHelper helper(false); |
b9179170 MV |
34 | |
35 | int Done=0; | |
25594bb5 DK |
36 | if (progress != NULL) |
37 | progress->SubProgress(Cache->Head().PackageCount, _("Sorting")); | |
38 | ||
39 | bool const insertCurrentVer = _config->FindB("APT::Cmd::Installed", false); | |
40 | bool const insertUpgradable = _config->FindB("APT::Cmd::Upgradable", false); | |
41 | bool const insertManualInstalled = _config->FindB("APT::Cmd::Manual-Installed", false); | |
42 | ||
b9179170 MV |
43 | for (pkgCache::PkgIterator P = Cache->PkgBegin(); P.end() == false; ++P) |
44 | { | |
25594bb5 DK |
45 | if (progress != NULL) |
46 | { | |
47 | if (Done % 500 == 0) | |
48 | progress->Progress(Done); | |
49 | ++Done; | |
50 | } | |
51 | ||
52 | // exclude virtual pkgs | |
53 | if (P->VersionList == 0) | |
54 | continue; | |
b9179170 MV |
55 | |
56 | if ((matcher)(P) == false) | |
25594bb5 | 57 | continue; |
b9179170 | 58 | |
b9179170 | 59 | pkgDepCache::StateCache &state = (*DepCache)[P]; |
25594bb5 | 60 | if (insertCurrentVer == true) |
b9179170 | 61 | { |
25594bb5 | 62 | if (P->CurrentVer != 0) |
fdba4d53 | 63 | vci->FromPackage(vci, CacheFile, P, APT::CacheSetHelper::INSTALLED, helper); |
b9179170 | 64 | } |
25594bb5 | 65 | else if (insertUpgradable == true) |
b9179170 | 66 | { |
25594bb5 | 67 | if(P.CurrentVer() && state.Upgradable()) |
fdba4d53 | 68 | vci->FromPackage(vci, CacheFile, P, APT::CacheSetHelper::CANDIDATE, helper); |
b9179170 | 69 | } |
25594bb5 | 70 | else if (insertManualInstalled == true) |
3bdf7da5 | 71 | { |
25594bb5 DK |
72 | if (P.CurrentVer() && |
73 | ((*DepCache)[P].Flags & pkgCache::Flag::Auto) == false) | |
fdba4d53 | 74 | vci->FromPackage(vci, CacheFile, P, APT::CacheSetHelper::CANDIDATE, helper); |
3bdf7da5 | 75 | } |
25594bb5 | 76 | else |
b9179170 | 77 | { |
fdba4d53 | 78 | if (vci->FromPackage(vci, CacheFile, P, APT::CacheSetHelper::CANDIDATE, helper) == false) |
25594bb5 DK |
79 | { |
80 | // no candidate, this may happen for packages in | |
81 | // dpkg "deinstall ok config-file" state - we pick the first ver | |
82 | // (which should be the only one) | |
83 | vci->insert(P.VersionList()); | |
84 | } | |
b9179170 MV |
85 | } |
86 | } | |
25594bb5 DK |
87 | if (progress != NULL) |
88 | progress->Done(); | |
b9179170 MV |
89 | return true; |
90 | } |