]> git.saurik.com Git - apt.git/commitdiff
* cleanups
authorMichael Vogt <michael.vogt@ubuntu.com>
Thu, 23 Jun 2005 16:40:54 +0000 (16:40 +0000)
committerMichael Vogt <michael.vogt@ubuntu.com>
Thu, 23 Jun 2005 16:40:54 +0000 (16:40 +0000)
apt-pkg/depcache.cc
apt-pkg/depcache.h
cmdline/apt-get.cc

index 5da411e4d0c8a1cef3a1d5afd4971335162c73e9..552a45a16382acdb4932212079836d6f6bb2af45 100644 (file)
@@ -20,7 +20,7 @@
 #include <apt-pkg/fileutl.h>
 #include <apt-pkg/configuration.h>
 #include <apt-pkg/tagfile.h>
-    
+#include <sstream>    
 #include <apti18n.h>    
                                                                        /*}}}*/
 
@@ -103,6 +103,66 @@ bool pkgDepCache::Init(OpProgress *Prog)
 } 
                                                                        /*}}}*/
 
+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();
+      Prog->OverallProgress(0, file_size, 1, 
+                           _("Reading extended 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("Remove-Reason", 
+                                        pkgCache::State::RemoveManual);
+           PkgState[pkg->ID].AutomaticRemove = reason;
+           //std::cout << "Set: " << pkgname << " to " << reason << std::endl;
+           amt+=section.size();
+           Prog->OverallProgress(amt, file_size, 1, 
+                                 _("Reading extended state information"));
+        }
+        Prog->OverallProgress(file_size, file_size, 1, 
+                              _("Reading extended state information"));
+      }
+   }
+
+   return true;
+}
+
+bool pkgDepCache::writeStateFile(OpProgress *prog)
+{
+   // write the auto-mark list ----------------------------------
+
+   FileFd StateFile;
+   string state = _config->FindDir("Dir::State") + "pkgstates";
+
+   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].AutomaticRemove != pkgCache::State::RemoveUnknown) {
+        ostr.str(string(""));
+        ostr << "Package: " << pkg.Name()
+             << "\nRemove-Reason: "
+             << (int)(PkgState[pkg->ID].AutomaticRemove) << "\n\n";
+        StateFile.Write(ostr.str().c_str(), ostr.str().size());
+        //std::cout << "Writing auto-mark: " << ostr.str() << endl;
+      }
+   }
+   return true;
+}
+
 // DepCache::CheckDep - Checks a single dependency                     /*{{{*/
 // ---------------------------------------------------------------------
 /* This first checks the dependency against the main target package and
@@ -454,34 +514,7 @@ void pkgDepCache::Update(OpProgress *Prog)
       AddStates(I);
    }
 
-   // read the state file ------------------------------
-   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();
-      Prog->OverallProgress(0, file_size, 1, _("Reading extended 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("Remove-Reason", pkgCache::State::RemoveManual);
-           PkgState[pkg->ID].AutomaticRemove = reason;
-           //std::cout << "Set: " << pkgname << " to " << reason << std::endl;
-           amt+=section.size();
-           Prog->OverallProgress(amt, file_size, 1, _("Reading extended state information"));
-        }
-        Prog->OverallProgress(file_size, file_size, 1, _("Reading extended state information"));
-      }
-   }
-   //--------------------------------------
-
+   readStateFile(Prog);
 
    if (Prog != 0)      
       Prog->Progress(Done);
index f974bfacf324af615e4a8a51dfa01d45c3fa5cc9..e02ed72f04885421f6c1fbbc2c80000f63f0ca42 100644 (file)
@@ -198,6 +198,10 @@ class pkgDepCache : protected pkgCache::Namespace
    
    // This is for debuging
    void Update(OpProgress *Prog = 0);
+
+   // read persistent states
+   bool readStateFile(OpProgress *prog);
+   bool writeStateFile(OpProgress *prog);
    
    // Size queries
    inline double UsrSize() {return iUsrSize;};
index 31148a80754b6811ea2437ea7b1ac8a36e230ae3..9f9ecd37524cc551f3db788e4a9389e867112302 100644 (file)
@@ -994,25 +994,8 @@ bool InstallPackages(CacheFile &Cache,bool ShwKept,bool Ask = true,
         return _error->Error(_("Aborting install."));
       }
 
-      // write the auto-mark list ----------------------------------
       // -- we do it here because there is no libapt::Commit() :/
-      FileFd state_file;
-      string state = _config->FindDir("Dir::State") + "pkgstates";
-
-
-      state_file.Open(state, FileFd::WriteEmpty);
-      std::ostringstream ostr;
-      for(pkgCache::PkgIterator p=Cache->PkgBegin(); !p.end();p++) {
-        if(Cache[p].AutomaticRemove != pkgCache::State::RemoveUnknown) {
-           ostr.str(string(""));
-           ostr << "Package: " << p.Name()
-                << "\nRemove-Reason: "
-                << (int)(Cache[p].AutomaticRemove) << "\n\n";
-           state_file.Write(ostr.str().c_str(), ostr.str().size());
-           //std::cout << "Writing auto-mark: " << ostr.str() << endl;
-        }
-      }
-      // ----------------------------------------------------------
+      Cache->writeStateFile(NULL);
                 
       _system->UnLock();
       pkgPackageManager::OrderResult Res = PM->DoInstall();
@@ -1720,8 +1703,8 @@ bool DoInstall(CommandLine &CmdL)
         
         if (*J == 0) {
            List += string(I.Name()) + " ";
-           //if (_config->FindB("APT::Get::AutomaticRemove"))
-              Cache[I].AutomaticRemove = pkgCache::State::RemoveRequired;
+           // mark each pkg as auto-installed 
+           Cache[I].AutomaticRemove = pkgCache::State::RemoveRequired;
         VersionsList += string(Cache[I].CandVersion) + "\n";
      }
       }