add the various foldmarkers in apt-pkg & cmdline (no code change)
[ntk/apt.git] / apt-pkg / depcache.cc
index e9ef9ce..a284a05 100644 (file)
@@ -15,6 +15,7 @@
 #include <apt-pkg/algorithms.h>
 
 #include <apt-pkg/fileutl.h>
+#include <apt-pkg/strutl.h>
 #include <apt-pkg/configuration.h>
 #include <apt-pkg/pkgsystem.h>
 #include <apt-pkg/tagfile.h>
@@ -26,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)
 {
@@ -46,16 +47,8 @@ ConfigValueInSubTree(const char* SubTree, const char *needle)
    }
    return false;
 }
-
-std::string OutputInDepth(const unsigned long Depth)
-{
-   std::string output = "";
-   for(unsigned long d=Depth; d > 0; d--)
-      output += "  ";
-   return output;
-}
-
-pkgDepCache::ActionGroup::ActionGroup(pkgDepCache &cache) :
+                                                                       /*}}}*/
+pkgDepCache::ActionGroup::ActionGroup(pkgDepCache &cache) :            /*{{{*/
   cache(cache), released(false)
 {
   ++cache.group_level;
@@ -83,7 +76,7 @@ pkgDepCache::ActionGroup::~ActionGroup()
 {
   release();
 }
-
+                                                                       /*}}}*/
 // DepCache::pkgDepCache - Constructors                                        /*{{{*/
 // ---------------------------------------------------------------------
 /* */
@@ -168,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";
@@ -207,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;
@@ -290,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
@@ -708,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              /*{{{*/
 // ---------------------------------------------------------------------
 /* */
@@ -1011,7 +1001,8 @@ void pkgDepCache::MarkInstall(PkgIterator const &Pkg,bool AutoInst,
            }
         }
         
-        if (InstPkg.end() == false) 
+        if (InstPkg.end() == false &&
+            AutoInstOk(InstPkg, (*this)[InstPkg].CandidateVerIter(*this), Start))
         {
            if(DebugAutoInstall == true)
               std::clog << OutputInDepth(Depth) << "Installing " << InstPkg.Name()
@@ -1049,9 +1040,13 @@ void pkgDepCache::MarkInstall(PkgIterator const &Pkg,bool AutoInst,
            PkgIterator Pkg = Ver.ParentPkg();
 
            if (Start->Type != Dep::DpkgBreaks)
-              MarkDelete(Pkg,false,Depth + 1);
+           {
+              if(AutoInstOk(Pkg, VerIterator(*this), Start))
+                 MarkDelete(Pkg);
+           }
            else
-              if (PkgState[Pkg->ID].CandidateVer != *I)
+              if (PkgState[Pkg->ID].CandidateVer != *I &&
+                  AutoInstOk(Pkg, VerIterator(*this, PkgState[Pkg->ID].CandidateVer), Start))
                  MarkInstall(Pkg,true,Depth + 1, false, ForceImportantDeps);
         }
         continue;
@@ -1059,6 +1054,18 @@ void pkgDepCache::MarkInstall(PkgIterator const &Pkg,bool AutoInst,
    }
 }
                                                                        /*}}}*/
+// DepCache::AutoInstOk - check if it is to install this package       /*{{{*/
+// ---------------------------------------------------------------------
+/* The default implementation just honors dpkg hold
+   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)
+{
+   return (Pkg->SelectedState != pkgCache::State::Hold);
+}
+                                                                       /*}}}*/
 // DepCache::SetReInstall - Set the reinstallation flag                        /*{{{*/
 // ---------------------------------------------------------------------
 /* */
@@ -1158,7 +1165,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
@@ -1195,7 +1201,6 @@ pkgCache::VerIterator pkgDepCache::Policy::GetCandidateVer(PkgIterator Pkg)
    return Last;
 }
                                                                        /*}}}*/
-
 // Policy::IsImportantDep - True if the dependency is important                /*{{{*/
 // ---------------------------------------------------------------------
 /* */
@@ -1221,8 +1226,7 @@ bool pkgDepCache::Policy::IsImportantDep(DepIterator Dep)
    return false;
 }
                                                                        /*}}}*/
-
-pkgDepCache::DefaultRootSetFunc::DefaultRootSetFunc()
+pkgDepCache::DefaultRootSetFunc::DefaultRootSetFunc()                  /*{{{*/
   : constructedSuccessfully(false)
 {
   Configuration::Item const *Opts;
@@ -1251,8 +1255,8 @@ pkgDepCache::DefaultRootSetFunc::DefaultRootSetFunc()
 
   constructedSuccessfully = true;
 }
-
-pkgDepCache::DefaultRootSetFunc::~DefaultRootSetFunc()
+                                                                       /*}}}*/
+pkgDepCache::DefaultRootSetFunc::~DefaultRootSetFunc()                 /*{{{*/
 {
   for(unsigned int i = 0; i < rootSetRegexp.size(); i++)
     {
@@ -1260,9 +1264,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)
@@ -1270,8 +1273,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())
@@ -1282,7 +1285,7 @@ pkgDepCache::InRootSetFunc *pkgDepCache::GetRootSetFunc()
       return NULL;
     }
 }
-
+                                                                       /*}}}*/
 bool pkgDepCache::MarkFollowsRecommends()
 {
   return _config->FindB("APT::AutoRemove::RecommendsImportant", true);
@@ -1293,7 +1296,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;
@@ -1338,8 +1341,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,
@@ -1458,8 +1461,8 @@ void pkgDepCache::MarkPackage(const pkgCache::PkgIterator &pkg,
      }
    }
 }
-
-bool pkgDepCache::Sweep()
+                                                                       /*}}}*/
+bool pkgDepCache::Sweep()                                              /*{{{*/
 {
    // do the sweep
    for(PkgIterator p=PkgBegin(); !p.end(); ++p)
@@ -1482,3 +1485,4 @@ bool pkgDepCache::Sweep()
 
    return true;
 }
+                                                                       /*}}}*/