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>
12 #include <apt-pkg/macros.h>
14 #include <apt-private/private-output.h>
29 #define RAMFS_MAGIC 0x858458f6
31 APT_PUBLIC
bool DoInstall(CommandLine
&Cmd
);
33 bool DoCacheManipulationFromCommandLine(CommandLine
&CmdL
, CacheFile
&Cache
,
34 std::map
<unsigned short, APT::VersionSet
> &verset
);
35 bool DoCacheManipulationFromCommandLine(CommandLine
&CmdL
, CacheFile
&Cache
);
37 APT_PUBLIC
bool InstallPackages(CacheFile
&Cache
,bool ShwKept
,bool Ask
= true,
41 // TryToInstall - Mark a package for installation /*{{{*/
44 pkgProblemResolver
* Fix
;
46 unsigned long AutoMarkChanged
;
47 APT::PackageSet doAutoInstallLater
;
49 TryToInstall(pkgCacheFile
&Cache
, pkgProblemResolver
*PM
, bool const FixBroken
) : Cache(&Cache
), Fix(PM
),
50 FixBroken(FixBroken
), AutoMarkChanged(0) {};
52 void operator() (pkgCache::VerIterator
const &Ver
) {
53 pkgCache::PkgIterator Pkg
= Ver
.ParentPkg();
55 Cache
->GetDepCache()->SetCandidateVersion(Ver
);
56 pkgDepCache::StateCache
&State
= (*Cache
)[Pkg
];
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());
71 Cache
->GetDepCache()->MarkInstall(Pkg
,false);
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());
79 Cache
->GetDepCache()->SetReInstall(Pkg
, true);
81 ioprintf(c1out
,_("%s is already the newest version.\n"),
82 Pkg
.FullName(true).c_str());
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
);
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)
100 ioprintf(c1out
,_("%s set to manually installed.\n"),
101 Pkg
.FullName(true).c_str());
102 Cache
->GetDepCache()->MarkAuto(Pkg
,false);
107 bool propergateReleaseCandiateSwitching(std::list
<std::pair
<pkgCache::VerIterator
, std::string
> > start
, std::ostream
&out
)
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
);
114 // the Changed list contains:
115 // first: "new version"
116 // second: "what-caused the change"
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
)
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
);
125 for (std::list
<std::pair
<pkgCache::VerIterator
, pkgCache::VerIterator
> >::const_iterator c
= Changed
.begin();
126 c
!= Changed
.end(); ++c
)
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
)
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());
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)
147 Cache
->GetDepCache()->MarkInstall(P
, true);
149 doAutoInstallLater
.clear();
153 // TryToRemove - Mark a package for removal /*{{{*/
156 pkgProblemResolver
* Fix
;
159 TryToRemove(pkgCacheFile
&Cache
, pkgProblemResolver
*PM
) : Cache(&Cache
), Fix(PM
),
160 PurgePkgs(_config
->FindB("APT::Get::Purge", false)) {};
162 void operator() (pkgCache::VerIterator
const &Ver
)
164 pkgCache::PkgIterator Pkg
= Ver
.ParentPkg();
173 if ((Pkg
->CurrentVer
== 0 && PurgePkgs
== false) ||
174 (PurgePkgs
== true && Pkg
->CurrentState
== pkgCache::State::NotInstalled
))
176 pkgCache::GrpIterator Grp
= Pkg
.Group();
177 pkgCache::PkgIterator P
= Grp
.PackageList();
178 for (; P
.end() != true; P
= Grp
.NextPkg(P
))
182 if (P
->CurrentVer
!= 0 || (PurgePkgs
== true && P
->CurrentState
!= pkgCache::State::NotInstalled
))
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());
191 ioprintf(c1out
,_("Package '%s' is not installed, so not removed\n"),Pkg
.FullName(true).c_str());
193 // MarkInstall refuses to install packages on hold
194 Pkg
->SelectedState
= pkgCache::State::Hold
;
197 Cache
->GetDepCache()->MarkDelete(Pkg
, PurgePkgs
);