]> git.saurik.com Git - apt.git/blob - apt-private/private-cacheset.cc
Merge branch 'debian/experimental' into feature/srv-records
[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 APT::VersionContainerInterface * const vci,
19 OpProgress * const progress)
20 {
21 Matcher null_matcher = Matcher();
22 return GetLocalitySortedVersionSet(CacheFile, vci,
23 null_matcher, progress);
24 }
25
26 bool GetLocalitySortedVersionSet(pkgCacheFile &CacheFile,
27 APT::VersionContainerInterface * const vci,
28 Matcher &matcher,
29 OpProgress * const progress)
30 {
31 pkgCache *Cache = CacheFile.GetPkgCache();
32 pkgDepCache *DepCache = CacheFile.GetDepCache();
33 APT::CacheSetHelper helper(false);
34
35 int Done=0;
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
43 for (pkgCache::PkgIterator P = Cache->PkgBegin(); P.end() == false; ++P)
44 {
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;
55
56 if ((matcher)(P) == false)
57 continue;
58
59 pkgDepCache::StateCache &state = (*DepCache)[P];
60 if (insertCurrentVer == true)
61 {
62 if (P->CurrentVer != 0)
63 vci->FromPackage(vci, CacheFile, P, APT::CacheSetHelper::INSTALLED, helper);
64 }
65 else if (insertUpgradable == true)
66 {
67 if(P.CurrentVer() && state.Upgradable())
68 vci->FromPackage(vci, CacheFile, P, APT::CacheSetHelper::CANDIDATE, helper);
69 }
70 else if (insertManualInstalled == true)
71 {
72 if (P.CurrentVer() &&
73 ((*DepCache)[P].Flags & pkgCache::Flag::Auto) == false)
74 vci->FromPackage(vci, CacheFile, P, APT::CacheSetHelper::CANDIDATE, helper);
75 }
76 else
77 {
78 if (vci->FromPackage(vci, CacheFile, P, APT::CacheSetHelper::CANDIDATE, helper) == false)
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 }
85 }
86 }
87 if (progress != NULL)
88 progress->Done();
89 return true;
90 }