summaryrefslogtreecommitdiff
path: root/apt-pkg/contrib
diff options
context:
space:
mode:
Diffstat (limited to 'apt-pkg/contrib')
-rw-r--r--apt-pkg/contrib/error.cc164
-rw-r--r--apt-pkg/contrib/error.h5
-rw-r--r--apt-pkg/contrib/fileutl.cc48
-rw-r--r--apt-pkg/contrib/fileutl.h2
-rw-r--r--apt-pkg/contrib/mmap.cc4
-rw-r--r--apt-pkg/contrib/mmap.h2
-rw-r--r--apt-pkg/contrib/progress.cc2
-rw-r--r--apt-pkg/contrib/strutl.cc26
-rw-r--r--apt-pkg/contrib/strutl.h2
-rw-r--r--apt-pkg/contrib/weakptr.h2
10 files changed, 160 insertions, 97 deletions
diff --git a/apt-pkg/contrib/error.cc b/apt-pkg/contrib/error.cc
index e2e8d6e57..fe50e606b 100644
--- a/apt-pkg/contrib/error.cc
+++ b/apt-pkg/contrib/error.cc
@@ -18,6 +18,7 @@
#include <iostream>
#include <errno.h>
#include <stdio.h>
+#include <stdlib.h>
#include <unistd.h>
#include <string>
@@ -57,108 +58,110 @@
// GlobalError::GlobalError - Constructor /*{{{*/
GlobalError::GlobalError() : PendingFlag(false) {}
/*}}}*/
-// GlobalError::FatalE - Get part of the error string from errno /*{{{*/
-bool GlobalError::FatalE(const char *Function,const char *Description,...) {
- va_list args;
- va_start(args,Description);
- return InsertErrno(FATAL, Function, Description, args);
-}
- /*}}}*/
-// GlobalError::Errno - Get part of the error string from errno /*{{{*/
-bool GlobalError::Errno(const char *Function,const char *Description,...) {
- va_list args;
- va_start(args,Description);
- return InsertErrno(ERROR, Function, Description, args);
-}
- /*}}}*/
-// GlobalError::WarningE - Get part of the warning string from errno /*{{{*/
-bool GlobalError::WarningE(const char *Function,const char *Description,...) {
- va_list args;
- va_start(args,Description);
- return InsertErrno(WARNING, Function, Description, args);
-}
- /*}}}*/
-// GlobalError::NoticeE - Get part of the notice string from errno /*{{{*/
-bool GlobalError::NoticeE(const char *Function,const char *Description,...) {
- va_list args;
- va_start(args,Description);
- return InsertErrno(NOTICE, Function, Description, args);
-}
- /*}}}*/
-// GlobalError::DebugE - Get part of the debug string from errno /*{{{*/
-bool GlobalError::DebugE(const char *Function,const char *Description,...) {
- va_list args;
- va_start(args,Description);
- return InsertErrno(DEBUG, Function, Description, args);
+// GlobalError::FatalE, Errno, WarningE, NoticeE and DebugE - Add to the list/*{{{*/
+#define GEMessage(NAME, TYPE) \
+bool GlobalError::NAME (const char *Function, const char *Description,...) { \
+ va_list args; \
+ size_t msgSize = 400; \
+ int const errsv = errno; \
+ while (true) { \
+ va_start(args,Description); \
+ if (InsertErrno(TYPE, Function, Description, args, errsv, msgSize) == false) \
+ break; \
+ va_end(args); \
+ } \
+ return false; \
}
+GEMessage(FatalE, FATAL)
+GEMessage(Errno, ERROR)
+GEMessage(WarningE, WARNING)
+GEMessage(NoticeE, NOTICE)
+GEMessage(DebugE, DEBUG)
+#undef GEMessage
/*}}}*/
// GlobalError::InsertErrno - Get part of the errortype string from errno/*{{{*/
bool GlobalError::InsertErrno(MsgType const &type, const char *Function,
const char *Description,...) {
va_list args;
- va_start(args,Description);
- return InsertErrno(type, Function, Description, args);
+ size_t msgSize = 400;
+ int const errsv = errno;
+ while (true) {
+ va_start(args,Description);
+ if (InsertErrno(type, Function, Description, args, errsv, msgSize) == false)
+ break;
+ va_end(args);
+ }
+ return false;
}
/*}}}*/
// GlobalError::InsertErrno - formats an error message with the errno /*{{{*/
bool GlobalError::InsertErrno(MsgType type, const char* Function,
- const char* Description, va_list &args) {
- char S[400];
- snprintf(S, sizeof(S), "%s - %s (%i: %s)", Description,
- Function, errno, strerror(errno));
- return Insert(type, S, args);
-}
- /*}}}*/
-// GlobalError::Fatal - Add a fatal error to the list /*{{{*/
-bool GlobalError::Fatal(const char *Description,...) {
- va_list args;
- va_start(args,Description);
- return Insert(FATAL, Description, args);
-}
- /*}}}*/
-// GlobalError::Error - Add an error to the list /*{{{*/
-bool GlobalError::Error(const char *Description,...) {
- va_list args;
- va_start(args,Description);
- return Insert(ERROR, Description, args);
-}
- /*}}}*/
-// GlobalError::Warning - Add a warning to the list /*{{{*/
-bool GlobalError::Warning(const char *Description,...) {
- va_list args;
- va_start(args,Description);
- return Insert(WARNING, Description, args);
-}
- /*}}}*/
-// GlobalError::Notice - Add a notice to the list /*{{{*/
-bool GlobalError::Notice(const char *Description,...)
-{
- va_list args;
- va_start(args,Description);
- return Insert(NOTICE, Description, args);
+ const char* Description, va_list &args,
+ int const errsv, size_t &msgSize) {
+ char* S = (char*) malloc(msgSize);
+ int const n = snprintf(S, msgSize, "%s - %s (%i: %s)", Description,
+ Function, errsv, strerror(errsv));
+ if (n > -1 && ((unsigned int) n) < msgSize);
+ else {
+ if (n > -1)
+ msgSize = n + 1;
+ else
+ msgSize *= 2;
+ return true;
+ }
+
+ bool const geins = Insert(type, S, args, msgSize);
+ free(S);
+ return geins;
}
/*}}}*/
-// GlobalError::Debug - Add a debug to the list /*{{{*/
-bool GlobalError::Debug(const char *Description,...)
-{
- va_list args;
- va_start(args,Description);
- return Insert(DEBUG, Description, args);
+// GlobalError::Fatal, Error, Warning, Notice and Debug - Add to the list/*{{{*/
+#define GEMessage(NAME, TYPE) \
+bool GlobalError::NAME (const char *Description,...) { \
+ va_list args; \
+ size_t msgSize = 400; \
+ while (true) { \
+ va_start(args,Description); \
+ if (Insert(TYPE, Description, args, msgSize) == false) \
+ break; \
+ va_end(args); \
+ } \
+ return false; \
}
+GEMessage(Fatal, FATAL)
+GEMessage(Error, ERROR)
+GEMessage(Warning, WARNING)
+GEMessage(Notice, NOTICE)
+GEMessage(Debug, DEBUG)
+#undef GEMessage
/*}}}*/
// GlobalError::Insert - Add a errotype message to the list /*{{{*/
bool GlobalError::Insert(MsgType const &type, const char *Description,...)
{
va_list args;
- va_start(args,Description);
- return Insert(type, Description, args);
+ size_t msgSize = 400;
+ while (true) {
+ va_start(args,Description);
+ if (Insert(type, Description, args, msgSize) == false)
+ break;
+ va_end(args);
+ }
+ return false;
}
/*}}}*/
// GlobalError::Insert - Insert a new item at the end /*{{{*/
bool GlobalError::Insert(MsgType type, const char* Description,
- va_list &args) {
- char S[400];
- vsnprintf(S,sizeof(S),Description,args);
+ va_list &args, size_t &msgSize) {
+ char* S = (char*) malloc(msgSize);
+ int const n = vsnprintf(S, msgSize, Description, args);
+ if (n > -1 && ((unsigned int) n) < msgSize);
+ else {
+ if (n > -1)
+ msgSize = n + 1;
+ else
+ msgSize *= 2;
+ return true;
+ }
Item const m(S, type);
Messages.push_back(m);
@@ -169,6 +172,7 @@ bool GlobalError::Insert(MsgType type, const char* Description,
if (type == FATAL || type == DEBUG)
std::clog << m << std::endl;
+ free(S);
return false;
}
/*}}}*/
diff --git a/apt-pkg/contrib/error.h b/apt-pkg/contrib/error.h
index ae756dbc4..21c51c1be 100644
--- a/apt-pkg/contrib/error.h
+++ b/apt-pkg/contrib/error.h
@@ -307,9 +307,10 @@ private: /*{{{*/
std::list<MsgStack> Stacks;
bool InsertErrno(MsgType type, const char* Function,
- const char* Description, va_list &args);
+ const char* Description, va_list &args,
+ int const errsv, size_t &msgSize);
bool Insert(MsgType type, const char* Description,
- va_list &args);
+ va_list &args, size_t &msgSize);
/*}}}*/
};
/*}}}*/
diff --git a/apt-pkg/contrib/fileutl.cc b/apt-pkg/contrib/fileutl.cc
index 266d480a4..767951daf 100644
--- a/apt-pkg/contrib/fileutl.cc
+++ b/apt-pkg/contrib/fileutl.cc
@@ -196,7 +196,7 @@ int GetLock(string File,bool Errors)
/*}}}*/
// FileExists - Check if a file exists /*{{{*/
// ---------------------------------------------------------------------
-/* */
+/* Beware: Directories are also files! */
bool FileExists(string File)
{
struct stat Buf;
@@ -205,6 +205,17 @@ bool FileExists(string File)
return true;
}
/*}}}*/
+// RealFileExists - Check if a file exists and if it is really a file /*{{{*/
+// ---------------------------------------------------------------------
+/* */
+bool RealFileExists(string File)
+{
+ struct stat Buf;
+ if (stat(File.c_str(),&Buf) != 0)
+ return false;
+ return ((Buf.st_mode & S_IFREG) != 0);
+}
+ /*}}}*/
// DirectoryExists - Check if a directory exists and is really one /*{{{*/
// ---------------------------------------------------------------------
/* */
@@ -309,6 +320,13 @@ std::vector<string> GetListOfFilesInDir(string const &Dir, std::vector<string> c
}
std::vector<string> List;
+
+ if (DirectoryExists(Dir.c_str()) == false)
+ {
+ _error->Error(_("List of files can't be created as '%s' is not a directory"), Dir.c_str());
+ return List;
+ }
+
Configuration::MatchAgainstConfig SilentIgnore("Dir::Ignore-Files-Silently");
DIR *D = opendir(Dir.c_str());
if (D == 0)
@@ -323,6 +341,20 @@ std::vector<string> GetListOfFilesInDir(string const &Dir, std::vector<string> c
if (Ent->d_name[0] == '.')
continue;
+ // Make sure it is a file and not something else
+ string const File = flCombine(Dir,Ent->d_name);
+#ifdef _DIRENT_HAVE_D_TYPE
+ if (Ent->d_type != DT_REG)
+#endif
+ {
+ if (RealFileExists(File.c_str()) == false)
+ {
+ if (SilentIgnore.Match(Ent->d_name) == false)
+ _error->Notice(_("Ignoring '%s' in directory '%s' as it is not a regular file"), Ent->d_name, Dir.c_str());
+ continue;
+ }
+ }
+
// check for accepted extension:
// no extension given -> periods are bad as hell!
// extensions given -> "" extension allows no extension
@@ -336,7 +368,7 @@ std::vector<string> GetListOfFilesInDir(string const &Dir, std::vector<string> c
if (Debug == true)
std::clog << "Bad file: " << Ent->d_name << " → no extension" << std::endl;
if (SilentIgnore.Match(Ent->d_name) == false)
- _error->Notice("Ignoring file '%s' in directory '%s' as it has no filename extension", Ent->d_name, Dir.c_str());
+ _error->Notice(_("Ignoring file '%s' in directory '%s' as it has no filename extension"), Ent->d_name, Dir.c_str());
continue;
}
}
@@ -345,7 +377,7 @@ std::vector<string> GetListOfFilesInDir(string const &Dir, std::vector<string> c
if (Debug == true)
std::clog << "Bad file: " << Ent->d_name << " → bad extension »" << flExtension(Ent->d_name) << "«" << std::endl;
if (SilentIgnore.Match(Ent->d_name) == false)
- _error->Notice("Ignoring file '%s' in directory '%s' as it has an invalid filename extension", Ent->d_name, Dir.c_str());
+ _error->Notice(_("Ignoring file '%s' in directory '%s' as it has an invalid filename extension"), Ent->d_name, Dir.c_str());
continue;
}
}
@@ -378,16 +410,6 @@ std::vector<string> GetListOfFilesInDir(string const &Dir, std::vector<string> c
continue;
}
- // Make sure it is a file and not something else
- string const File = flCombine(Dir,Ent->d_name);
- struct stat St;
- if (stat(File.c_str(),&St) != 0 || S_ISREG(St.st_mode) == 0)
- {
- if (Debug == true)
- std::clog << "Bad file: " << Ent->d_name << " → stat says not a good file" << std::endl;
- continue;
- }
-
if (Debug == true)
std::clog << "Accept file: " << Ent->d_name << " in " << Dir << std::endl;
List.push_back(File);
diff --git a/apt-pkg/contrib/fileutl.h b/apt-pkg/contrib/fileutl.h
index 1380f06b4..cde288ad2 100644
--- a/apt-pkg/contrib/fileutl.h
+++ b/apt-pkg/contrib/fileutl.h
@@ -72,6 +72,7 @@ class FileFd
// Simple manipulators
inline int Fd() {return iFd;};
inline void Fd(int fd) {iFd = fd;};
+ inline gzFile gzFd() {return gz;};
inline bool IsOpen() {return iFd >= 0;};
inline bool Failed() {return (Flags & Fail) == Fail;};
inline void EraseOnFailure() {Flags |= DelOnFail;};
@@ -93,6 +94,7 @@ bool RunScripts(const char *Cnf);
bool CopyFile(FileFd &From,FileFd &To);
int GetLock(string File,bool Errors = true);
bool FileExists(string File);
+bool RealFileExists(string File);
bool DirectoryExists(string const &Path) __attrib_const;
bool CreateDirectory(string const &Parent, string const &Path);
diff --git a/apt-pkg/contrib/mmap.cc b/apt-pkg/contrib/mmap.cc
index 69fb61fca..9945b1606 100644
--- a/apt-pkg/contrib/mmap.cc
+++ b/apt-pkg/contrib/mmap.cc
@@ -106,7 +106,7 @@ bool MMap::Map(FileFd &Fd)
/* */
bool MMap::Close(bool DoSync)
{
- if ((Flags & UnMapped) == UnMapped || Base == 0 || iSize == 0)
+ if ((Flags & UnMapped) == UnMapped || validData() == false || iSize == 0)
return true;
if (DoSync == true)
@@ -266,6 +266,8 @@ DynamicMMap::~DynamicMMap()
{
if (Fd == 0)
{
+ if (validData() == false)
+ return;
#ifdef _POSIX_MAPPED_FILES
munmap(Base, WorkSpace);
#else
diff --git a/apt-pkg/contrib/mmap.h b/apt-pkg/contrib/mmap.h
index 5ca951204..2bf2c1540 100644
--- a/apt-pkg/contrib/mmap.h
+++ b/apt-pkg/contrib/mmap.h
@@ -61,6 +61,8 @@ class MMap
inline operator void *() {return Base;};
inline void *Data() {return Base;};
inline unsigned long Size() {return iSize;};
+ inline void AddSize(unsigned long const size) {iSize += size;};
+ inline bool validData() const { return Base != (void *)-1 && Base != 0; };
// File manipulators
bool Sync();
diff --git a/apt-pkg/contrib/progress.cc b/apt-pkg/contrib/progress.cc
index cffdddc4f..45e81edcb 100644
--- a/apt-pkg/contrib/progress.cc
+++ b/apt-pkg/contrib/progress.cc
@@ -135,7 +135,7 @@ bool OpProgress::CheckChange(float Interval)
OpTextProgress::OpTextProgress(Configuration &Config) :
NoUpdate(false), NoDisplay(false), LastLen(0)
{
- if (Config.FindI("quiet",0) >= 1)
+ if (Config.FindI("quiet",0) >= 1 || Config.FindB("quiet::NoUpdate", false) == true)
NoUpdate = true;
if (Config.FindI("quiet",0) >= 2)
NoDisplay = true;
diff --git a/apt-pkg/contrib/strutl.cc b/apt-pkg/contrib/strutl.cc
index 987f4c3a4..2e2bb5ebc 100644
--- a/apt-pkg/contrib/strutl.cc
+++ b/apt-pkg/contrib/strutl.cc
@@ -968,6 +968,23 @@ bool StrToNum(const char *Str,unsigned long &Res,unsigned Len,unsigned Base)
return true;
}
/*}}}*/
+// Base256ToNum - Convert a fixed length binary to a number /*{{{*/
+// ---------------------------------------------------------------------
+/* This is used in decoding the 256bit encoded fixed length fields in
+ tar files */
+bool Base256ToNum(const char *Str,unsigned long &Res,unsigned int Len)
+{
+ if ((Str[0] & 0x80) == 0)
+ return false;
+ else
+ {
+ Res = Str[0] & 0x7F;
+ for(unsigned int i = 1; i < Len; ++i)
+ Res = (Res<<8) + Str[i];
+ return true;
+ }
+}
+ /*}}}*/
// HexDigit - Convert a hex character into an integer /*{{{*/
// ---------------------------------------------------------------------
/* Helper for Hex2Num */
@@ -1174,6 +1191,15 @@ char *safe_snprintf(char *Buffer,char *End,const char *Format,...)
return Buffer + Did;
}
/*}}}*/
+// StripEpoch - Remove the version "epoch" from a version string /*{{{*/
+// ---------------------------------------------------------------------
+string StripEpoch(const string &VerStr)
+{
+ size_t i = VerStr.find(":");
+ if (i == string::npos)
+ return VerStr;
+ return VerStr.substr(i+1);
+}
// tolower_ascii - tolower() function that ignores the locale /*{{{*/
// ---------------------------------------------------------------------
diff --git a/apt-pkg/contrib/strutl.h b/apt-pkg/contrib/strutl.h
index a457ff047..89cbf0370 100644
--- a/apt-pkg/contrib/strutl.h
+++ b/apt-pkg/contrib/strutl.h
@@ -52,6 +52,7 @@ string LookupTag(const string &Message,const char *Tag,const char *Default = 0);
int StringToBool(const string &Text,int Default = -1);
bool ReadMessages(int Fd, vector<string> &List);
bool StrToNum(const char *Str,unsigned long &Res,unsigned Len,unsigned Base = 0);
+bool Base256ToNum(const char *Str,unsigned long &Res,unsigned int Len);
bool Hex2Num(const string &Str,unsigned char *Num,unsigned int Length);
bool TokSplitString(char Tok,char *Input,char **List,
unsigned long ListMax);
@@ -61,6 +62,7 @@ void strprintf(string &out,const char *format,...) __like_printf(2);
char *safe_snprintf(char *Buffer,char *End,const char *Format,...) __like_printf(3);
bool CheckDomainList(const string &Host, const string &List);
int tolower_ascii(int const c) __attrib_const __hot;
+string StripEpoch(const string &VerStr);
#define APT_MKSTRCMP(name,func) \
inline int name(const char *A,const char *B) {return func(A,A+strlen(A),B,B+strlen(B));}; \
diff --git a/apt-pkg/contrib/weakptr.h b/apt-pkg/contrib/weakptr.h
index 5158e393c..8de727d89 100644
--- a/apt-pkg/contrib/weakptr.h
+++ b/apt-pkg/contrib/weakptr.h
@@ -22,6 +22,8 @@
#define WEAK_POINTER_H
#include <set>
+#include <stddef.h>
+
/**
* Class for objects providing support for weak pointers.
*