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