]> git.saurik.com Git - apt.git/blobdiff - apt-pkg/depcache.cc
* invert the auto-mark flag only for new installs (in MarkInstall()), keep it as...
[apt.git] / apt-pkg / depcache.cc
index d410413d40ad544bd9a1591ccdb17a3d95f3b574..4c52c6c719aa843d863dd2fc6a26b80557c5c234 100644 (file)
@@ -1,6 +1,6 @@
 // -*- mode: cpp; mode: fold -*-
 // Description                                                         /*{{{*/
-// $Id: depcache.cc,v 1.23 2001/02/20 07:03:17 jgg Exp $
+// $Id: depcache.cc,v 1.25 2001/05/27 05:36:04 jgg Exp $
 /* ######################################################################
 
    Dependency Cache - Caches Dependency information.
 #include <apt-pkg/error.h>
 #include <apt-pkg/sptr.h>
 #include <apt-pkg/algorithms.h>
-    
+
+#include <apt-pkg/fileutl.h>
+#include <apt-pkg/configuration.h>
+#include <apt-pkg/tagfile.h>
+
+#include <iostream>
+#include <sstream>    
 #include <apti18n.h>    
                                                                        /*}}}*/
 
@@ -57,8 +63,8 @@ bool pkgDepCache::Init(OpProgress *Prog)
    if (Prog != 0)
    {
       Prog->OverallProgress(0,2*Head().PackageCount,Head().PackageCount,
-                           _("Building Dependency Tree"));
-      Prog->SubProgress(Head().PackageCount,_("Candidate Versions"));
+                           _("Building dependency tree"));
+      Prog->SubProgress(Head().PackageCount,_("Candidate versions"));
    }
    
    /* Set the current state of everything. In this state all of the
@@ -72,7 +78,7 @@ bool pkgDepCache::Init(OpProgress *Prog)
       // Find the proper cache slot
       StateCache &State = PkgState[I->ID];
       State.iFlags = 0;
-      
+
       // Figure out the install version
       State.CandidateVer = GetCandidateVer(I);
       State.InstallVer = I.CurrentVer();
@@ -86,16 +92,85 @@ bool pkgDepCache::Init(OpProgress *Prog)
       
       Prog->OverallProgress(Head().PackageCount,2*Head().PackageCount,
                            Head().PackageCount,
-                           _("Building Dependency Tree"));
-      Prog->SubProgress(Head().PackageCount,_("Dependency Generation"));
+                           _("Building dependency tree"));
+      Prog->SubProgress(Head().PackageCount,_("Dependency generation"));
    }
    
    Update(Prog);
+
+   if(Prog != 0)
+      Prog->Done();
    
    return true;
 } 
                                                                        /*}}}*/
 
+bool pkgDepCache::readStateFile(OpProgress *Prog)
+{
+   FileFd state_file;
+   string state = _config->FindDir("Dir::State") + "pkgstates";
+   if(FileExists(state)) {
+      state_file.Open(state, FileFd::ReadOnly);
+      int file_size = state_file.Size();
+      if(Prog != NULL)
+        Prog->OverallProgress(0, file_size, 1, 
+                              _("Reading state information"));
+
+      pkgTagFile tagfile(&state_file);
+      pkgTagSection section;
+      int amt=0;
+      while(tagfile.Step(section)) {
+        string pkgname = section.FindS("Package");
+        pkgCache::PkgIterator pkg=Cache->FindPkg(pkgname);
+        // Silently ignore unknown packages and packages with no actual
+        // version.
+        if(!pkg.end() && !pkg.VersionList().end()) {
+           short reason = section.FindI("Auto-Installed", 0);
+           if(reason > 0)
+              PkgState[pkg->ID].Flags  |= Flag::Auto;
+           if(_config->FindB("Debug::pkgAutoRemove",false))
+              std::cout << "Auto-Installed : " << pkgname << std::endl;
+           amt+=section.size();
+           if(Prog != NULL)
+              Prog->OverallProgress(amt, file_size, 1, 
+                                    _("Reading state information"));
+        }
+        if(Prog != NULL)
+           Prog->OverallProgress(file_size, file_size, 1, 
+                                 _("Reading state information"));
+      }
+   }
+
+   return true;
+}
+
+bool pkgDepCache::writeStateFile(OpProgress *prog)
+{
+   FileFd StateFile;
+   string state = _config->FindDir("Dir::State") + "pkgstates";
+
+   if(_config->FindB("Debug::pkgAutoRemove",false))
+      std::clog << "pkgDepCache::writeStateFile()" << std::endl;
+
+   if(!StateFile.Open(state, FileFd::WriteEmpty))
+      return _error->Error(_("Failed to write StateFile %s"),
+                          state.c_str());
+
+   std::ostringstream ostr;
+   for(pkgCache::PkgIterator pkg=Cache->PkgBegin(); !pkg.end();pkg++) {
+
+      if(PkgState[pkg->ID].Flags & Flag::Auto) {
+        if(_config->FindB("Debug::pkgAutoRemove",false))
+           std::clog << "AutoInstal: " << pkg.Name() << std::endl;
+        ostr.str(string(""));
+        ostr << "Package: " << pkg.Name() 
+             << "\nAuto-Installed: 1\n\n";
+        StateFile.Write(ostr.str().c_str(), ostr.str().size());
+      }
+   }
+   return true;
+}
+
 // DepCache::CheckDep - Checks a single dependency                     /*{{{*/
 // ---------------------------------------------------------------------
 /* This first checks the dependency against the main target package and
@@ -182,6 +257,9 @@ void pkgDepCache::AddSizes(const PkgIterator &Pkg,signed long Mult)
 {
    StateCache &P = PkgState[Pkg->ID];
    
+   if (Pkg->VersionList == 0)
+      return;
+   
    if (Pkg.State() == pkgCache::PkgIterator::NeedsConfigure && 
        P.Keep() == true)
       return;
@@ -444,6 +522,8 @@ void pkgDepCache::Update(OpProgress *Prog)
       AddStates(I);
    }
 
+   readStateFile(Prog);
+
    if (Prog != 0)      
       Prog->Progress(Done);
 }
@@ -579,7 +659,8 @@ void pkgDepCache::MarkDelete(PkgIterator const &Pkg, bool rPurge)
    else
       P.Mode = ModeDelete;
    P.InstallVer = 0;
-   P.Flags &= Flag::Auto;
+   // This was not inverted before, but I think it should be
+   P.Flags &= ~Flag::Auto;
 
    AddStates(Pkg);   
    Update(Pkg);
@@ -627,7 +708,9 @@ void pkgDepCache::MarkInstall(PkgIterator const &Pkg,bool AutoInst,
    
    P.Mode = ModeInstall;
    P.InstallVer = P.CandidateVer;
-   P.Flags &= ~Flag::Auto;
+   // invert the auto-flag only for new installs, not for upgrades
+   if(P.Status == 0)
+      P.Flags &= ~Flag::Auto;
    if (P.CandidateVer == (Version *)Pkg.CurrentVer())
       P.Mode = ModeKeep;
        
@@ -669,7 +752,7 @@ void pkgDepCache::MarkInstall(PkgIterator const &Pkg,bool AutoInst,
          succeed. We have already cached this.. */
       for (; Ors > 1 && (DepState[Start->ID] & DepCVer) != DepCVer; Ors--)
         Start++;
-      
+
       /* This bit is for processing the possibilty of an install/upgrade
          fixing the problem */
       SPtrArray<Version *> List = Start.AllTargets();
@@ -691,7 +774,7 @@ void pkgDepCache::MarkInstall(PkgIterator const &Pkg,bool AutoInst,
         }
 
         // Select the highest priority providing package
-        if (InstPkg.end() == false)
+        if (InstPkg.end() == true)
         {
            pkgPrioSortList(*Cache,Cur);
            for (; *Cur != 0; Cur++)