summaryrefslogtreecommitdiff
path: root/apt-pkg/contrib
diff options
context:
space:
mode:
Diffstat (limited to 'apt-pkg/contrib')
-rw-r--r--apt-pkg/contrib/error.cc28
-rw-r--r--apt-pkg/contrib/error.h2
-rw-r--r--apt-pkg/contrib/fileutl.cc2
-rw-r--r--apt-pkg/contrib/mmap.cc16
4 files changed, 23 insertions, 25 deletions
diff --git a/apt-pkg/contrib/error.cc b/apt-pkg/contrib/error.cc
index 892cd4874..8a87e16e9 100644
--- a/apt-pkg/contrib/error.cc
+++ b/apt-pkg/contrib/error.cc
@@ -27,6 +27,7 @@
#include <unistd.h>
#include <string>
#include <cstring>
+#include <algorithm>
/*}}}*/
@@ -212,12 +213,13 @@ void GlobalError::DumpErrors(std::ostream &out, MsgType const &threshold,
if (mergeStack == true)
for (std::list<MsgStack>::const_reverse_iterator s = Stacks.rbegin();
s != Stacks.rend(); ++s)
- Messages.insert(Messages.begin(), s->Messages.begin(), s->Messages.end());
+ std::copy(s->Messages.begin(), s->Messages.end(), std::front_inserter(Messages));
+
+ std::for_each(Messages.begin(), Messages.end(), [&threshold, &out](Item const &m) {
+ if (m.Type >= threshold)
+ out << m << std::endl;
+ });
- for (std::list<Item>::const_iterator m = Messages.begin();
- m != Messages.end(); ++m)
- if (m->Type >= threshold)
- out << (*m) << std::endl;
Discard();
}
/*}}}*/
@@ -228,25 +230,21 @@ void GlobalError::Discard() {
}
/*}}}*/
// GlobalError::empty - does our error list include anything? /*{{{*/
-bool GlobalError::empty(MsgType const &trashhold) const {
+bool GlobalError::empty(MsgType const &threshold) const {
if (PendingFlag == true)
return false;
if (Messages.empty() == true)
return true;
- for (std::list<Item>::const_iterator m = Messages.begin();
- m != Messages.end(); ++m)
- if (m->Type >= trashhold)
- return false;
-
- return true;
+ return std::find_if(Messages.begin(), Messages.end(), [&threshold](Item const &m) {
+ return m.Type >= threshold;
+ }) == Messages.end();
}
/*}}}*/
// GlobalError::PushToStack /*{{{*/
void GlobalError::PushToStack() {
- MsgStack pack(Messages, PendingFlag);
- Stacks.push_back(pack);
+ Stacks.emplace_back(Messages, PendingFlag);
Discard();
}
/*}}}*/
@@ -262,7 +260,7 @@ void GlobalError::RevertToStack() {
// GlobalError::MergeWithStack /*{{{*/
void GlobalError::MergeWithStack() {
MsgStack pack = Stacks.back();
- Messages.insert(Messages.begin(), pack.Messages.begin(), pack.Messages.end());
+ Messages.splice(Messages.begin(), pack.Messages);
PendingFlag = PendingFlag || pack.PendingFlag;
Stacks.pop_back();
}
diff --git a/apt-pkg/contrib/error.h b/apt-pkg/contrib/error.h
index ed8c19153..1fb0ede4a 100644
--- a/apt-pkg/contrib/error.h
+++ b/apt-pkg/contrib/error.h
@@ -333,7 +333,7 @@ private: /*{{{*/
bool PendingFlag;
struct MsgStack {
- std::list<Item> const Messages;
+ std::list<Item> Messages;
bool const PendingFlag;
MsgStack(std::list<Item> const &Messages, bool const &Pending) :
diff --git a/apt-pkg/contrib/fileutl.cc b/apt-pkg/contrib/fileutl.cc
index 52fedce8f..02b27f5cf 100644
--- a/apt-pkg/contrib/fileutl.cc
+++ b/apt-pkg/contrib/fileutl.cc
@@ -665,7 +665,7 @@ string flAbsPath(string File)
char *p = realpath(File.c_str(), NULL);
if (p == NULL)
{
- _error->Errno("realpath", "flAbsPath failed");
+ _error->Errno("realpath", "flAbsPath on %s failed", File.c_str());
return "";
}
std::string AbsPath(p);
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);