1 #ifndef APT_PRIVATE_INSTALL_H
2 #define APT_PRIVATE_INSTALL_H
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>
20 #include "private-output.h"
27 #define RAMFS_MAGIC 0x858458f6
29 bool DoInstall(CommandLine
&Cmd
);
31 bool DoCacheManipulationFromCommandLine(CommandLine
&CmdL
, CacheFile
&Cache
,
32 std::map
<unsigned short, APT::VersionSet
> &verset
);
33 bool DoCacheManipulationFromCommandLine(CommandLine
&CmdL
, CacheFile
&Cache
);
35 bool InstallPackages(CacheFile
&Cache
,bool ShwKept
,bool Ask
= true,
39 // TryToInstall - Mark a package for installation /*{{{*/
42 pkgProblemResolver
* Fix
;
44 unsigned long AutoMarkChanged
;
45 APT::PackageSet doAutoInstallLater
;
47 TryToInstall(pkgCacheFile
&Cache
, pkgProblemResolver
*PM
, bool const FixBroken
) : Cache(&Cache
), Fix(PM
),
48 FixBroken(FixBroken
), AutoMarkChanged(0) {};
50 void operator() (pkgCache::VerIterator
const &Ver
) {
51 pkgCache::PkgIterator Pkg
= Ver
.ParentPkg();
53 Cache
->GetDepCache()->SetCandidateVersion(Ver
);
54 pkgDepCache::StateCache
&State
= (*Cache
)[Pkg
];
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());
69 Cache
->GetDepCache()->MarkInstall(Pkg
,false);
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());
77 Cache
->GetDepCache()->SetReInstall(Pkg
, true);
79 ioprintf(c1out
,_("%s is already the newest version.\n"),
80 Pkg
.FullName(true).c_str());
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
);
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)
98 ioprintf(c1out
,_("%s set to manually installed.\n"),
99 Pkg
.FullName(true).c_str());
100 Cache
->GetDepCache()->MarkAuto(Pkg
,false);
105 bool propergateReleaseCandiateSwitching(std::list
<std::pair
<pkgCache::VerIterator
, std::string
> > start
, std::ostream
&out
)
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
);
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
)
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
);
123 for (std::list
<std::pair
<pkgCache::VerIterator
, pkgCache::VerIterator
> >::const_iterator c
= Changed
.begin();
124 c
!= Changed
.end(); ++c
)
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
)
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());
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)
145 Cache
->GetDepCache()->MarkInstall(P
, true);
147 doAutoInstallLater
.clear();
151 // TryToRemove - Mark a package for removal /*{{{*/
154 pkgProblemResolver
* Fix
;
157 TryToRemove(pkgCacheFile
&Cache
, pkgProblemResolver
*PM
) : Cache(&Cache
), Fix(PM
),
158 PurgePkgs(_config
->FindB("APT::Get::Purge", false)) {};
160 void operator() (pkgCache::VerIterator
const &Ver
)
162 pkgCache::PkgIterator Pkg
= Ver
.ParentPkg();
171 if ((Pkg
->CurrentVer
== 0 && PurgePkgs
== false) ||
172 (PurgePkgs
== true && Pkg
->CurrentState
== pkgCache::State::NotInstalled
))
174 pkgCache::GrpIterator Grp
= Pkg
.Group();
175 pkgCache::PkgIterator P
= Grp
.PackageList();
176 for (; P
.end() != true; P
= Grp
.NextPkg(P
))
180 if (P
->CurrentVer
!= 0 || (PurgePkgs
== true && P
->CurrentState
!= pkgCache::State::NotInstalled
))
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());
189 ioprintf(c1out
,_("Package '%s' is not installed, so not removed\n"),Pkg
.FullName(true).c_str());
191 // MarkInstall refuses to install packages on hold
192 Pkg
->SelectedState
= pkgCache::State::Hold
;
195 Cache
->GetDepCache()->MarkDelete(Pkg
, PurgePkgs
);