File: testkeep.cc

package info (click to toggle)
apt 3.1.13
  • links: PTS, VCS
  • area: main
  • in suites: forky
  • size: 22,764 kB
  • sloc: cpp: 71,085; sh: 31,750; xml: 5,553; perl: 217; python: 197; ansic: 191; makefile: 41
file content (57 lines) | stat: -rw-r--r-- 1,380 bytes parent folder | download | duplicates (3)
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
#include <config.h>

#include <apt-pkg/init.h>
#include <apt-pkg/algorithms.h>
#include <apt-pkg/cachefile.h>
#include <apt-pkg/error.h>
#include <apt-pkg/pkgsystem.h>
#include <apt-pkg/prettyprinters.h>

#include <iostream>
#include <string>

static bool test(const char *name, bool hold)
{
   pkgCacheFile cache;
   if (not cache.Open())
      return false;

   for (auto Pkg = cache->PkgBegin(); Pkg.end() == false; ++Pkg)
      std::cout << "A: " << APT::PrettyPkg(cache, Pkg) << std::endl;

   cache->MarkDelete(cache->FindPkg(name));
   if (hold)
      cache->MarkProtected(cache->FindPkg(name));

   for (auto Pkg = cache->PkgBegin(); Pkg.end() == false; ++Pkg)
      std::cout << "B: " << APT::PrettyPkg(cache, Pkg) << std::endl;

   pkgProblemResolver resolve(cache);
   bool res = resolve.ResolveByKeep();

   for (auto Pkg = cache->PkgBegin(); Pkg.end() == false; ++Pkg)
      std::cout << "C: " << APT::PrettyPkg(cache, Pkg) << std::endl;

   return res;
}

int main(int argc, const char *argv[])
{
   if (argc != 2 && argc != 3)
   {
      return _error->Error("Expected one argument");
      goto err;
   }
   if (not pkgInitConfig(*_config))
      goto err;
   if (not pkgInitSystem(*_config, _system))
      goto err;
   if (not test(argv[1], argc > 2 && strcmp(argv[2], "--hold") == 0))
      goto err;

   return 0;
err:
   _error->DumpErrors();
   return 1;
}