summaryrefslogtreecommitdiff
path: root/apt-pkg/contrib/mmap.cc
diff options
context:
space:
mode:
authorDavid Kalnischkies <david@kalnischkies.de>2015-09-10 19:00:51 +0200
committerDavid Kalnischkies <david@kalnischkies.de>2015-09-14 15:22:18 +0200
commit95278287f4e1eeaf5d96749d6fc9bfc53fb400d0 (patch)
tree90cc504d25c680b2fc3fe77994573e517263275f /apt-pkg/contrib/mmap.cc
parent7f58427b9584686f80cd5eccfdd02c1ace75518a (diff)
avoid using global PendingError to avoid failing too often too soon
Our error reporting is historically grown into some kind of mess. A while ago I implemented stacking for the global error which is used in this commit now to wrap calls to functions which do not report (all) errors via return, so that only failures in those calls cause a failure to propergate down the chain rather than failing if anything (potentially totally unrelated) has failed at some point in the past. This way we can avoid stopping the entire acquire process just because a single source produced an error for example. It also means that after the acquire process the cache is generated – even if the acquire process had failures – as we still have the old good data around we can and should generate a cache for (again). There are probably more instances of this hiding, but all these looked like the easiest to work with and fix with reasonable (aka net-positive) effects.
Diffstat (limited to 'apt-pkg/contrib/mmap.cc')
-rw-r--r--apt-pkg/contrib/mmap.cc16
1 files changed, 8 insertions, 8 deletions
diff --git a/apt-pkg/contrib/mmap.cc b/apt-pkg/contrib/mmap.cc
index b2a53a6cb..8e169027e 100644
--- a/apt-pkg/contrib/mmap.cc
+++ b/apt-pkg/contrib/mmap.cc
@@ -215,9 +215,6 @@ DynamicMMap::DynamicMMap(FileFd &F,unsigned long Flags,unsigned long const &Work
MMap(F,Flags | NoImmMap), Fd(&F), WorkSpace(Workspace),
GrowFactor(Grow), Limit(Limit)
{
- if (_error->PendingError() == true)
- return;
-
// disable Moveable if we don't grow
if (Grow == 0)
this->Flags &= ~Moveable;
@@ -252,9 +249,6 @@ DynamicMMap::DynamicMMap(unsigned long Flags,unsigned long const &WorkSpace,
MMap(Flags | NoImmMap | UnMapped), Fd(0), WorkSpace(WorkSpace),
GrowFactor(Grow), Limit(Limit)
{
- if (_error->PendingError() == true)
- return;
-
// disable Moveable if we don't grow
if (Grow == 0)
this->Flags &= ~Moveable;
@@ -390,12 +384,15 @@ unsigned long DynamicMMap::Allocate(unsigned long ItemSize)
const unsigned long size = 20*1024;
I->Count = size/ItemSize;
Pool* oldPools = Pools;
+ _error->PushToStack();
Result = RawAllocate(size,ItemSize);
+ bool const newError = _error->PendingError();
+ _error->MergeWithStack();
if (Pools != oldPools)
I += Pools - oldPools;
// Does the allocation failed ?
- if (Result == 0 && _error->PendingError())
+ if (Result == 0 && newError)
return 0;
I->Start = Result;
}
@@ -416,9 +413,12 @@ unsigned long DynamicMMap::WriteString(const char *String,
if (Len == (unsigned long)-1)
Len = strlen(String);
+ _error->PushToStack();
unsigned long const Result = RawAllocate(Len+1,0);
+ bool const newError = _error->PendingError();
+ _error->MergeWithStack();
- if (Base == NULL || (Result == 0 && _error->PendingError()))
+ if (Base == NULL || (Result == 0 && newError))
return 0;
memcpy((char *)Base + Result,String,Len);