summaryrefslogtreecommitdiff
path: root/apt-pkg/contrib
diff options
context:
space:
mode:
Diffstat (limited to 'apt-pkg/contrib')
-rw-r--r--apt-pkg/contrib/cdromutl.cc13
-rw-r--r--apt-pkg/contrib/cdromutl.h3
-rw-r--r--apt-pkg/contrib/configuration.cc7
-rw-r--r--apt-pkg/contrib/error.cc13
-rw-r--r--apt-pkg/contrib/hashes.cc24
-rw-r--r--apt-pkg/contrib/md5.cc13
-rw-r--r--apt-pkg/contrib/mmap.cc120
-rw-r--r--apt-pkg/contrib/mmap.h2
-rw-r--r--apt-pkg/contrib/sha256.cc32
-rw-r--r--apt-pkg/contrib/strutl.cc11
-rw-r--r--apt-pkg/contrib/strutl.h2
11 files changed, 159 insertions, 81 deletions
diff --git a/apt-pkg/contrib/cdromutl.cc b/apt-pkg/contrib/cdromutl.cc
index b6524a178..0cf9697ac 100644
--- a/apt-pkg/contrib/cdromutl.cc
+++ b/apt-pkg/contrib/cdromutl.cc
@@ -98,7 +98,7 @@ bool UnmountCdrom(string Path)
// MountCdrom - Mount a cdrom /*{{{*/
// ---------------------------------------------------------------------
/* We fork mount and drop all messages */
-bool MountCdrom(string Path)
+bool MountCdrom(string Path, string DeviceName)
{
if (IsMounted(Path) == true)
return true;
@@ -122,8 +122,15 @@ bool MountCdrom(string Path)
{
const char *Args[10];
Args[0] = "mount";
- Args[1] = Path.c_str();
- Args[2] = 0;
+ if (DeviceName == "")
+ {
+ Args[1] = Path.c_str();
+ Args[2] = 0;
+ } else {
+ Args[1] = DeviceName.c_str();
+ Args[2] = Path.c_str();
+ Args[3] = 0;
+ }
execvp(Args[0],(char **)Args);
_exit(100);
}
diff --git a/apt-pkg/contrib/cdromutl.h b/apt-pkg/contrib/cdromutl.h
index f24bb8c70..9d14249c5 100644
--- a/apt-pkg/contrib/cdromutl.h
+++ b/apt-pkg/contrib/cdromutl.h
@@ -14,7 +14,8 @@
using std::string;
-bool MountCdrom(string Path);
+// mount cdrom, DeviceName (e.g. /dev/sr0) is optional
+bool MountCdrom(string Path, string DeviceName="");
bool UnmountCdrom(string Path);
bool IdentCdrom(string CD,string &Res,unsigned int Version = 2);
bool IsMounted(string &Path);
diff --git a/apt-pkg/contrib/configuration.cc b/apt-pkg/contrib/configuration.cc
index 7326b84ea..48a5f0bff 100644
--- a/apt-pkg/contrib/configuration.cc
+++ b/apt-pkg/contrib/configuration.cc
@@ -182,9 +182,9 @@ string Configuration::FindFile(const char *Name,const char *Default) const
if (Itm == 0 || Itm->Value.empty() == true)
{
if (Default == 0)
- return "";
+ return rootDir;
else
- return Default;
+ return rootDir + Default;
}
string val = Itm->Value;
@@ -521,6 +521,7 @@ bool ReadConfigFile(Configuration &Conf,const string &FName,bool AsSectional,
F.getline(Buffer,sizeof(Buffer) / 2);
Input += Buffer;
+ delete[] Buffer;
}
while (F.fail() && !F.eof());
@@ -582,7 +583,7 @@ bool ReadConfigFile(Configuration &Conf,const string &FName,bool AsSectional,
if (InQuote == true)
continue;
- if (*I == '/' && I + 1 != End && I[1] == '/')
+ if ((*I == '/' && I + 1 != End && I[1] == '/') || *I == '#')
{
End = I;
break;
diff --git a/apt-pkg/contrib/error.cc b/apt-pkg/contrib/error.cc
index db8c53c36..927b7e05c 100644
--- a/apt-pkg/contrib/error.cc
+++ b/apt-pkg/contrib/error.cc
@@ -84,17 +84,17 @@ bool GlobalError::Errno(const char *Function,const char *Description,...)
char S[400];
vsnprintf(S,sizeof(S),Description,args);
snprintf(S + strlen(S),sizeof(S) - strlen(S),
- " - %s (%i %s)",Function,errno,strerror(errno));
+ " - %s (%i: %s)",Function,errno,strerror(errno));
// Put it on the list
Item *Itm = new Item;
Itm->Text = S;
Itm->Error = true;
Insert(Itm);
-
+
PendingFlag = true;
- return false;
+ return false;
}
/*}}}*/
// GlobalError::WarningE - Get part of the warn string from errno /*{{{*/
@@ -112,15 +112,16 @@ bool GlobalError::WarningE(const char *Function,const char *Description,...)
// sprintf the description
char S[400];
vsnprintf(S,sizeof(S),Description,args);
- snprintf(S + strlen(S),sizeof(S) - strlen(S)," - %s (%i %s)",Function,errno,strerror(errno));
+ snprintf(S + strlen(S),sizeof(S) - strlen(S),
+ " - %s (%i: %s)",Function,errno,strerror(errno));
// Put it on the list
Item *Itm = new Item;
Itm->Text = S;
Itm->Error = false;
Insert(Itm);
-
- return false;
+
+ return false;
}
/*}}}*/
// GlobalError::Error - Add an error to the list /*{{{*/
diff --git a/apt-pkg/contrib/hashes.cc b/apt-pkg/contrib/hashes.cc
index fcc2f887c..b43771ea7 100644
--- a/apt-pkg/contrib/hashes.cc
+++ b/apt-pkg/contrib/hashes.cc
@@ -34,7 +34,7 @@ HashString::HashString(string Type, string Hash) : Type(Type), Hash(Hash)
{
}
-HashString::HashString(string StringedHash)
+HashString::HashString(string StringedHash) /*{{{*/
{
// legacy: md5sum without "MD5Sum:" prefix
if (StringedHash.find(":") == string::npos && StringedHash.size() == 32)
@@ -50,9 +50,8 @@ HashString::HashString(string StringedHash)
if(_config->FindB("Debug::Hashes",false) == true)
std::clog << "HashString(string): " << Type << " : " << Hash << std::endl;
}
-
-
-bool HashString::VerifyFile(string filename) const
+ /*}}}*/
+bool HashString::VerifyFile(string filename) const /*{{{*/
{
FileFd fd;
MD5Summation MD5;
@@ -83,7 +82,7 @@ bool HashString::VerifyFile(string filename) const
return (fileHash == Hash);
}
-
+ /*}}}*/
const char** HashString::SupportedHashes()
{
return _SupportedHashes;
@@ -94,13 +93,11 @@ bool HashString::empty() const
return (Type.empty() || Hash.empty());
}
-
string HashString::toStr() const
{
return Type+string(":")+Hash;
}
-
// Hashes::AddFD - Add the contents of the FD /*{{{*/
// ---------------------------------------------------------------------
/* */
@@ -108,11 +105,16 @@ bool Hashes::AddFD(int Fd,unsigned long Size)
{
unsigned char Buf[64*64];
int Res = 0;
- while (Size != 0)
+ int ToEOF = (Size == 0);
+ while (Size != 0 || ToEOF)
{
- Res = read(Fd,Buf,min(Size,(unsigned long)sizeof(Buf)));
- if (Res < 0 || (unsigned)Res != min(Size,(unsigned long)sizeof(Buf)))
- return false;
+ unsigned n = sizeof(Buf);
+ if (!ToEOF) n = min(Size,(unsigned long)n);
+ Res = read(Fd,Buf,n);
+ if (Res < 0 || (!ToEOF && (unsigned) Res != n)) // error, or short read
+ return false;
+ if (ToEOF && Res == 0) // EOF
+ break;
Size -= Res;
MD5.Add(Buf,Res);
SHA1.Add(Buf,Res);
diff --git a/apt-pkg/contrib/md5.cc b/apt-pkg/contrib/md5.cc
index a095f8f0f..2bfd70f1b 100644
--- a/apt-pkg/contrib/md5.cc
+++ b/apt-pkg/contrib/md5.cc
@@ -294,11 +294,16 @@ bool MD5Summation::AddFD(int Fd,unsigned long Size)
{
unsigned char Buf[64*64];
int Res = 0;
- while (Size != 0)
+ int ToEOF = (Size == 0);
+ while (Size != 0 || ToEOF)
{
- Res = read(Fd,Buf,min(Size,(unsigned long)sizeof(Buf)));
- if (Res < 0 || (unsigned)Res != min(Size,(unsigned long)sizeof(Buf)))
- return false;
+ unsigned n = sizeof(Buf);
+ if (!ToEOF) n = min(Size,(unsigned long)n);
+ Res = read(Fd,Buf,n);
+ if (Res < 0 || (!ToEOF && (unsigned) Res != n)) // error, or short read
+ return false;
+ if (ToEOF && Res == 0) // EOF
+ break;
Size -= Res;
Add(Buf,Res);
}
diff --git a/apt-pkg/contrib/mmap.cc b/apt-pkg/contrib/mmap.cc
index 04a45811b..aa52b4c30 100644
--- a/apt-pkg/contrib/mmap.cc
+++ b/apt-pkg/contrib/mmap.cc
@@ -13,11 +13,6 @@
libc6 generates warnings -- which should be errors, g++ isn't properly
strict.
- The configure test notes that some OS's have broken private mmap's
- so on those OS's we can't use mmap. This means we have to use
- configure to test mmap and can't rely on the POSIX
- _POSIX_MAPPED_FILES test.
-
##################################################################### */
/*}}}*/
// Include Files /*{{{*/
@@ -31,6 +26,7 @@
#include <sys/stat.h>
#include <unistd.h>
#include <fcntl.h>
+#include <stdlib.h>
#include <cstring>
/*}}}*/
@@ -144,7 +140,7 @@ bool MMap::Sync(unsigned long Start,unsigned long Stop)
// DynamicMMap::DynamicMMap - Constructor /*{{{*/
// ---------------------------------------------------------------------
/* */
-DynamicMMap::DynamicMMap(FileFd &F,unsigned long Flags,unsigned long WorkSpace) :
+DynamicMMap::DynamicMMap(FileFd &F,unsigned long Flags,unsigned long WorkSpace) :
MMap(F,Flags | NoImmMap), Fd(&F), WorkSpace(WorkSpace)
{
if (_error->PendingError() == true)
@@ -166,15 +162,34 @@ DynamicMMap::DynamicMMap(FileFd &F,unsigned long Flags,unsigned long WorkSpace)
/*}}}*/
// DynamicMMap::DynamicMMap - Constructor for a non-file backed map /*{{{*/
// ---------------------------------------------------------------------
-/* This is just a fancy malloc really.. */
+/* We try here to use mmap to reserve some space - this is much more
+ cooler than the fallback solution to simply allocate a char array
+ and could come in handy later than we are able to grow such an mmap */
DynamicMMap::DynamicMMap(unsigned long Flags,unsigned long WorkSpace) :
MMap(Flags | NoImmMap | UnMapped), Fd(0), WorkSpace(WorkSpace)
{
if (_error->PendingError() == true)
return;
-
+
+#ifdef _POSIX_MAPPED_FILES
+ // Set the permissions.
+ int Prot = PROT_READ;
+ int Map = MAP_PRIVATE | MAP_ANONYMOUS;
+ if ((Flags & ReadOnly) != ReadOnly)
+ Prot |= PROT_WRITE;
+ if ((Flags & Public) == Public)
+ Map = MAP_SHARED | MAP_ANONYMOUS;
+
+ // use anonymous mmap() to get the memory
+ Base = (unsigned char*) mmap(0, WorkSpace, Prot, Map, -1, 0);
+
+ if(Base == MAP_FAILED)
+ _error->Errno("DynamicMMap",_("Couldn't make mmap of %lu bytes"),WorkSpace);
+#else
+ // fallback to a static allocated space
Base = new unsigned char[WorkSpace];
memset(Base,0,WorkSpace);
+#endif
iSize = 0;
}
/*}}}*/
@@ -185,7 +200,11 @@ DynamicMMap::~DynamicMMap()
{
if (Fd == 0)
{
+#ifdef _POSIX_MAPPED_FILES
+ munmap(Base, WorkSpace);
+#else
delete [] (unsigned char *)Base;
+#endif
return;
}
@@ -204,17 +223,19 @@ unsigned long DynamicMMap::RawAllocate(unsigned long Size,unsigned long Aln)
unsigned long Result = iSize;
if (Aln != 0)
Result += Aln - (iSize%Aln);
-
+
iSize = Result + Size;
-
- // Just in case error check
- if (Result + Size > WorkSpace)
+
+ // try to grow the buffer
+ while(Result + Size > WorkSpace)
{
- _error->Error(_("Dynamic MMap ran out of room. Please increase the size "
- "of APT::Cache-Limit. Current value: %lu. (man 5 apt.conf)"), WorkSpace);
- return 0;
+ if(!Grow())
+ {
+ _error->Error(_("Dynamic MMap ran out of room. Please increase the size "
+ "of APT::Cache-Limit. Current value: %lu. (man 5 apt.conf)"), WorkSpace);
+ return 0;
+ }
}
-
return Result;
}
/*}}}*/
@@ -223,7 +244,7 @@ unsigned long DynamicMMap::RawAllocate(unsigned long Size,unsigned long Aln)
/* This allocates an Item of size ItemSize so that it is aligned to its
size in the file. */
unsigned long DynamicMMap::Allocate(unsigned long ItemSize)
-{
+{
// Look for a matching pool entry
Pool *I;
Pool *Empty = 0;
@@ -234,7 +255,6 @@ unsigned long DynamicMMap::Allocate(unsigned long ItemSize)
if (I->ItemSize == ItemSize)
break;
}
-
// No pool is allocated, use an unallocated one
if (I == Pools + PoolCount)
{
@@ -249,17 +269,24 @@ unsigned long DynamicMMap::Allocate(unsigned long ItemSize)
I->ItemSize = ItemSize;
I->Count = 0;
}
-
+
+ unsigned long Result = 0;
// Out of space, allocate some more
if (I->Count == 0)
{
- I->Count = 20*1024/ItemSize;
- I->Start = RawAllocate(I->Count*ItemSize,ItemSize);
- }
+ const unsigned long size = 20*1024;
+ I->Count = size/ItemSize;
+ Result = RawAllocate(size,ItemSize);
+ // Does the allocation failed ?
+ if (Result == 0 && _error->PendingError())
+ return 0;
+ I->Start = Result;
+ }
+ else
+ Result = I->Start;
I->Count--;
- unsigned long Result = I->Start;
- I->Start += ItemSize;
+ I->Start += ItemSize;
return Result/ItemSize;
}
/*}}}*/
@@ -269,20 +296,45 @@ unsigned long DynamicMMap::Allocate(unsigned long ItemSize)
unsigned long DynamicMMap::WriteString(const char *String,
unsigned long Len)
{
- unsigned long Result = iSize;
- // Just in case error check
- if (Result + Len > WorkSpace)
- {
- _error->Error(_("Dynamic MMap ran out of room. Please increase the size "
- "of APT::Cache-Limit. Current value: %lu. (man 5 apt.conf)"), WorkSpace);
- return 0;
- }
-
if (Len == (unsigned long)-1)
Len = strlen(String);
- iSize += Len + 1;
+
+ unsigned long Result = RawAllocate(Len+1,0);
+
+ if (Result == 0 && _error->PendingError())
+ return 0;
+
memcpy((char *)Base + Result,String,Len);
((char *)Base)[Result + Len] = 0;
return Result;
}
/*}}}*/
+// DynamicMMap::Grow - Grow the mmap /*{{{*/
+// ---------------------------------------------------------------------
+/* This method will try to grow the mmap we currently use. This doesn't
+ work most of the time because we can't move the mmap around in the
+ memory for now as this would require to adjust quite a lot of pointers
+ but why we should not at least try to grow it before we give up? */
+bool DynamicMMap::Grow()
+{
+#ifdef _POSIX_MAPPED_FILES
+ unsigned long newSize = WorkSpace + 1024*1024;
+
+ if(Fd != 0)
+ {
+ Fd->Seek(newSize - 1);
+ char C = 0;
+ Fd->Write(&C,sizeof(C));
+ }
+
+ Base = mremap(Base, WorkSpace, newSize, 0);
+ if(Base == MAP_FAILED)
+ return false;
+
+ WorkSpace = newSize;
+ return true;
+#else
+ return false;
+#endif
+}
+ /*}}}*/
diff --git a/apt-pkg/contrib/mmap.h b/apt-pkg/contrib/mmap.h
index 19cf7582d..bde62217d 100644
--- a/apt-pkg/contrib/mmap.h
+++ b/apt-pkg/contrib/mmap.h
@@ -84,6 +84,8 @@ class DynamicMMap : public MMap
unsigned long WorkSpace;
Pool *Pools;
unsigned int PoolCount;
+
+ bool Grow();
public:
diff --git a/apt-pkg/contrib/sha256.cc b/apt-pkg/contrib/sha256.cc
index ecda3d8e8..e380c13ae 100644
--- a/apt-pkg/contrib/sha256.cc
+++ b/apt-pkg/contrib/sha256.cc
@@ -1,5 +1,5 @@
/*
- * Cryptographic API.
+ * Cryptographic API. {{{
*
* SHA-256, as specified in
* http://csrc.nist.gov/cryptval/shs/sha256-384-512.pdf
@@ -17,7 +17,7 @@
* Software Foundation; either version 2 of the License, or (at your option)
* any later version.
*
- */
+ */ /*}}}*/
#ifdef __GNUG__
#pragma implementation "apt-pkg/sha256.h"
@@ -65,20 +65,20 @@ static inline u32 Maj(u32 x, u32 y, u32 z)
#define H6 0x1f83d9ab
#define H7 0x5be0cd19
-static inline void LOAD_OP(int I, u32 *W, const u8 *input)
+static inline void LOAD_OP(int I, u32 *W, const u8 *input) /*{{{*/
{
W[I] = ( ((u32) input[I * 4 + 0] << 24)
| ((u32) input[I * 4 + 1] << 16)
| ((u32) input[I * 4 + 2] << 8)
| ((u32) input[I * 4 + 3]));
}
-
+ /*}}}*/
static inline void BLEND_OP(int I, u32 *W)
{
W[I] = s1(W[I-2]) + W[I-7] + s0(W[I-15]) + W[I-16];
}
-static void sha256_transform(u32 *state, const u8 *input)
+static void sha256_transform(u32 *state, const u8 *input) /*{{{*/
{
u32 a, b, c, d, e, f, g, h, t1, t2;
u32 W[64];
@@ -240,8 +240,8 @@ static void sha256_transform(u32 *state, const u8 *input)
a = b = c = d = e = f = g = h = t1 = t2 = 0;
memset(W, 0, 64 * sizeof(u32));
}
-
-SHA256Summation::SHA256Summation()
+ /*}}}*/
+SHA256Summation::SHA256Summation() /*{{{*/
{
Sum.state[0] = H0;
Sum.state[1] = H1;
@@ -255,8 +255,8 @@ SHA256Summation::SHA256Summation()
memset(Sum.buf, 0, sizeof(Sum.buf));
Done = false;
}
-
-bool SHA256Summation::Add(const u8 *data, unsigned long len)
+ /*}}}*/
+bool SHA256Summation::Add(const u8 *data, unsigned long len) /*{{{*/
{
struct sha256_ctx *sctx = &Sum;
unsigned int i, index, part_len;
@@ -291,8 +291,8 @@ bool SHA256Summation::Add(const u8 *data, unsigned long len)
return true;
}
-
-SHA256SumValue SHA256Summation::Result()
+ /*}}}*/
+SHA256SumValue SHA256Summation::Result() /*{{{*/
{
struct sha256_ctx *sctx = &Sum;
if (!Done) {
@@ -340,7 +340,7 @@ SHA256SumValue SHA256Summation::Result()
return res;
}
-
+ /*}}}*/
// SHA256SumValue::SHA256SumValue - Constructs the sum from a string /*{{{*/
// ---------------------------------------------------------------------
/* The string form of a SHA256 is a 64 character hex number */
@@ -349,7 +349,6 @@ SHA256SumValue::SHA256SumValue(string Str)
memset(Sum,0,sizeof(Sum));
Set(Str);
}
-
/*}}}*/
// SHA256SumValue::SHA256SumValue - Default constructor /*{{{*/
// ---------------------------------------------------------------------
@@ -358,7 +357,6 @@ SHA256SumValue::SHA256SumValue()
{
memset(Sum,0,sizeof(Sum));
}
-
/*}}}*/
// SHA256SumValue::Set - Set the sum from a string /*{{{*/
// ---------------------------------------------------------------------
@@ -391,9 +389,7 @@ string SHA256SumValue::Value() const
return string(Result);
}
-
-
-
+ /*}}}*/
// SHA256SumValue::operator == - Comparator /*{{{*/
// ---------------------------------------------------------------------
/* Call memcmp on the buffer */
@@ -402,8 +398,6 @@ bool SHA256SumValue::operator == (const SHA256SumValue & rhs) const
return memcmp(Sum,rhs.Sum,sizeof(Sum)) == 0;
}
/*}}}*/
-
-
// SHA256Summation::AddFD - Add content of file into the checksum /*{{{*/
// ---------------------------------------------------------------------
/* */
diff --git a/apt-pkg/contrib/strutl.cc b/apt-pkg/contrib/strutl.cc
index 0b1bc3c98..a991b8988 100644
--- a/apt-pkg/contrib/strutl.cc
+++ b/apt-pkg/contrib/strutl.cc
@@ -387,6 +387,17 @@ string SubstVar(string Str,const struct SubstVar *Vars)
return Str;
}
/*}}}*/
+// OutputInDepth - return a string with separator multiplied with depth /*{{{*/
+// ---------------------------------------------------------------------
+/* Returns a string with the supplied separator depth + 1 times in it */
+std::string OutputInDepth(const unsigned long Depth, const char* Separator)
+{
+ std::string output = "";
+ for(unsigned long d=Depth+1; d > 0; d--)
+ output.append(Separator);
+ return output;
+}
+ /*}}}*/
// URItoFileName - Convert the uri into a unique file name /*{{{*/
// ---------------------------------------------------------------------
/* This converts a URI into a safe filename. It quotes all unsafe characters
diff --git a/apt-pkg/contrib/strutl.h b/apt-pkg/contrib/strutl.h
index 51416a24a..0cbf14a7a 100644
--- a/apt-pkg/contrib/strutl.h
+++ b/apt-pkg/contrib/strutl.h
@@ -48,6 +48,7 @@ string DeQuoteString(const string &Str);
string SizeToStr(double Bytes);
string TimeToStr(unsigned long Sec);
string Base64Encode(const string &Str);
+string OutputInDepth(const unsigned long Depth, const char* Separator=" ");
string URItoFileName(const string &URI);
string TimeRFC1123(time_t Date);
bool StrToTime(const string &Val,time_t &Result);
@@ -65,6 +66,7 @@ bool CheckDomainList(const string &Host, const string &List);
int tolower_ascii(int c);
#define APT_MKSTRCMP(name,func) \
+inline int name(const char *A,const char *B) {return func(A,A+strlen(A),B,B+strlen(B));}; \
inline int name(const char *A,const char *AEnd,const char *B) {return func(A,AEnd,B,B+strlen(B));}; \
inline int name(string A,const char *B) {return func(A.c_str(),A.c_str()+A.length(),B,B+strlen(B));}; \
inline int name(string A,string B) {return func(A.c_str(),A.c_str()+A.length(),B.c_str(),B.c_str()+B.length());}; \