summaryrefslogtreecommitdiff
path: root/apt-private/private-cacheset.cc
blob: 4a63c7e8178756d1fc433b98014850e6d0be31e5 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
#include <config.h>

#include <apt-pkg/cachefile.h>
#include <apt-pkg/pkgcache.h>
#include <apt-pkg/depcache.h>
#include <apt-pkg/cacheiterators.h>
#include <apt-pkg/configuration.h>
#include <apt-pkg/progress.h>
#include <apt-pkg/policy.h>

#include <apt-private/private-cacheset.h>

#include <stddef.h>

#include <apti18n.h>

bool GetLocalitySortedVersionSet(pkgCacheFile &CacheFile, 
                                 LocalitySortedVersionSet &output_set,
                                 OpProgress &progress)
{
    Matcher null_matcher = Matcher();
    return GetLocalitySortedVersionSet(CacheFile, output_set, 
                                       null_matcher, progress);
}

bool GetLocalitySortedVersionSet(pkgCacheFile &CacheFile, 
                                 LocalitySortedVersionSet &output_set,
                                 Matcher &matcher,
                                 OpProgress &progress)
{
   pkgCache *Cache = CacheFile.GetPkgCache();
   pkgDepCache *DepCache = CacheFile.GetDepCache();

   int Done=0;
   progress.SubProgress(Cache->Head().PackageCount, _("Sorting"));
   for (pkgCache::PkgIterator P = Cache->PkgBegin(); P.end() == false; ++P)
   {
      if (Done%500 == 0)
         progress.Progress(Done);
      Done++;

      if ((matcher)(P) == false)
         continue;

      // exclude virtual pkgs
      if (P.VersionList() == 0)
         continue;
      pkgDepCache::StateCache &state = (*DepCache)[P];
      if (_config->FindB("APT::Cmd::Installed") == true)
      {
         if (P.CurrentVer() != NULL)
         {
            output_set.insert(P.CurrentVer());
         }
      }
      else if (_config->FindB("APT::Cmd::Upgradable") == true)
      {
         if(P.CurrentVer() && state.Upgradable())
         {
             pkgPolicy *policy = CacheFile.GetPolicy();
             output_set.insert(policy->GetCandidateVer(P));
         }
      }
      else if (_config->FindB("APT::Cmd::Manual-Installed") == true)
      {
         if (P.CurrentVer() && 
             ((*DepCache)[P].Flags & pkgCache::Flag::Auto) == false)
         {
             pkgPolicy *policy = CacheFile.GetPolicy();
             output_set.insert(policy->GetCandidateVer(P));
         }
      }
      else 
      {
         pkgPolicy *policy = CacheFile.GetPolicy();
         output_set.insert(policy->GetCandidateVer(P));
      }
   }
   progress.Done();
   return true;
}