]> git.saurik.com Git - apt.git/blobdiff - apt-pkg/depcache.cc
* added APT::NeverAutoRemove (a list of regexp for package names that should never...
[apt.git] / apt-pkg / depcache.cc
index c6bf3185ae2b09bb4e093c6d91a02bf53f544b15..366687382121aad69d04f4de9e20da089d4db955 100644 (file)
 #include <apt-pkg/error.h>
 #include <apt-pkg/sptr.h>
 #include <apt-pkg/algorithms.h>
 #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>    
                                                                        /*}}}*/
 
 #include <apti18n.h>    
                                                                        /*}}}*/
 
@@ -72,7 +78,7 @@ bool pkgDepCache::Init(OpProgress *Prog)
       // Find the proper cache slot
       StateCache &State = PkgState[I->ID];
       State.iFlags = 0;
       // 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();
       // Figure out the install version
       State.CandidateVer = GetCandidateVer(I);
       State.InstallVer = I.CurrentVer();
@@ -91,11 +97,81 @@ bool pkgDepCache::Init(OpProgress *Prog)
    }
    
    Update(Prog);
    }
    
    Update(Prog);
+
+   if(Prog != 0)
+      Prog->Done();
    
    return true;
 } 
                                                                        /*}}}*/
 
    
    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("Install-Reason", 0);
+           if(reason > 0)
+              PkgState[pkg->ID].Flags  |= pkgCache::Flag::Auto;
+           if(_config->FindB("Debug::pkgAutoRemove",false))
+              std::cout << "Install-Reason for: " << pkgname 
+                        << " is " << reason << 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 & pkgCache::Flag::Auto) {
+        if(_config->FindB("Debug::pkgAutoRemove",false))
+           std::clog << "AutoInstal: " << pkg.Name() << std::endl;
+        ostr.str(string(""));
+        ostr << "Package: " << pkg.Name() 
+             << "\nInstall-Reason: 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
 // DepCache::CheckDep - Checks a single dependency                     /*{{{*/
 // ---------------------------------------------------------------------
 /* This first checks the dependency against the main target package and
@@ -447,6 +523,8 @@ void pkgDepCache::Update(OpProgress *Prog)
       AddStates(I);
    }
 
       AddStates(I);
    }
 
+   readStateFile(Prog);
+
    if (Prog != 0)      
       Prog->Progress(Done);
 }
    if (Prog != 0)      
       Prog->Progress(Done);
 }
@@ -582,7 +660,8 @@ void pkgDepCache::MarkDelete(PkgIterator const &Pkg, bool rPurge)
    else
       P.Mode = ModeDelete;
    P.InstallVer = 0;
    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);
 
    AddStates(Pkg);   
    Update(Pkg);