Merge remote-tracking branch 'mvo/bugfix/coverity' into debian/sid
[ntk/apt.git] / apt-private / private-install.h
1 #ifndef APT_PRIVATE_INSTALL_H
2 #define APT_PRIVATE_INSTALL_H
3
4 #include <apt-pkg/cacheset.h>
5 #include <apt-pkg/cmndline.h>
6 #include <apt-pkg/strutl.h>
7
8 #include "private-cachefile.h"
9 #include "private-output.h"
10
11 #include <apti18n.h>
12
13 #define RAMFS_MAGIC 0x858458f6
14
15 bool DoInstall(CommandLine &Cmd);
16
17
18 bool InstallPackages(CacheFile &Cache,bool ShwKept,bool Ask = true,
19 bool Safety = true);
20
21
22 // TryToInstall - Mark a package for installation /*{{{*/
23 struct TryToInstall {
24 pkgCacheFile* Cache;
25 pkgProblemResolver* Fix;
26 bool FixBroken;
27 unsigned long AutoMarkChanged;
28 APT::PackageSet doAutoInstallLater;
29
30 TryToInstall(pkgCacheFile &Cache, pkgProblemResolver *PM, bool const FixBroken) : Cache(&Cache), Fix(PM),
31 FixBroken(FixBroken), AutoMarkChanged(0) {};
32
33 void operator() (pkgCache::VerIterator const &Ver) {
34 pkgCache::PkgIterator Pkg = Ver.ParentPkg();
35
36 Cache->GetDepCache()->SetCandidateVersion(Ver);
37 pkgDepCache::StateCache &State = (*Cache)[Pkg];
38
39 // Handle the no-upgrade case
40 if (_config->FindB("APT::Get::upgrade",true) == false && Pkg->CurrentVer != 0)
41 ioprintf(c1out,_("Skipping %s, it is already installed and upgrade is not set.\n"),
42 Pkg.FullName(true).c_str());
43 // Ignore request for install if package would be new
44 else if (_config->FindB("APT::Get::Only-Upgrade", false) == true && Pkg->CurrentVer == 0)
45 ioprintf(c1out,_("Skipping %s, it is not installed and only upgrades are requested.\n"),
46 Pkg.FullName(true).c_str());
47 else {
48 if (Fix != NULL) {
49 Fix->Clear(Pkg);
50 Fix->Protect(Pkg);
51 }
52 Cache->GetDepCache()->MarkInstall(Pkg,false);
53
54 if (State.Install() == false) {
55 if (_config->FindB("APT::Get::ReInstall",false) == true) {
56 if (Pkg->CurrentVer == 0 || Pkg.CurrentVer().Downloadable() == false)
57 ioprintf(c1out,_("Reinstallation of %s is not possible, it cannot be downloaded.\n"),
58 Pkg.FullName(true).c_str());
59 else
60 Cache->GetDepCache()->SetReInstall(Pkg, true);
61 } else
62 ioprintf(c1out,_("%s is already the newest version.\n"),
63 Pkg.FullName(true).c_str());
64 }
65
66 // Install it with autoinstalling enabled (if we not respect the minial
67 // required deps or the policy)
68 if (FixBroken == false)
69 doAutoInstallLater.insert(Pkg);
70 }
71
72 // see if we need to fix the auto-mark flag
73 // e.g. apt-get install foo
74 // where foo is marked automatic
75 if (State.Install() == false &&
76 (State.Flags & pkgCache::Flag::Auto) &&
77 _config->FindB("APT::Get::ReInstall",false) == false &&
78 _config->FindB("APT::Get::Only-Upgrade",false) == false &&
79 _config->FindB("APT::Get::Download-Only",false) == false)
80 {
81 ioprintf(c1out,_("%s set to manually installed.\n"),
82 Pkg.FullName(true).c_str());
83 Cache->GetDepCache()->MarkAuto(Pkg,false);
84 AutoMarkChanged++;
85 }
86 }
87
88 bool propergateReleaseCandiateSwitching(std::list<std::pair<pkgCache::VerIterator, std::string> > start, std::ostream &out)
89 {
90 for (std::list<std::pair<pkgCache::VerIterator, std::string> >::const_iterator s = start.begin();
91 s != start.end(); ++s)
92 Cache->GetDepCache()->SetCandidateVersion(s->first);
93
94 bool Success = true;
95 std::list<std::pair<pkgCache::VerIterator, pkgCache::VerIterator> > Changed;
96 for (std::list<std::pair<pkgCache::VerIterator, std::string> >::const_iterator s = start.begin();
97 s != start.end(); ++s)
98 {
99 Changed.push_back(std::make_pair(s->first, pkgCache::VerIterator(*Cache)));
100 // We continue here even if it failed to enhance the ShowBroken output
101 Success &= Cache->GetDepCache()->SetCandidateRelease(s->first, s->second, Changed);
102 }
103 for (std::list<std::pair<pkgCache::VerIterator, pkgCache::VerIterator> >::const_iterator c = Changed.begin();
104 c != Changed.end(); ++c)
105 {
106 if (c->second.end() == true)
107 ioprintf(out, _("Selected version '%s' (%s) for '%s'\n"),
108 c->first.VerStr(), c->first.RelStr().c_str(), c->first.ParentPkg().FullName(true).c_str());
109 else if (c->first.ParentPkg()->Group != c->second.ParentPkg()->Group)
110 {
111 pkgCache::VerIterator V = (*Cache)[c->first.ParentPkg()].CandidateVerIter(*Cache);
112 ioprintf(out, _("Selected version '%s' (%s) for '%s' because of '%s'\n"), V.VerStr(),
113 V.RelStr().c_str(), V.ParentPkg().FullName(true).c_str(), c->second.ParentPkg().FullName(true).c_str());
114 }
115 }
116 return Success;
117 }
118
119 void doAutoInstall() {
120 for (APT::PackageSet::const_iterator P = doAutoInstallLater.begin();
121 P != doAutoInstallLater.end(); ++P) {
122 pkgDepCache::StateCache &State = (*Cache)[P];
123 if (State.InstBroken() == false && State.InstPolicyBroken() == false)
124 continue;
125 Cache->GetDepCache()->MarkInstall(P, true);
126 }
127 doAutoInstallLater.clear();
128 }
129 };
130 /*}}}*/
131 // TryToRemove - Mark a package for removal /*{{{*/
132 struct TryToRemove {
133 pkgCacheFile* Cache;
134 pkgProblemResolver* Fix;
135 bool PurgePkgs;
136
137 TryToRemove(pkgCacheFile &Cache, pkgProblemResolver *PM) : Cache(&Cache), Fix(PM),
138 PurgePkgs(_config->FindB("APT::Get::Purge", false)) {};
139
140 void operator() (pkgCache::VerIterator const &Ver)
141 {
142 pkgCache::PkgIterator Pkg = Ver.ParentPkg();
143
144 if (Fix != NULL)
145 {
146 Fix->Clear(Pkg);
147 Fix->Protect(Pkg);
148 Fix->Remove(Pkg);
149 }
150
151 if ((Pkg->CurrentVer == 0 && PurgePkgs == false) ||
152 (PurgePkgs == true && Pkg->CurrentState == pkgCache::State::NotInstalled))
153 {
154 pkgCache::GrpIterator Grp = Pkg.Group();
155 pkgCache::PkgIterator P = Grp.PackageList();
156 for (; P.end() != true; P = Grp.NextPkg(P))
157 {
158 if (P == Pkg)
159 continue;
160 if (P->CurrentVer != 0 || (PurgePkgs == true && P->CurrentState != pkgCache::State::NotInstalled))
161 {
162 // TRANSLATORS: Note, this is not an interactive question
163 ioprintf(c1out,_("Package '%s' is not installed, so not removed. Did you mean '%s'?\n"),
164 Pkg.FullName(true).c_str(), P.FullName(true).c_str());
165 break;
166 }
167 }
168 if (P.end() == true)
169 ioprintf(c1out,_("Package '%s' is not installed, so not removed\n"),Pkg.FullName(true).c_str());
170
171 // MarkInstall refuses to install packages on hold
172 Pkg->SelectedState = pkgCache::State::Hold;
173 }
174 else
175 Cache->GetDepCache()->MarkDelete(Pkg, PurgePkgs);
176 }
177 };
178 /*}}}*/
179
180
181 #endif