]> 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 269fe8543f7e069bc74c4aca61a6f3e5e4e3fd94..366687382121aad69d04f4de9e20da089d4db955 100644 (file)
@@ -20,6 +20,8 @@
 #include <apt-pkg/fileutl.h>
 #include <apt-pkg/configuration.h>
 #include <apt-pkg/tagfile.h>
 #include <apt-pkg/fileutl.h>
 #include <apt-pkg/configuration.h>
 #include <apt-pkg/tagfile.h>
+
+#include <iostream>
 #include <sstream>    
 #include <apti18n.h>    
                                                                        /*}}}*/
 #include <sstream>    
 #include <apti18n.h>    
                                                                        /*}}}*/
@@ -76,9 +78,6 @@ 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;
-      State.DirtyState = pkgCache::State::RemoveUnknown;
-      //State.AutomaticRemove = I->AutomaticRemove;
-      State.AutomaticRemove = pkgCache::State::RemoveUnknown;
 
       // Figure out the install version
       State.CandidateVer = GetCandidateVer(I);
 
       // Figure out the install version
       State.CandidateVer = GetCandidateVer(I);
@@ -98,6 +97,9 @@ bool pkgDepCache::Init(OpProgress *Prog)
    }
    
    Update(Prog);
    }
    
    Update(Prog);
+
+   if(Prog != 0)
+      Prog->Done();
    
    return true;
 } 
    
    return true;
 } 
@@ -110,8 +112,9 @@ bool pkgDepCache::readStateFile(OpProgress *Prog)
    if(FileExists(state)) {
       state_file.Open(state, FileFd::ReadOnly);
       int file_size = state_file.Size();
    if(FileExists(state)) {
       state_file.Open(state, FileFd::ReadOnly);
       int file_size = state_file.Size();
-      Prog->OverallProgress(0, file_size, 1, 
-                           _("Reading extended state information"));
+      if(Prog != NULL)
+        Prog->OverallProgress(0, file_size, 1, 
+                              _("Reading state information"));
 
       pkgTagFile tagfile(&state_file);
       pkgTagSection section;
 
       pkgTagFile tagfile(&state_file);
       pkgTagSection section;
@@ -122,16 +125,20 @@ bool pkgDepCache::readStateFile(OpProgress *Prog)
         // Silently ignore unknown packages and packages with no actual
         // version.
         if(!pkg.end() && !pkg.VersionList().end()) {
         // Silently ignore unknown packages and packages with no actual
         // version.
         if(!pkg.end() && !pkg.VersionList().end()) {
-           short reason = section.FindI("Remove-Reason", 
-                                        pkgCache::State::RemoveManual);
-           PkgState[pkg->ID].AutomaticRemove = reason;
-           //std::cout << "Set: " << pkgname << " to " << reason << std::endl;
+           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();
            amt+=section.size();
-           Prog->OverallProgress(amt, file_size, 1, 
-                                 _("Reading extended state information"));
+           if(Prog != NULL)
+              Prog->OverallProgress(amt, file_size, 1, 
+                                    _("Reading state information"));
         }
         }
-        Prog->OverallProgress(file_size, file_size, 1, 
-                              _("Reading extended state information"));
+        if(Prog != NULL)
+           Prog->OverallProgress(file_size, file_size, 1, 
+                                 _("Reading state information"));
       }
    }
 
       }
    }
 
@@ -140,12 +147,12 @@ bool pkgDepCache::readStateFile(OpProgress *Prog)
 
 bool pkgDepCache::writeStateFile(OpProgress *prog)
 {
 
 bool pkgDepCache::writeStateFile(OpProgress *prog)
 {
-   // FIXME: this function needs to be called inside the commit()
-   // of the package manager. so after 
-
    FileFd StateFile;
    string state = _config->FindDir("Dir::State") + "pkgstates";
 
    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());
    if(!StateFile.Open(state, FileFd::WriteEmpty))
       return _error->Error(_("Failed to write StateFile %s"),
                           state.c_str());
@@ -153,23 +160,13 @@ bool pkgDepCache::writeStateFile(OpProgress *prog)
    std::ostringstream ostr;
    for(pkgCache::PkgIterator pkg=Cache->PkgBegin(); !pkg.end();pkg++) {
 
    std::ostringstream ostr;
    for(pkgCache::PkgIterator pkg=Cache->PkgBegin(); !pkg.end();pkg++) {
 
-      // clear out no longer installed pkg
-      if(PkgState[pkg->ID].Delete() || pkg.CurrentVer() == NULL) 
-        PkgState[pkg->ID].AutomaticRemove = pkgCache::State::RemoveUnknown;
-
-      // check if we have new information
       if(PkgState[pkg->ID].Flags & pkgCache::Flag::Auto) {
       if(PkgState[pkg->ID].Flags & pkgCache::Flag::Auto) {
-        std::cout << "pkg: " << pkg.Name() << " is auto-dep" << std::endl;
-        PkgState[pkg->ID].AutomaticRemove = pkgCache::State::RemoveRequired;
-      }
-
-      if(PkgState[pkg->ID].AutomaticRemove != pkgCache::State::RemoveUnknown) {
+        if(_config->FindB("Debug::pkgAutoRemove",false))
+           std::clog << "AutoInstal: " << pkg.Name() << std::endl;
         ostr.str(string(""));
         ostr.str(string(""));
-        ostr << "Package: " << pkg.Name()
-             << "\nRemove-Reason: "
-             << (int)(PkgState[pkg->ID].AutomaticRemove) << "\n\n";
+        ostr << "Package: " << pkg.Name() 
+             << "\nInstall-Reason: 1\n\n";
         StateFile.Write(ostr.str().c_str(), ostr.str().size());
         StateFile.Write(ostr.str().c_str(), ostr.str().size());
-        //std::cout << "Writing auto-mark: " << ostr.str() << endl;
       }
    }
    return true;
       }
    }
    return true;
@@ -836,15 +833,6 @@ void pkgDepCache::SetReInstall(PkgIterator const &Pkg,bool To)
    AddSizes(Pkg);
 }
                                                                        /*}}}*/
    AddSizes(Pkg);
 }
                                                                        /*}}}*/
-// DepCache::SetDirty - Switch the package between dirty states                /*{{{*/
-// ---------------------------------------------------------------------
-/* */
-void pkgDepCache::SetDirty(PkgIterator const &Pkg, pkgCache::State::PkgRemoveState To)
-{
-   StateCache &P = PkgState[Pkg->ID];
-   P.DirtyState = To;
-}
-                                                                       /*}}}*/
 // DepCache::SetCandidateVersion - Change the candidate version                /*{{{*/
 // ---------------------------------------------------------------------
 /* */
 // DepCache::SetCandidateVersion - Change the candidate version                /*{{{*/
 // ---------------------------------------------------------------------
 /* */