summaryrefslogtreecommitdiff
path: root/apt-pkg
diff options
context:
space:
mode:
authorMichael Vogt <egon@bottom>2008-01-07 21:26:11 +0100
committerMichael Vogt <egon@bottom>2008-01-07 21:26:11 +0100
commit187b88d8d90ee10b2e2e14ba762be2fdd9fce744 (patch)
treefbb090aa431bcd89a7207b20d3b585ff43456d8e /apt-pkg
parent0a626f9e3738d5ff70b81820b3c497a4a50f589c (diff)
parentf0983ff2091df782027a2e344cbd9e3df43c1450 (diff)
* apt-pkg/packagemanager.{cc,h}:
- propergate the Immediate flag to make hitting the "E: Internal Error, Could not perform immediate configuration (2)" 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
Diffstat (limited to 'apt-pkg')
-rw-r--r--apt-pkg/acquire-worker.cc1
-rw-r--r--apt-pkg/algorithms.cc76
-rw-r--r--apt-pkg/algorithms.h3
-rw-r--r--apt-pkg/cachefile.cc3
-rw-r--r--apt-pkg/cachefile.h2
-rw-r--r--apt-pkg/contrib/fileutl.cc67
-rw-r--r--apt-pkg/contrib/fileutl.h1
-rw-r--r--apt-pkg/deb/dpkgpm.cc71
-rw-r--r--apt-pkg/deb/dpkgpm.h1
-rw-r--r--apt-pkg/packagemanager.cc53
-rw-r--r--apt-pkg/packagemanager.h1
11 files changed, 198 insertions, 81 deletions
diff --git a/apt-pkg/acquire-worker.cc b/apt-pkg/acquire-worker.cc
index 739c9e32c..1a754dae9 100644
--- a/apt-pkg/acquire-worker.cc
+++ b/apt-pkg/acquire-worker.cc
@@ -325,6 +325,7 @@ bool pkgAcquire::Worker::RunMessages()
// set some status
if(LookupTag(Message,"FailReason") == "Timeout" ||
LookupTag(Message,"FailReason") == "TmpResolveFailure" ||
+ LookupTag(Message,"FailReason") == "ResolveFailure" ||
LookupTag(Message,"FailReason") == "ConnectionRefused")
Owner->Status = pkgAcquire::Item::StatTransientNetworkError;
diff --git a/apt-pkg/algorithms.cc b/apt-pkg/algorithms.cc
index 158f9c258..6e2b97557 100644
--- a/apt-pkg/algorithms.cc
+++ b/apt-pkg/algorithms.cc
@@ -19,7 +19,7 @@
#include <apt-pkg/configuration.h>
#include <apt-pkg/version.h>
#include <apt-pkg/sptr.h>
-
+#include <apt-pkg/acquire-item.h>
#include <apti18n.h>
#include <sys/types.h>
@@ -1302,3 +1302,77 @@ void pkgPrioSortList(pkgCache &Cache,pkgCache::Version **List)
}
/*}}}*/
+// 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 ListUpdate(pkgAcquireStatus &Stat,
+ pkgSourceList &List,
+ int PulseInterval)
+{
+ pkgAcquire::RunResult res;
+ pkgAcquire Fetcher(&Stat);
+
+ // Populate it with the source selection
+ if (List.GetIndexes(&Fetcher) == false)
+ return false;
+
+ // Run scripts
+ RunScripts("APT::Update::Pre-Invoke");
+
+ // check arguments
+ if(PulseInterval>0)
+ res = Fetcher.Run(PulseInterval);
+ else
+ res = Fetcher.Run();
+
+ if (res == 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();
+
+ _error->Warning(_("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;
+}
+ /*}}}*/
diff --git a/apt-pkg/algorithms.h b/apt-pkg/algorithms.h
index b72874d8e..defaed57d 100644
--- a/apt-pkg/algorithms.h
+++ b/apt-pkg/algorithms.h
@@ -33,6 +33,7 @@
#include <apt-pkg/packagemanager.h>
#include <apt-pkg/depcache.h>
+#include <apt-pkg/acquire.h>
#include <iostream>
@@ -130,5 +131,7 @@ bool pkgAllUpgrade(pkgDepCache &Cache);
bool pkgMinimizeUpgrade(pkgDepCache &Cache);
void pkgPrioSortList(pkgCache &Cache,pkgCache::Version **List);
+
+bool ListUpdate(pkgAcquireStatus &progress, pkgSourceList &List, int PulseInterval=0);
#endif
diff --git a/apt-pkg/cachefile.cc b/apt-pkg/cachefile.cc
index cccad2bf3..1a84aea54 100644
--- a/apt-pkg/cachefile.cc
+++ b/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,7 @@ bool pkgCacheFile::Open(OpProgress &Progress,bool WithLock)
}
/*}}}*/
+
// CacheFile::Close - close the cache files /*{{{*/
// ---------------------------------------------------------------------
/* */
diff --git a/apt-pkg/cachefile.h b/apt-pkg/cachefile.h
index d23841e5e..3b057951c 100644
--- a/apt-pkg/cachefile.h
+++ b/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
diff --git a/apt-pkg/contrib/fileutl.cc b/apt-pkg/contrib/fileutl.cc
index 9e13b4f60..2b7e25080 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 <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 */
diff --git a/apt-pkg/contrib/fileutl.h b/apt-pkg/contrib/fileutl.h
index 48bd95537..73b5ea3be 100644
--- a/apt-pkg/contrib/fileutl.h
+++ b/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);
diff --git a/apt-pkg/deb/dpkgpm.cc b/apt-pkg/deb/dpkgpm.cc
index d796146fa..34e166447 100644
--- a/apt-pkg/deb/dpkgpm.cc
+++ b/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
@@ -342,8 +281,8 @@ bool pkgDPkgPM::RunScriptsWithPkgs(const char *Cnf)
*/
void pkgDPkgPM::DoStdin(int master)
{
- char input_buf[256] = {0,};
- int len = read(0, input_buf, sizeof(input_buf));
+ unsigned char input_buf[256] = {0,};
+ ssize_t len = read(0, input_buf, sizeof(input_buf));
if (len)
write(master, input_buf, len);
else
@@ -357,9 +296,9 @@ void pkgDPkgPM::DoStdin(int master)
*/
void pkgDPkgPM::DoTerminalPty(int master)
{
- char term_buf[1024] = {0,};
+ unsigned char term_buf[1024] = {0,0, };
- int len=read(master, term_buf, sizeof(term_buf));
+ ssize_t len=read(master, term_buf, sizeof(term_buf));
if(len == -1 && errno == EIO)
{
// this happens when the child is about to exit, we
diff --git a/apt-pkg/deb/dpkgpm.h b/apt-pkg/deb/dpkgpm.h
index 81a888f05..ebc7e32bf 100644
--- a/apt-pkg/deb/dpkgpm.h
+++ b/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);
diff --git a/apt-pkg/packagemanager.cc b/apt-pkg/packagemanager.cc
index d6172c6c4..c391a6036 100644
--- a/apt-pkg/packagemanager.cc
+++ b/apt-pkg/packagemanager.cc
@@ -118,6 +118,41 @@ bool pkgPackageManager::FixMissing()
}
/*}}}*/
+// PM::ImmediateAdd - Add the immediate flag recursivly /*{{{*/
+// ---------------------------------------------------------------------
+/* This adds the immediate flag to the pkg and recursively to the
+ dependendies
+ */
+void pkgPackageManager::ImmediateAdd(PkgIterator I, bool UseInstallVer)
+{
+ DepIterator D;
+
+ if(UseInstallVer)
+ {
+ if(Cache[I].InstallVer == 0)
+ return;
+ D = Cache[I].InstVerIter(Cache).DependsList();
+ } else {
+ if (I->CurrentVer == 0)
+ return;
+ D = I.CurrentVer().DependsList();
+ }
+
+ for ( /* nothing */ ; D.end() == false; D++)
+ if (D->Type == pkgCache::Dep::Depends || D->Type == pkgCache::Dep::PreDepends)
+ {
+ if(!List->IsFlag(D.TargetPkg(), pkgOrderList::Immediate))
+ {
+ if(Debug)
+ clog << "ImmediateAdd(): Adding Immediate flag to " << I.Name() << endl;
+ List->Flag(D.TargetPkg(),pkgOrderList::Immediate);
+ ImmediateAdd(D.TargetPkg(), UseInstallVer);
+ }
+ }
+ return;
+}
+ /*}}}*/
+
// PM::CreateOrderList - Create the ordering class /*{{{*/
// ---------------------------------------------------------------------
/* This populates the ordering list with all the packages that are
@@ -144,21 +179,15 @@ bool pkgPackageManager::CreateOrderList()
(I->Flags & pkgCache::Flag::Important) == pkgCache::Flag::Important) &&
NoImmConfigure == false)
{
+ if(Debug)
+ clog << "CreateOrderList(): Adding Immediate flag for " << I.Name() << endl;
List->Flag(I,pkgOrderList::Immediate);
-
- // Look for other packages to make immediate configurea
- if (Cache[I].InstallVer != 0)
- for (DepIterator D = Cache[I].InstVerIter(Cache).DependsList();
- D.end() == false; D++)
- if (D->Type == pkgCache::Dep::Depends || D->Type == pkgCache::Dep::PreDepends)
- List->Flag(D.TargetPkg(),pkgOrderList::Immediate);
+
+ // Look for other install packages to make immediate configurea
+ ImmediateAdd(I, true);
// And again with the current version.
- if (I->CurrentVer != 0)
- for (DepIterator D = I.CurrentVer().DependsList();
- D.end() == false; D++)
- if (D->Type == pkgCache::Dep::Depends || D->Type == pkgCache::Dep::PreDepends)
- List->Flag(D.TargetPkg(),pkgOrderList::Immediate);
+ ImmediateAdd(I, false);
}
// Not interesting
diff --git a/apt-pkg/packagemanager.h b/apt-pkg/packagemanager.h
index 53cd4c96f..a1bfdc52d 100644
--- a/apt-pkg/packagemanager.h
+++ b/apt-pkg/packagemanager.h
@@ -49,6 +49,7 @@ class pkgPackageManager : protected pkgCache::Namespace
bool Debug;
bool DepAdd(pkgOrderList &Order,PkgIterator P,int Depth = 0);
+ void ImmediateAdd(PkgIterator P, bool UseInstallVer);
virtual OrderResult OrderInstall();
bool CheckRConflicts(PkgIterator Pkg,DepIterator Dep,const char *Ver);
bool CreateOrderList();