summaryrefslogtreecommitdiff
path: root/apt-pkg/depcache.cc
diff options
context:
space:
mode:
authorMichael Vogt <michael.vogt@ubuntu.com>2009-07-21 18:31:36 +0200
committerMichael Vogt <michael.vogt@ubuntu.com>2009-07-21 18:31:36 +0200
commitd59725349555939d39af81cf7746069d6aa3536c (patch)
tree90a85a3e4ffef76d9572ecf4a1dc8323f7ea38c9 /apt-pkg/depcache.cc
parent02e8ba352f71b82a936f5034059251425ab183d5 (diff)
parentc5f44afc2446d738e30ea4c6021d4b60915546b1 (diff)
The 'not dead yet' release
* add hook for MarkInstall and MarkDelete (closes: #470035) * add the various foldmarkers in apt-pkg & cmdline (no code change) * versions with a pin of -1 shouldn't be a candidate (Closes: #355237) * prefer mmap as memory allocator in MMap instead of a static char array which can (at least in theory) grow dynamic * eliminate (hopefully all) segfaults in pkgcachegen.cc and mmap.cc which can arise if cache doesn't fit into the mmap (Closes: #535218) * display warnings instead of errors if the parts dirs doesn't exist * honor the dpkg hold state in new Marker hooks (closes: #64141)
Diffstat (limited to 'apt-pkg/depcache.cc')
-rw-r--r--apt-pkg/depcache.cc121
1 files changed, 70 insertions, 51 deletions
diff --git a/apt-pkg/depcache.cc b/apt-pkg/depcache.cc
index b1b8f970f..e17b7b0e8 100644
--- a/apt-pkg/depcache.cc
+++ b/apt-pkg/depcache.cc
@@ -27,8 +27,8 @@
#include <sys/stat.h>
#include <apti18n.h>
-
-// helper for Install-Recommends-Sections and Never-MarkAuto-Sections
+ /*}}}*/
+// helper for Install-Recommends-Sections and Never-MarkAuto-Sections /*{{{*/
static bool
ConfigValueInSubTree(const char* SubTree, const char *needle)
{
@@ -47,8 +47,8 @@ ConfigValueInSubTree(const char* SubTree, const char *needle)
}
return false;
}
-
-pkgDepCache::ActionGroup::ActionGroup(pkgDepCache &cache) :
+ /*}}}*/
+pkgDepCache::ActionGroup::ActionGroup(pkgDepCache &cache) : /*{{{*/
cache(cache), released(false)
{
++cache.group_level;
@@ -76,7 +76,7 @@ pkgDepCache::ActionGroup::~ActionGroup()
{
release();
}
-
+ /*}}}*/
// DepCache::pkgDepCache - Constructors /*{{{*/
// ---------------------------------------------------------------------
/* */
@@ -161,8 +161,7 @@ bool pkgDepCache::Init(OpProgress *Prog)
return true;
}
/*}}}*/
-
-bool pkgDepCache::readStateFile(OpProgress *Prog)
+bool pkgDepCache::readStateFile(OpProgress *Prog) /*{{{*/
{
FileFd state_file;
string state = _config->FindDir("Dir::State") + "extended_states";
@@ -200,8 +199,8 @@ bool pkgDepCache::readStateFile(OpProgress *Prog)
return true;
}
-
-bool pkgDepCache::writeStateFile(OpProgress *prog, bool InstalledOnly)
+ /*}}}*/
+bool pkgDepCache::writeStateFile(OpProgress *prog, bool InstalledOnly) /*{{{*/
{
if(_config->FindB("Debug::pkgAutoRemove",false))
std::clog << "pkgDepCache::writeStateFile()" << std::endl;
@@ -283,7 +282,7 @@ bool pkgDepCache::writeStateFile(OpProgress *prog, bool InstalledOnly)
return true;
}
-
+ /*}}}*/
// DepCache::CheckDep - Checks a single dependency /*{{{*/
// ---------------------------------------------------------------------
/* This first checks the dependency against the main target package and
@@ -701,9 +700,7 @@ void pkgDepCache::Update(PkgIterator const &Pkg)
P.end() != true; P++)
Update(P.ParentPkg().RevDependsList());
}
-
/*}}}*/
-
// DepCache::MarkKeep - Put the package in the keep state /*{{{*/
// ---------------------------------------------------------------------
/* */
@@ -750,7 +747,7 @@ void pkgDepCache::MarkKeep(PkgIterator const &Pkg, bool Soft, bool FromUser,
#endif
if (DebugMarker == true)
- std::clog << OutputInDepth(Depth) << "MarkKeep " << Pkg << std::endl;
+ std::clog << OutputInDepth(Depth) << "MarkKeep " << Pkg << " FU=" << FromUser << std::endl;
RemoveSizes(Pkg);
RemoveStates(Pkg);
@@ -772,7 +769,7 @@ void pkgDepCache::MarkKeep(PkgIterator const &Pkg, bool Soft, bool FromUser,
// ---------------------------------------------------------------------
/* */
void pkgDepCache::MarkDelete(PkgIterator const &Pkg, bool rPurge,
- unsigned long Depth)
+ unsigned long Depth, bool FromUser)
{
// Simplifies other routines.
if (Pkg.end() == true)
@@ -794,8 +791,12 @@ void pkgDepCache::MarkDelete(PkgIterator const &Pkg, bool rPurge,
if (Pkg->VersionList == 0)
return;
+ // check if we are allowed to install the package
+ if (IsDeleteOk(Pkg,rPurge,Depth,FromUser) == false)
+ return;
+
if (DebugMarker == true)
- std::clog << OutputInDepth(Depth) << "MarkDelete " << Pkg << std::endl;
+ std::clog << OutputInDepth(Depth) << "MarkDelete " << Pkg << " FU=" << FromUser << std::endl;
RemoveSizes(Pkg);
RemoveStates(Pkg);
@@ -811,6 +812,23 @@ void pkgDepCache::MarkDelete(PkgIterator const &Pkg, bool rPurge,
AddSizes(Pkg);
}
/*}}}*/
+// DepCache::IsDeleteOk - check if it is ok to remove this package /*{{{*/
+// ---------------------------------------------------------------------
+/* The default implementation just honors dpkg hold
+ But an application using this library can override this method
+ to control the MarkDelete behaviour */
+bool pkgDepCache::IsDeleteOk(PkgIterator const &Pkg,bool rPurge,
+ unsigned long Depth, bool FromUser)
+{
+ if (FromUser == false && Pkg->SelectedState == pkgCache::State::Hold)
+ {
+ if (DebugMarker == true)
+ std::clog << OutputInDepth(Depth) << "Hold prevents MarkDelete of " << Pkg << " FU=" << FromUser << std::endl;
+ return false;
+ }
+ return true;
+}
+ /*}}}*/
// DepCache::MarkInstall - Put the package in the install state /*{{{*/
// ---------------------------------------------------------------------
/* */
@@ -846,6 +864,11 @@ void pkgDepCache::MarkInstall(PkgIterator const &Pkg,bool AutoInst,
// We dont even try to install virtual packages..
if (Pkg->VersionList == 0)
return;
+
+ // check if we are allowed to install the package
+ if (IsInstallOk(Pkg,AutoInst,Depth,FromUser) == false)
+ return;
+
/* Target the candidate version and remove the autoflag. We reset the
autoflag below if this was called recursively. Otherwise the user
should have the ability to de-auto a package by changing its state */
@@ -874,12 +897,12 @@ void pkgDepCache::MarkInstall(PkgIterator const &Pkg,bool AutoInst,
AddStates(Pkg);
Update(Pkg);
AddSizes(Pkg);
-
+
if (AutoInst == false)
return;
if (DebugMarker == true)
- std::clog << OutputInDepth(Depth) << "MarkInstall " << Pkg << std::endl;
+ std::clog << OutputInDepth(Depth) << "MarkInstall " << Pkg << " FU=" << FromUser << std::endl;
DepIterator Dep = P.InstVerIter(*this).DependsList();
for (; Dep.end() != true;)
@@ -1004,8 +1027,7 @@ void pkgDepCache::MarkInstall(PkgIterator const &Pkg,bool AutoInst,
}
}
- if (InstPkg.end() == false &&
- AutoInstOk(InstPkg, (*this)[InstPkg].CandidateVerIter(*this), Start))
+ if (InstPkg.end() == false)
{
if(DebugAutoInstall == true)
std::clog << OutputInDepth(Depth) << "Installing " << InstPkg.Name()
@@ -1043,30 +1065,30 @@ void pkgDepCache::MarkInstall(PkgIterator const &Pkg,bool AutoInst,
PkgIterator Pkg = Ver.ParentPkg();
if (Start->Type != Dep::DpkgBreaks)
- {
- if(AutoInstOk(Pkg, VerIterator(*this), Start))
- MarkDelete(Pkg);
- }
- else
- if (PkgState[Pkg->ID].CandidateVer != *I &&
- AutoInstOk(Pkg, VerIterator(*this, PkgState[Pkg->ID].CandidateVer), Start))
- MarkInstall(Pkg,true,Depth + 1, false, ForceImportantDeps);
+ MarkDelete(Pkg,false,Depth + 1, false);
+ else if (PkgState[Pkg->ID].CandidateVer != *I)
+ MarkInstall(Pkg,true,Depth + 1, false, ForceImportantDeps);
}
continue;
}
}
}
-
-// DepCache::AutoInstOk - check if it is to install this package /*{{{*/
+ /*}}}*/
+// DepCache::IsInstallOk - check if it is ok to install this package /*{{{*/
// ---------------------------------------------------------------------
/* The default implementation just honors dpkg hold
- But an application using this library can override this method
+ But an application using this library can override this method
to control the MarkInstall behaviour */
-bool pkgDepCache::AutoInstOk(const PkgIterator &Pkg,
- const VerIterator &v,
- const DepIterator &d)
+bool pkgDepCache::IsInstallOk(PkgIterator const &Pkg,bool AutoInst,
+ unsigned long Depth, bool FromUser)
{
- return (Pkg->SelectedState != pkgCache::State::Hold);
+ if (FromUser == false && Pkg->SelectedState == pkgCache::State::Hold)
+ {
+ if (DebugMarker == true)
+ std::clog << OutputInDepth(Depth) << "Hold prevents MarkInstall of " << Pkg << " FU=" << FromUser << std::endl;
+ return false;
+ }
+ return true;
}
/*}}}*/
// DepCache::SetReInstall - Set the reinstallation flag /*{{{*/
@@ -1168,7 +1190,6 @@ const char *pkgDepCache::StateCache::StripEpoch(const char *Ver)
return Ver;
}
/*}}}*/
-
// Policy::GetCandidateVer - Returns the Candidate install version /*{{{*/
// ---------------------------------------------------------------------
/* The default just returns the highest available version that is not
@@ -1205,7 +1226,6 @@ pkgCache::VerIterator pkgDepCache::Policy::GetCandidateVer(PkgIterator Pkg)
return Last;
}
/*}}}*/
-
// Policy::IsImportantDep - True if the dependency is important /*{{{*/
// ---------------------------------------------------------------------
/* */
@@ -1231,8 +1251,7 @@ bool pkgDepCache::Policy::IsImportantDep(DepIterator Dep)
return false;
}
/*}}}*/
-
-pkgDepCache::DefaultRootSetFunc::DefaultRootSetFunc()
+pkgDepCache::DefaultRootSetFunc::DefaultRootSetFunc() /*{{{*/
: constructedSuccessfully(false)
{
Configuration::Item const *Opts;
@@ -1261,8 +1280,8 @@ pkgDepCache::DefaultRootSetFunc::DefaultRootSetFunc()
constructedSuccessfully = true;
}
-
-pkgDepCache::DefaultRootSetFunc::~DefaultRootSetFunc()
+ /*}}}*/
+pkgDepCache::DefaultRootSetFunc::~DefaultRootSetFunc() /*{{{*/
{
for(unsigned int i = 0; i < rootSetRegexp.size(); i++)
{
@@ -1270,9 +1289,8 @@ pkgDepCache::DefaultRootSetFunc::~DefaultRootSetFunc()
delete rootSetRegexp[i];
}
}
-
-
-bool pkgDepCache::DefaultRootSetFunc::InRootSet(const pkgCache::PkgIterator &pkg)
+ /*}}}*/
+bool pkgDepCache::DefaultRootSetFunc::InRootSet(const pkgCache::PkgIterator &pkg) /*{{{*/
{
for(unsigned int i = 0; i < rootSetRegexp.size(); i++)
if (regexec(rootSetRegexp[i], pkg.Name(), 0, 0, 0) == 0)
@@ -1280,8 +1298,8 @@ bool pkgDepCache::DefaultRootSetFunc::InRootSet(const pkgCache::PkgIterator &pkg
return false;
}
-
-pkgDepCache::InRootSetFunc *pkgDepCache::GetRootSetFunc()
+ /*}}}*/
+pkgDepCache::InRootSetFunc *pkgDepCache::GetRootSetFunc() /*{{{*/
{
DefaultRootSetFunc *f = new DefaultRootSetFunc;
if(f->wasConstructedSuccessfully())
@@ -1292,7 +1310,7 @@ pkgDepCache::InRootSetFunc *pkgDepCache::GetRootSetFunc()
return NULL;
}
}
-
+ /*}}}*/
bool pkgDepCache::MarkFollowsRecommends()
{
return _config->FindB("APT::AutoRemove::RecommendsImportant", true);
@@ -1303,7 +1321,7 @@ bool pkgDepCache::MarkFollowsSuggests()
return _config->FindB("APT::AutoRemove::SuggestsImportant", false);
}
-// the main mark algorithm
+// pkgDepCache::MarkRequired - the main mark algorithm /*{{{*/
bool pkgDepCache::MarkRequired(InRootSetFunc &userFunc)
{
bool follow_recommends;
@@ -1348,8 +1366,8 @@ bool pkgDepCache::MarkRequired(InRootSetFunc &userFunc)
return true;
}
-
-// mark a single package in Mark-and-Sweep
+ /*}}}*/
+// MarkPackage - mark a single package in Mark-and-Sweep /*{{{*/
void pkgDepCache::MarkPackage(const pkgCache::PkgIterator &pkg,
const pkgCache::VerIterator &ver,
bool follow_recommends,
@@ -1468,8 +1486,8 @@ void pkgDepCache::MarkPackage(const pkgCache::PkgIterator &pkg,
}
}
}
-
-bool pkgDepCache::Sweep()
+ /*}}}*/
+bool pkgDepCache::Sweep() /*{{{*/
{
// do the sweep
for(PkgIterator p=PkgBegin(); !p.end(); ++p)
@@ -1492,3 +1510,4 @@ bool pkgDepCache::Sweep()
return true;
}
+ /*}}}*/