Просмотр исходного кода

* merged the apt--DoListUpdate branch, this provides a common interface
for apt-get update like operations for the frontends and also provides
hooks to run stuff in APT::Update::{Pre,Post}-Invoke

Michael Vogt лет назад: 18
Родитель
Сommit
893d3e85b9

+ 69 - 0
apt-pkg/cachefile.cc

@@ -19,6 +19,8 @@
 #include <apt-pkg/configuration.h>
 #include <apt-pkg/policy.h>
 #include <apt-pkg/pkgsystem.h>
+#include <apt-pkg/acquire-item.h>
+#include <apt-pkg/fileutl.h>
     
 #include <apti18n.h>
 									/*}}}*/
@@ -107,6 +109,73 @@ bool pkgCacheFile::Open(OpProgress &Progress,bool WithLock)
 }
 									/*}}}*/
 
+// CacheFile::ListUpdate - update the cache files                    	/*{{{*/
+// ---------------------------------------------------------------------
+/* This is a simple wrapper to update the cache. it will fetch stuff
+ * from the network (or any other sources defined in sources.list)
+ */
+bool pkgCacheFile::ListUpdate(pkgAcquireStatus &Stat, pkgSourceList &List)
+{
+   pkgAcquire Fetcher(&Stat);
+
+   // Populate it with the source selection
+   if (List.GetIndexes(&Fetcher) == false)
+	 return false;
+
+   // Run scripts
+   RunScripts("APT::Update::Pre-Invoke");
+   
+   // Run it
+   if (Fetcher.Run() == pkgAcquire::Failed)
+      return false;
+
+   bool Failed = false;
+   bool TransientNetworkFailure = false;
+   for (pkgAcquire::ItemIterator I = Fetcher.ItemsBegin(); 
+	I != Fetcher.ItemsEnd(); I++)
+   {
+      if ((*I)->Status == pkgAcquire::Item::StatDone)
+	 continue;
+
+      (*I)->Finished();
+
+      fprintf(stderr,_("Failed to fetch %s  %s\n"),(*I)->DescURI().c_str(),
+	      (*I)->ErrorText.c_str());
+
+      if ((*I)->Status == pkgAcquire::Item::StatTransientNetworkError) 
+      {
+	 TransientNetworkFailure = true;
+	 continue;
+      }
+
+      Failed = true;
+   }
+   
+   // Clean out any old list files
+   // Keep "APT::Get::List-Cleanup" name for compatibility, but
+   // this is really a global option for the APT library now
+   if (!TransientNetworkFailure && !Failed &&
+       (_config->FindB("APT::Get::List-Cleanup",true) == true ||
+	_config->FindB("APT::List-Cleanup",true) == true))
+   {
+      if (Fetcher.Clean(_config->FindDir("Dir::State::lists")) == false ||
+	  Fetcher.Clean(_config->FindDir("Dir::State::lists") + "partial/") == false)
+	 // something went wrong with the clean
+	 return false;
+   }
+   
+   if (TransientNetworkFailure == true)
+      _error->Warning(_("Some index files failed to download, they have been ignored, or old ones used instead."));
+   else if (Failed == true)
+      return _error->Error(_("Some index files failed to download, they have been ignored, or old ones used instead."));
+
+
+   // Run the scripts if all was fine
+   RunScripts("APT::Update::Post-Invoke");
+   return true;
+}
+									/*}}}*/
+
 // CacheFile::Close - close the cache files				/*{{{*/
 // ---------------------------------------------------------------------
 /* */

+ 3 - 0
apt-pkg/cachefile.h

@@ -19,6 +19,8 @@
 
 
 #include <apt-pkg/depcache.h>
+#include <apt-pkg/acquire.h>
+#include <apt-pkg/sourcelist.h>
 
 class pkgPolicy;
 class pkgCacheFile
@@ -45,6 +47,7 @@ class pkgCacheFile
 
    bool BuildCaches(OpProgress &Progress,bool WithLock = true);
    bool Open(OpProgress &Progress,bool WithLock = true);
+   bool ListUpdate(pkgAcquireStatus &progress, pkgSourceList &List);
    void Close();
    
    pkgCacheFile();

+ 66 - 1
apt-pkg/contrib/fileutl.cc

@@ -8,9 +8,12 @@
    CopyFile - Buffered copy of a single file
    GetLock - dpkg compatible lock file manipulation (fcntl)
    
-   This source is placed in the Public Domain, do with it what you will
+   Most of this source is placed in the Public Domain, do with it what 
+   you will
    It was originally written by Jason Gunthorpe <jgg@debian.org>.
    
+   The exception is RunScripts() it is under the GPLv2
+
    ##################################################################### */
 									/*}}}*/
 // Include Files							/*{{{*/
@@ -38,6 +41,68 @@
 
 using namespace std;
 
+// RunScripts - Run a set of scripts from a configuration subtree	/*{{{*/
+// ---------------------------------------------------------------------
+/* */
+bool RunScripts(const char *Cnf)
+{
+   Configuration::Item const *Opts = _config->Tree(Cnf);
+   if (Opts == 0 || Opts->Child == 0)
+      return true;
+   Opts = Opts->Child;
+
+   // Fork for running the system calls
+   pid_t Child = ExecFork();
+   
+   // This is the child
+   if (Child == 0)
+   {
+      if (chdir("/tmp/") != 0)
+	 _exit(100);
+	 
+      unsigned int Count = 1;
+      for (; Opts != 0; Opts = Opts->Next, Count++)
+      {
+	 if (Opts->Value.empty() == true)
+	    continue;
+	 
+	 if (system(Opts->Value.c_str()) != 0)
+	    _exit(100+Count);
+      }
+      _exit(0);
+   }      
+
+   // Wait for the child
+   int Status = 0;
+   while (waitpid(Child,&Status,0) != Child)
+   {
+      if (errno == EINTR)
+	 continue;
+      return _error->Errno("waitpid","Couldn't wait for subprocess");
+   }
+
+   // Restore sig int/quit
+   signal(SIGQUIT,SIG_DFL);
+   signal(SIGINT,SIG_DFL);   
+
+   // Check for an error code.
+   if (WIFEXITED(Status) == 0 || WEXITSTATUS(Status) != 0)
+   {
+      unsigned int Count = WEXITSTATUS(Status);
+      if (Count > 100)
+      {
+	 Count -= 100;
+	 for (; Opts != 0 && Count != 1; Opts = Opts->Next, Count--);
+	 _error->Error("Problem executing scripts %s '%s'",Cnf,Opts->Value.c_str());
+      }
+      
+      return _error->Error("Sub-process returned an error code");
+   }
+   
+   return true;
+}
+									/*}}}*/
+
 // CopyFile - Buffered copy of a file					/*{{{*/
 // ---------------------------------------------------------------------
 /* The caller is expected to set things so that failure causes erasure */

+ 1 - 0
apt-pkg/contrib/fileutl.h

@@ -77,6 +77,7 @@ class FileFd
    virtual ~FileFd();
 };
 
+bool RunScripts(const char *Cnf);
 bool CopyFile(FileFd &From,FileFd &To);
 int GetLock(string File,bool Errors = true);
 bool FileExists(string File);

+ 1 - 62
apt-pkg/deb/dpkgpm.cc

@@ -14,6 +14,7 @@
 #include <apt-pkg/depcache.h>
 #include <apt-pkg/strutl.h>
 #include <apti18n.h>
+#include <apt-pkg/fileutl.h>
 
 #include <unistd.h>
 #include <stdlib.h>
@@ -95,68 +96,6 @@ bool pkgDPkgPM::Remove(PkgIterator Pkg,bool Purge)
    return true;
 }
 									/*}}}*/
-// DPkgPM::RunScripts - Run a set of scripts				/*{{{*/
-// ---------------------------------------------------------------------
-/* This looks for a list of script sto run from the configuration file,
-   each one is run with system from a forked child. */
-bool pkgDPkgPM::RunScripts(const char *Cnf)
-{
-   Configuration::Item const *Opts = _config->Tree(Cnf);
-   if (Opts == 0 || Opts->Child == 0)
-      return true;
-   Opts = Opts->Child;
-
-   // Fork for running the system calls
-   pid_t Child = ExecFork();
-   
-   // This is the child
-   if (Child == 0)
-   {
-      if (chdir("/tmp/") != 0)
-	 _exit(100);
-	 
-      unsigned int Count = 1;
-      for (; Opts != 0; Opts = Opts->Next, Count++)
-      {
-	 if (Opts->Value.empty() == true)
-	    continue;
-	 
-	 if (system(Opts->Value.c_str()) != 0)
-	    _exit(100+Count);
-      }
-      _exit(0);
-   }      
-
-   // Wait for the child
-   int Status = 0;
-   while (waitpid(Child,&Status,0) != Child)
-   {
-      if (errno == EINTR)
-	 continue;
-      return _error->Errno("waitpid","Couldn't wait for subprocess");
-   }
-
-   // Restore sig int/quit
-   signal(SIGQUIT,SIG_DFL);
-   signal(SIGINT,SIG_DFL);   
-
-   // Check for an error code.
-   if (WIFEXITED(Status) == 0 || WEXITSTATUS(Status) != 0)
-   {
-      unsigned int Count = WEXITSTATUS(Status);
-      if (Count > 100)
-      {
-	 Count -= 100;
-	 for (; Opts != 0 && Count != 1; Opts = Opts->Next, Count--);
-	 _error->Error("Problem executing scripts %s '%s'",Cnf,Opts->Value.c_str());
-      }
-      
-      return _error->Error("Sub-process returned an error code");
-   }
-   
-   return true;
-}
-                                                                        /*}}}*/
 // DPkgPM::SendV2Pkgs - Send version 2 package info			/*{{{*/
 // ---------------------------------------------------------------------
 /* This is part of the helper script communication interface, it sends

+ 0 - 1
apt-pkg/deb/dpkgpm.h

@@ -64,7 +64,6 @@ class pkgDPkgPM : public pkgPackageManager
    vector<Item> List;
 
    // Helpers
-   bool RunScripts(const char *Cnf);
    bool RunScriptsWithPkgs(const char *Cnf);
    bool SendV2Pkgs(FILE *F);
 

+ 9 - 48
cmdline/apt-get.cc

@@ -1351,14 +1351,15 @@ bool DoUpdate(CommandLine &CmdL)
 	 return _error->Error(_("Unable to lock the list directory"));
    }
    
-   // Create the download object
+   // Create the progress
    AcqTextStatus Stat(ScreenWidth,_config->FindI("quiet",0));
-   pkgAcquire Fetcher(&Stat);
-
-   
+      
    // Just print out the uris an exit if the --print-uris flag was used
    if (_config->FindB("APT::Get::Print-URIs") == true)
    {
+      // get a fetcher
+      pkgAcquire Fetcher(&Stat);
+
       // Populate it with the source selection and get all Indexes 
       // (GetAll=true)
       if (List.GetIndexes(&Fetcher,true) == false)
@@ -1371,54 +1372,14 @@ bool DoUpdate(CommandLine &CmdL)
       return true;
    }
 
-   // Populate it with the source selection
-   if (List.GetIndexes(&Fetcher) == false)
-	 return false;
-   
-   // Run it
-   if (Fetcher.Run() == pkgAcquire::Failed)
-      return false;
-
-   bool Failed = false;
-   bool TransientNetworkFailure = false;
-   for (pkgAcquire::ItemIterator I = Fetcher.ItemsBegin(); I != Fetcher.ItemsEnd(); I++)
-   {
-      if ((*I)->Status == pkgAcquire::Item::StatDone)
-	 continue;
-
-      (*I)->Finished();
-
-      fprintf(stderr,_("Failed to fetch %s  %s\n"),(*I)->DescURI().c_str(),
-	      (*I)->ErrorText.c_str());
-
-      if ((*I)->Status == pkgAcquire::Item::StatTransientNetworkError) 
-      {
-	 TransientNetworkFailure = true;
-	 continue;
-      }
-
-      Failed = true;
-   }
-   
-   // Clean out any old list files
-   if (!TransientNetworkFailure &&
-       _config->FindB("APT::Get::List-Cleanup",true) == true)
-   {
-      if (Fetcher.Clean(_config->FindDir("Dir::State::lists")) == false ||
-	  Fetcher.Clean(_config->FindDir("Dir::State::lists") + "partial/") == false)
-	 return false;
-   }
-   
-   // Prepare the cache.   
+   // do the work
    CacheFile Cache;
+   bool res = Cache.ListUpdate(Stat, List);
+     
+   // Rebuild the cache.   
    if (Cache.BuildCaches() == false)
       return false;
    
-   if (TransientNetworkFailure == true)
-      _error->Warning(_("Some index files failed to download, they have been ignored, or old ones used instead."));
-   else if (Failed == true)
-      return _error->Error(_("Some index files failed to download, they have been ignored, or old ones used instead."));
-
    return true;
 }
 									/*}}}*/

+ 3 - 0
debian/changelog

@@ -49,6 +49,9 @@ apt (0.7.10) UNRELEASED; urgency=low
       harder
   * debian/control:
     - build against libdb-dev (instead of libdb4.4-dev)
+  * merged the apt--DoListUpdate branch, this provides a common interface
+    for apt-get update like operations for the frontends and also provides
+    hooks to run stuff in APT::Update::{Pre,Post}-Invoke
 
   [ Chris Cheney ]
   * ftparchive/contents.cc:

+ 6 - 0
doc/examples/configure-index

@@ -77,6 +77,12 @@ APT
      NoAct "false";
   };
 
+  Update
+  {
+     Pre-Invoke {"touch /var/lib/apt/pre-update-stamp"; };
+     Post-Invoke {"touch /var/lib/apt/post-update-stamp"; };
+  };
+
   Authentication
   {
      TrustCDROM "false";            // consider the CDROM always trusted