From 89b70b5a5c80b15d928b6593604bacc02a1b9a51 Mon Sep 17 00:00:00 2001 From: Michael Vogt Date: Wed, 7 Jun 2006 09:52:46 +0200 Subject: * apt-pkg/cachefile, cmdline/apt-get.cc: - move the code that does the work from apt-get.cc to pkgCacheFile::ListUpdate() --- apt-pkg/cachefile.cc | 46 ++++++++++++++++++++++++++++++++++++++++++++++ apt-pkg/cachefile.h | 3 +++ 2 files changed, 49 insertions(+) (limited to 'apt-pkg') diff --git a/apt-pkg/cachefile.cc b/apt-pkg/cachefile.cc index ab3003092..96d9672c2 100644 --- a/apt-pkg/cachefile.cc +++ b/apt-pkg/cachefile.cc @@ -23,6 +23,7 @@ #include #include #include +#include #include /*}}}*/ @@ -111,6 +112,51 @@ bool pkgCacheFile::Open(OpProgress &Progress,bool WithLock) } /*}}}*/ +// CacheFile::ListUpdate - update the cache files /*{{{*/ +// --------------------------------------------------------------------- +/* */ +bool pkgCacheFile::ListUpdate(pkgAcquireStatus &Stat, pkgSourceList &List) +{ + pkgAcquire Fetcher(&Stat); + + // 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; + for (pkgAcquire::ItemIterator I = Fetcher.ItemsBegin(); I != Fetcher.ItemsEnd(); I++) + { + if ((*I)->Status == pkgAcquire::Item::StatDone) + continue; + + (*I)->Finished(); + + _error->Warning(_("Failed to fetch %s %s\n"), + (*I)->DescURI().c_str(), + (*I)->ErrorText.c_str()); + Failed = true; + } + + // Clean out any old list files (if it was not a failure) + // Keep "APT::Get::List-Cleanup" name for compatibility, but + // this is really a global option for the APT library now + if (!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) + return false; + } + + + return (Failed == false); +} + /*}}}*/ + // CacheFile::Close - close the cache files /*{{{*/ // --------------------------------------------------------------------- /* */ diff --git a/apt-pkg/cachefile.h b/apt-pkg/cachefile.h index a128c29ab..366e3576f 100644 --- a/apt-pkg/cachefile.h +++ b/apt-pkg/cachefile.h @@ -22,6 +22,8 @@ #endif #include +#include +#include class pkgPolicy; class pkgCacheFile @@ -48,6 +50,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(); -- cgit v1.2.3 From 614adaa09f9f24dccd9e2e8bb4eb00d17285c92e Mon Sep 17 00:00:00 2001 From: Michael Vogt Date: Wed, 7 Jun 2006 10:03:41 +0200 Subject: * apt-pkg/deb/dpkgpm.cc, apt-pkg/contrib/fileutl.{cc,h}: - move the RunScripts() code into fileutl.{cc,h} * apt-pkg/cachefile.cc: - add support for "APT::Update::{Pre,Post}-Invoke" scripts --- apt-pkg/cachefile.cc | 6 +++++ apt-pkg/contrib/fileutl.cc | 67 +++++++++++++++++++++++++++++++++++++++++++++- apt-pkg/contrib/fileutl.h | 1 + apt-pkg/deb/dpkgpm.cc | 56 ++------------------------------------ 4 files changed, 75 insertions(+), 55 deletions(-) (limited to 'apt-pkg') diff --git a/apt-pkg/cachefile.cc b/apt-pkg/cachefile.cc index 96d9672c2..8b8e6dc98 100644 --- a/apt-pkg/cachefile.cc +++ b/apt-pkg/cachefile.cc @@ -24,6 +24,7 @@ #include #include #include +#include #include /*}}}*/ @@ -123,6 +124,9 @@ bool pkgCacheFile::ListUpdate(pkgAcquireStatus &Stat, pkgSourceList &List) if (List.GetIndexes(&Fetcher) == false) return false; + // Run scripts + RunScripts("APT::Update::Pre-Invoke"); + // Run it if (Fetcher.Run() == pkgAcquire::Failed) return false; @@ -152,6 +156,8 @@ bool pkgCacheFile::ListUpdate(pkgAcquireStatus &Stat, pkgSourceList &List) return false; } + // Run the scripts + RunScripts("APT::Update::Post-Invoke"); return (Failed == false); } diff --git a/apt-pkg/contrib/fileutl.cc b/apt-pkg/contrib/fileutl.cc index 9fd71728e..77287952a 100644 --- a/apt-pkg/contrib/fileutl.cc +++ b/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 . + 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 */ diff --git a/apt-pkg/contrib/fileutl.h b/apt-pkg/contrib/fileutl.h index 041aa3309..363dd041d 100644 --- a/apt-pkg/contrib/fileutl.h +++ b/apt-pkg/contrib/fileutl.h @@ -80,6 +80,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); diff --git a/apt-pkg/deb/dpkgpm.cc b/apt-pkg/deb/dpkgpm.cc index 667db8ff2..fe13614c5 100644 --- a/apt-pkg/deb/dpkgpm.cc +++ b/apt-pkg/deb/dpkgpm.cc @@ -16,6 +16,7 @@ #include #include #include +#include #include #include @@ -93,60 +94,7 @@ bool pkgDPkgPM::Remove(PkgIterator Pkg,bool Purge) 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; + RunScripts(Cnf); } /*}}}*/ // DPkgPM::SendV2Pkgs - Send version 2 package info /*{{{*/ -- cgit v1.2.3 From f8477782df203e1998a8704e71a1a3cc699e9e3a Mon Sep 17 00:00:00 2001 From: Michael Vogt Date: Wed, 7 Jun 2006 10:06:45 +0200 Subject: * doc/examples/configure-index: - document the new features * apt-pkg/init.h, apt-pkg/makefile, methods/makefile: - we break the ABI, record this --- apt-pkg/init.h | 2 +- apt-pkg/makefile | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) (limited to 'apt-pkg') diff --git a/apt-pkg/init.h b/apt-pkg/init.h index 8255b406a..b584b2cce 100644 --- a/apt-pkg/init.h +++ b/apt-pkg/init.h @@ -18,7 +18,7 @@ // See the makefile #define APT_PKG_MAJOR 3 -#define APT_PKG_MINOR 11 +#define APT_PKG_MINOR 12 #define APT_PKG_RELEASE 0 extern const char *pkgVersion; diff --git a/apt-pkg/makefile b/apt-pkg/makefile index 0e6aecc65..ab0ff8005 100644 --- a/apt-pkg/makefile +++ b/apt-pkg/makefile @@ -13,7 +13,7 @@ include ../buildlib/defaults.mak # methods/makefile - FIXME LIBRARY=apt-pkg LIBEXT=$(GLIBC_VER)$(LIBSTDCPP_VER) -MAJOR=3.11 +MAJOR=3.12 MINOR=0 SLIBS=$(PTHREADLIB) $(INTLLIBS) APT_DOMAIN:=libapt-pkg$(MAJOR) -- cgit v1.2.3