File: pkgchecks.cc

package info (click to toggle)
console-apt 0.7.7.2potato2
  • links: PTS
  • area: main
  • in suites: potato
  • size: 612 kB
  • ctags: 658
  • sloc: cpp: 6,883; sh: 152; makefile: 47
file content (132 lines) | stat: -rw-r--r-- 3,883 bytes parent folder | download
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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132

#include <std.h>

#include <func/apt.h>

#include <interface/dialogs.h>

// TryToInstall - Try to install or remove a single package
// ---------------------------------------------------------------------
bool TryToInstall(pkgCache::PkgIterator Pkg, pkgDepCache & Cache, pkgProblemResolver & Fix, bool Remove, bool BrokenFix, unsigned int &ExpectedInst, bool AllowFail = true)
{
	string s;

	/* This is a pure virtual package and there is a single available 
	   provides */
	if (Cache[Pkg].CandidateVer == 0 && Pkg->ProvidesList != 0 && Pkg.ProvidesList()->NextProvides == 0)
	{
		pkgCache::PkgIterator Tmp = Pkg.ProvidesList().OwnerPkg();
		ui_dialog(0, "\n Missed selection", "Note, selecting %s instead of %s \n", Tmp.Name(), Pkg.Name());
		Pkg = Tmp;
	}

	// Handle the no-upgrade case
	/*if (_config->FindB("APT::Get::no-upgrade", false) == true && Pkg->CurrentVer != 0)
	   {
	   if (AllowFail == true)
	   c1out << "Skipping " << Pkg.Name() << ", it is already installed and no-upgrade is set." << endl;
	   return true;
	   } */

	// Check if there is something at all to install
	pkgDepCache::StateCache & State = Cache[Pkg];
	if (Remove == true && Pkg->CurrentVer == 0)
	{
		if (AllowFail == false)
			return false;

		ui_dialog(0, "Not installed", "\n Package %s is not installed \n", Pkg.Name());

		return false;
	}

	if (State.CandidateVer == 0 && Remove == false)
	{
		if (AllowFail == false)
			return false;

		if (Pkg->ProvidesList != 0)
		{
			s = "\n Package " + string(Pkg.Name()) + " is a virtual package provided by: \n";

			pkgCache::PrvIterator I = Pkg.ProvidesList();
			for (; I.end() == false; I++)
			{
				pkgCache::PkgIterator Pkg = I.OwnerPkg();

				if (Cache[Pkg].CandidateVerIter(Cache) == I.OwnerVer())
				{
					if (Cache[Pkg].Install() == true && Cache[Pkg].NewInstall() == false)
						s += "  * " + string(Pkg.Name()) + " " + string(I.OwnerVer().VerStr()) + " [Installed]\n";
					else
						s += "  * " + string(Pkg.Name()) + " " + string(I.OwnerVer().VerStr()) + "\n";
				}
			}
			s += " You should explicitly select one to install.\n";
		}
		else
		{
			s = "\n Package $2#" + string(Pkg.Name()) + "$! has no available version, but exists in the database. \n"
				" This typically means that the package was mentioned in a dependency and \n"
				" never uploaded, has been obsoleted or is not available with the contents \n" " of sources.list";

			pkgCache::DepIterator Dep = Pkg.RevDependsList();

			string t;

			for (; Dep.end() == false; Dep++)
			{
				if (Dep->Type != pkgCache::Dep::Replaces)
					continue;
				t += " * " + string(Dep.ParentPkg().Name()) + "\n";
			}

			if (t.length() > 0)
				s += ", however the following package(s) replace it: \n\n" + t;
			else
				s += ".\n";
		}

		ui_dialog(0, (char *) (string(Pkg.Name()) + " has no version").c_str(), "%s", s.c_str());

		_error->Error("Package %s has no installation candidate", Pkg.Name());

		return false;
	}

	Fix.Clear(Pkg);
	Fix.Protect(Pkg);
	if (Remove == true)
	{
		Fix.Remove(Pkg);
		Cache.MarkDelete(Pkg, _config->FindB("APT::Console::Purge", false));
		ExpectedInst++;
		return true;
	}

	// Install it
	Cache.MarkInstall(Pkg, false);
	if (State.Install() == false)
	{
		if (_config->FindB("APT::Console::ReInstall", false) == true)
		{
			if (Pkg->CurrentVer == 0 || Pkg.CurrentVer().Downloadable() == false)
				ui_dialog(0, "Reinstall impossible", "\n Sorry, %s cannot be downloaded \n", Pkg.Name());
			else
				Cache.SetReInstall(Pkg, true);
		}
		else
		{
			if (AllowFail == true)
				ui_dialog(0, "Package already upgraded",
					  "\n Sorry, package is already the newest version: \n\n '%s' [= $2#%s$!] \n", Pkg.Name(), Cache[Pkg].InstVerIter(Cache).VerStr());
		}
	}
	else
		ExpectedInst++;

	// Install it with autoinstalling enabled.
	if (State.InstBroken() == true && BrokenFix == true)
		Cache.MarkInstall(Pkg, true);
	return true;
}