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>
11 #include <apt-private/private-cacheset.h>
17 bool GetLocalitySortedVersionSet(pkgCacheFile
&CacheFile
,
18 APT::VersionContainerInterface
* const vci
,
19 OpProgress
* const progress
)
21 Matcher null_matcher
= Matcher();
22 return GetLocalitySortedVersionSet(CacheFile
, vci
,
23 null_matcher
, progress
);
26 bool GetLocalitySortedVersionSet(pkgCacheFile
&CacheFile
,
27 APT::VersionContainerInterface
* const vci
,
29 OpProgress
* const progress
)
31 pkgCache
*Cache
= CacheFile
.GetPkgCache();
32 pkgDepCache
*DepCache
= CacheFile
.GetDepCache();
33 APT::CacheSetHelper
helper(false);
37 progress
->SubProgress(Cache
->Head().PackageCount
, _("Sorting"));
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);
43 for (pkgCache::PkgIterator P
= Cache
->PkgBegin(); P
.end() == false; ++P
)
48 progress
->Progress(Done
);
52 // exclude virtual pkgs
53 if (P
->VersionList
== 0)
56 if ((matcher
)(P
) == false)
59 pkgDepCache::StateCache
&state
= (*DepCache
)[P
];
60 if (insertCurrentVer
== true)
62 if (P
->CurrentVer
!= 0)
63 vci
->FromPackage(vci
, CacheFile
, P
, APT::CacheSetHelper::INSTALLED
, helper
);
65 else if (insertUpgradable
== true)
67 if(P
.CurrentVer() && state
.Upgradable())
68 vci
->FromPackage(vci
, CacheFile
, P
, APT::CacheSetHelper::CANDIDATE
, helper
);
70 else if (insertManualInstalled
== true)
73 ((*DepCache
)[P
].Flags
& pkgCache::Flag::Auto
) == false)
74 vci
->FromPackage(vci
, CacheFile
, P
, APT::CacheSetHelper::CANDIDATE
, helper
);
78 if (vci
->FromPackage(vci
, CacheFile
, P
, APT::CacheSetHelper::CANDIDATE
, helper
) == false)
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());