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