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