summaryrefslogtreecommitdiff
path: root/apt-pkg
diff options
context:
space:
mode:
Diffstat (limited to 'apt-pkg')
-rw-r--r--apt-pkg/acquire-item.cc108
-rw-r--r--apt-pkg/acquire-item.h30
-rw-r--r--apt-pkg/acquire.cc36
-rw-r--r--apt-pkg/acquire.h4
-rw-r--r--apt-pkg/algorithms.cc19
-rw-r--r--apt-pkg/aptconfiguration.cc2
-rw-r--r--apt-pkg/cachefilter.h70
-rw-r--r--apt-pkg/cacheset.cc15
-rw-r--r--apt-pkg/cdrom.cc66
-rw-r--r--apt-pkg/cdrom.h1
-rw-r--r--apt-pkg/contrib/configuration.cc4
-rw-r--r--apt-pkg/contrib/configuration.h6
-rw-r--r--apt-pkg/contrib/fileutl.cc162
-rw-r--r--apt-pkg/contrib/fileutl.h37
-rw-r--r--apt-pkg/contrib/hashes.cc2
-rw-r--r--apt-pkg/contrib/hashes.h2
-rw-r--r--apt-pkg/contrib/macros.h2
-rw-r--r--apt-pkg/contrib/netrc.cc12
-rw-r--r--apt-pkg/contrib/netrc.h4
-rw-r--r--apt-pkg/deb/debindexfile.cc106
-rw-r--r--apt-pkg/deb/debindexfile.h30
-rw-r--r--apt-pkg/deb/deblistparser.cc20
-rw-r--r--apt-pkg/deb/deblistparser.h15
-rw-r--r--apt-pkg/deb/debmetaindex.cc29
-rw-r--r--apt-pkg/deb/debmetaindex.h24
-rw-r--r--apt-pkg/deb/debrecords.h18
-rw-r--r--apt-pkg/deb/debsrcrecords.cc131
-rw-r--r--apt-pkg/deb/dpkgpm.cc15
-rw-r--r--apt-pkg/indexrecords.cc2
-rw-r--r--apt-pkg/indexrecords.h2
-rw-r--r--apt-pkg/init.cc1
-rw-r--r--apt-pkg/install-progress.cc35
-rw-r--r--apt-pkg/install-progress.h3
-rw-r--r--apt-pkg/makefile48
-rw-r--r--apt-pkg/packagemanager.cc1
-rw-r--r--apt-pkg/packagemanager.h5
-rw-r--r--apt-pkg/pkgcache.cc2
-rw-r--r--apt-pkg/pkgcache.h2
-rw-r--r--apt-pkg/sourcelist.h10
-rw-r--r--apt-pkg/srcrecords.h1
40 files changed, 762 insertions, 320 deletions
diff --git a/apt-pkg/acquire-item.cc b/apt-pkg/acquire-item.cc
index 30743addf..913764f64 100644
--- a/apt-pkg/acquire-item.cc
+++ b/apt-pkg/acquire-item.cc
@@ -55,7 +55,8 @@ using namespace std;
/* */
pkgAcquire::Item::Item(pkgAcquire *Owner) : Owner(Owner), FileSize(0),
PartialSize(0), Mode(0), ID(0), Complete(false),
- Local(false), QueueCounter(0)
+ Local(false), QueueCounter(0),
+ ExpectedAdditionalItems(0)
{
Owner->Add(this);
Status = StatIdle;
@@ -342,21 +343,24 @@ bool pkgAcqSubIndex::ParseIndex(string const &IndexFile) /*{{{*/
* the original packages file
*/
pkgAcqDiffIndex::pkgAcqDiffIndex(pkgAcquire *Owner,
- string URI,string URIDesc,string ShortDesc,
- HashString ExpectedHash)
- : Item(Owner), RealURI(URI), ExpectedHash(ExpectedHash),
- Description(URIDesc)
+ IndexTarget const *Target,
+ HashString ExpectedHash,
+ indexRecords *MetaIndexParser)
+ : Item(Owner), ExpectedHash(ExpectedHash), Target(Target),
+ MetaIndexParser(MetaIndexParser)
+
{
Debug = _config->FindB("Debug::pkgAcquire::Diffs",false);
- Desc.Description = URIDesc + "/DiffIndex";
+ RealURI = Target->URI;
Desc.Owner = this;
- Desc.ShortDesc = ShortDesc;
- Desc.URI = URI + ".diff/Index";
+ Desc.Description = Target->Description + "/DiffIndex";
+ Desc.ShortDesc = Target->ShortDesc;
+ Desc.URI = Target->URI + ".diff/Index";
DestFile = _config->FindDir("Dir::State::lists") + "partial/";
- DestFile += URItoFileName(URI) + string(".DiffIndex");
+ DestFile += URItoFileName(Target->URI) + string(".DiffIndex");
if(Debug)
std::clog << "pkgAcqDiffIndex: " << Desc.URI << std::endl;
@@ -559,8 +563,7 @@ void pkgAcqDiffIndex::Failed(string Message,pkgAcquire::MethodConfig * /*Cnf*/)/
std::clog << "pkgAcqDiffIndex failed: " << Desc.URI << " with " << Message << std::endl
<< "Falling back to normal index file acquire" << std::endl;
- new pkgAcqIndex(Owner, RealURI, Description, Desc.ShortDesc,
- ExpectedHash);
+ new pkgAcqIndex(Owner, Target, ExpectedHash, MetaIndexParser);
Complete = false;
Status = StatDone;
@@ -919,7 +922,8 @@ void pkgAcqIndexMergeDiffs::Done(string Message,unsigned long long Size,string M
pkgAcqIndex::pkgAcqIndex(pkgAcquire *Owner,
string URI,string URIDesc,string ShortDesc,
HashString ExpectedHash, string comprExt)
- : Item(Owner), RealURI(URI), ExpectedHash(ExpectedHash)
+ : Item(Owner), RealURI(URI), ExpectedHash(ExpectedHash), Target(0),
+ MetaIndexParser(0)
{
if(comprExt.empty() == true)
{
@@ -932,10 +936,12 @@ pkgAcqIndex::pkgAcqIndex(pkgAcquire *Owner,
}
CompressionExtension = comprExt;
+ Verify = true;
+
Init(URI, URIDesc, ShortDesc);
}
pkgAcqIndex::pkgAcqIndex(pkgAcquire *Owner, IndexTarget const *Target,
- HashString const &ExpectedHash, indexRecords const *MetaIndexParser)
+ HashString const &ExpectedHash, indexRecords *MetaIndexParser)
: Item(Owner), RealURI(Target->URI), ExpectedHash(ExpectedHash)
{
// autoselect the compression method
@@ -962,6 +968,10 @@ pkgAcqIndex::pkgAcqIndex(pkgAcquire *Owner, IndexTarget const *Target,
else
Verify = true;
+ // we need this in Init()
+ this->Target = Target;
+ this->MetaIndexParser = MetaIndexParser;
+
Init(Target->URI, Target->Description, Target->ShortDesc);
}
/*}}}*/
@@ -974,10 +984,27 @@ void pkgAcqIndex::Init(string const &URI, string const &URIDesc, string const &S
DestFile += URItoFileName(URI);
std::string const comprExt = CompressionExtension.substr(0, CompressionExtension.find(' '));
+ std::string MetaKey;
if (comprExt == "uncompressed")
+ {
Desc.URI = URI;
+ if(Target)
+ MetaKey = string(Target->MetaKey);
+ }
else
+ {
Desc.URI = URI + '.' + comprExt;
+ if(Target)
+ MetaKey = string(Target->MetaKey) + '.' + comprExt;
+ }
+
+ // load the filesize
+ if(MetaIndexParser)
+ {
+ indexRecords::checkSum *Record = MetaIndexParser->Lookup(MetaKey);
+ if(Record)
+ FileSize = Record->Size;
+ }
Desc.Description = URIDesc;
Desc.Owner = this;
@@ -1079,7 +1106,7 @@ void pkgAcqIndex::Done(string Message,unsigned long long Size,string Hash,
FinalFile += URItoFileName(RealURI);
Rename(DestFile,FinalFile);
chmod(FinalFile.c_str(),0644);
-
+
/* We restore the original name to DestFile so that the clean operation
will work OK */
DestFile = _config->FindDir("Dir::State::lists") + "partial/";
@@ -1088,6 +1115,7 @@ void pkgAcqIndex::Done(string Message,unsigned long long Size,string Hash,
// Remove the compressed version.
if (Erase == true)
unlink(DestFile.c_str());
+
return;
}
@@ -1175,9 +1203,13 @@ pkgAcqIndexTrans::pkgAcqIndexTrans(pkgAcquire *Owner,
{
}
pkgAcqIndexTrans::pkgAcqIndexTrans(pkgAcquire *Owner, IndexTarget const *Target,
- HashString const &ExpectedHash, indexRecords const *MetaIndexParser)
+ HashString const &ExpectedHash, indexRecords *MetaIndexParser)
: pkgAcqIndex(Owner, Target, ExpectedHash, MetaIndexParser)
{
+ // load the filesize
+ indexRecords::checkSum *Record = MetaIndexParser->Lookup(string(Target->MetaKey));
+ if(Record)
+ FileSize = Record->Size;
}
/*}}}*/
// AcqIndexTrans::Custom600Headers - Insert custom request headers /*{{{*/
@@ -1257,6 +1289,9 @@ pkgAcqMetaSig::pkgAcqMetaSig(pkgAcquire *Owner, /*{{{*/
Rename(Final,LastGoodSig);
}
+ // we expect the indextargets + one additional Release file
+ ExpectedAdditionalItems = IndexTargets->size() + 1;
+
QueueURI(Desc);
}
/*}}}*/
@@ -1309,6 +1344,9 @@ void pkgAcqMetaSig::Done(string Message,unsigned long long Size,string MD5,
Complete = true;
+ // at this point pkgAcqMetaIndex takes over
+ ExpectedAdditionalItems = 0;
+
// put the last known good file back on i-m-s hit (it will
// be re-verified again)
// Else do nothing, we have the new file in DestFile then
@@ -1326,6 +1364,9 @@ void pkgAcqMetaSig::Failed(string Message,pkgAcquire::MethodConfig *Cnf)/*{{{*/
{
string Final = _config->FindDir("Dir::State::lists") + URItoFileName(RealURI);
+ // at this point pkgAcqMetaIndex takes over
+ ExpectedAdditionalItems = 0;
+
// if we get a network error we fail gracefully
if(Status == StatTransientNetworkError)
{
@@ -1376,6 +1417,9 @@ pkgAcqMetaIndex::pkgAcqMetaIndex(pkgAcquire *Owner, /*{{{*/
Desc.ShortDesc = ShortDesc;
Desc.URI = URI;
+ // we expect more item
+ ExpectedAdditionalItems = IndexTargets->size();
+
QueueURI(Desc);
}
/*}}}*/
@@ -1426,9 +1470,20 @@ void pkgAcqMetaIndex::Done(string Message,unsigned long long Size,string Hash, /
}
else
{
+ // FIXME: move this into pkgAcqMetaClearSig::Done on the next
+ // ABI break
+
+ // if we expect a ClearTextSignature (InRelase), ensure that
+ // this is what we get and if not fail to queue a
+ // Release/Release.gpg, see #346386
+ if (SigFile == DestFile && !StartsWithGPGClearTextSignature(DestFile))
+ {
+ Failed(Message, Cfg);
+ return;
+ }
+
// There was a signature file, so pass it to gpgv for
// verification
-
if (_config->FindB("Debug::pkgAcquire::Auth", false))
std::cerr << "Metaindex acquired, queueing gpg verification ("
<< SigFile << "," << DestFile << ")\n";
@@ -1554,12 +1609,15 @@ void pkgAcqMetaIndex::QueueIndexes(bool verify) /*{{{*/
}
}
+ // at this point the real Items are loaded in the fetcher
+ ExpectedAdditionalItems = 0;
+
for (vector <struct IndexTarget*>::const_iterator Target = IndexTargets->begin();
Target != IndexTargets->end();
++Target)
{
HashString ExpectedIndexHash;
- const indexRecords::checkSum *Record = MetaIndexParser->Lookup((*Target)->MetaKey);
+ indexRecords::checkSum *Record = MetaIndexParser->Lookup((*Target)->MetaKey);
bool compressedAvailable = false;
if (Record == NULL)
{
@@ -1606,8 +1664,7 @@ void pkgAcqMetaIndex::QueueIndexes(bool verify) /*{{{*/
{
if (_config->FindB("Acquire::PDiffs",true) == true && transInRelease == true &&
MetaIndexParser->Exists((*Target)->MetaKey + ".diff/Index") == true)
- new pkgAcqDiffIndex(Owner, (*Target)->URI, (*Target)->Description,
- (*Target)->ShortDesc, ExpectedIndexHash);
+ new pkgAcqDiffIndex(Owner, *Target, ExpectedIndexHash, MetaIndexParser);
else
new pkgAcqIndexTrans(Owner, *Target, ExpectedIndexHash, MetaIndexParser);
}
@@ -1620,8 +1677,7 @@ void pkgAcqMetaIndex::QueueIndexes(bool verify) /*{{{*/
instead, but passing the required info to it is to much hassle */
if(_config->FindB("Acquire::PDiffs",true) == true && (verify == false ||
MetaIndexParser->Exists((*Target)->MetaKey + ".diff/Index") == true))
- new pkgAcqDiffIndex(Owner, (*Target)->URI, (*Target)->Description,
- (*Target)->ShortDesc, ExpectedIndexHash);
+ new pkgAcqDiffIndex(Owner, *Target, ExpectedIndexHash, MetaIndexParser);
else
new pkgAcqIndex(Owner, *Target, ExpectedIndexHash, MetaIndexParser);
}
@@ -1784,6 +1840,10 @@ pkgAcqMetaClearSig::pkgAcqMetaClearSig(pkgAcquire *Owner, /*{{{*/
{
SigFile = DestFile;
+ // index targets + (worst case:) Release/Release.gpg
+ ExpectedAdditionalItems = IndexTargets->size() + 2;
+
+
// keep the old InRelease around in case of transistent network errors
string const Final = _config->FindDir("Dir::State::lists") + URItoFileName(RealURI);
if (RealFileExists(Final) == true)
@@ -1826,6 +1886,9 @@ string pkgAcqMetaClearSig::Custom600Headers()
/*}}}*/
void pkgAcqMetaClearSig::Failed(string Message,pkgAcquire::MethodConfig *Cnf) /*{{{*/
{
+ // we failed, we will not get additional items from this method
+ ExpectedAdditionalItems = 0;
+
if (AuthPass == false)
{
// Remove the 'old' InRelease file if we try Release.gpg now as otherwise
@@ -2084,7 +2147,8 @@ void pkgAcqArchive::Done(string Message,unsigned long long Size,string CalcHash,
}
// Check the hash
- if(ExpectedHash.toStr() != CalcHash)
+ // FIXME: could this empty() check impose *any* sort of security issue?
+ if(ExpectedHash.empty() == false && ExpectedHash.toStr() != CalcHash)
{
RenameOnError(HashSumMismatch);
return;
diff --git a/apt-pkg/acquire-item.h b/apt-pkg/acquire-item.h
index f48d2a0d7..eab5bb222 100644
--- a/apt-pkg/acquire-item.h
+++ b/apt-pkg/acquire-item.h
@@ -166,6 +166,16 @@ class pkgAcquire::Item : public WeakPointable
* \sa pkgAcquire
*/
unsigned int QueueCounter;
+
+ /** \brief The number of additional fetch items that are expected
+ * once this item is done.
+ *
+ * Some items like pkgAcqMeta{Index,Sig} will queue additional
+ * items. This variable can be set by the methods if it knows
+ * in advance how many items to expect to get a more accurate
+ * progress.
+ */
+ unsigned int ExpectedAdditionalItems;
/** \brief The name of the file into which the retrieved object
* will be written.
@@ -395,6 +405,11 @@ class pkgAcqDiffIndex : public pkgAcquire::Item
*/
std::string Description;
+ /** \brief Pointer to the IndexTarget data
+ */
+ const struct IndexTarget * Target;
+ indexRecords *MetaIndexParser;
+
public:
// Specialized action members
virtual void Failed(std::string Message,pkgAcquire::MethodConfig *Cnf);
@@ -428,8 +443,10 @@ class pkgAcqDiffIndex : public pkgAcquire::Item
*
* \param ExpectedHash The list file's MD5 signature.
*/
- pkgAcqDiffIndex(pkgAcquire *Owner,std::string URI,std::string URIDesc,
- std::string ShortDesc, HashString ExpectedHash);
+ pkgAcqDiffIndex(pkgAcquire *Owner,
+ struct IndexTarget const * const Target,
+ HashString ExpectedHash,
+ indexRecords *MetaIndexParser);
};
/*}}}*/
/** \brief An item that is responsible for fetching client-merge patches {{{
@@ -713,6 +730,11 @@ class pkgAcqIndex : public pkgAcquire::Item
*/
std::string CompressionExtension;
+ /** \brief Pointer to the IndexTarget data
+ */
+ const struct IndexTarget * Target;
+ indexRecords *MetaIndexParser;
+
public:
// Specialized action members
@@ -746,7 +768,7 @@ class pkgAcqIndex : public pkgAcquire::Item
std::string ShortDesc, HashString ExpectedHash,
std::string compressExt="");
pkgAcqIndex(pkgAcquire *Owner, struct IndexTarget const * const Target,
- HashString const &ExpectedHash, indexRecords const *MetaIndexParser);
+ HashString const &ExpectedHash, indexRecords *MetaIndexParser);
void Init(std::string const &URI, std::string const &URIDesc, std::string const &ShortDesc);
};
/*}}}*/
@@ -778,7 +800,7 @@ class pkgAcqIndexTrans : public pkgAcqIndex
pkgAcqIndexTrans(pkgAcquire *Owner,std::string URI,std::string URIDesc,
std::string ShortDesc);
pkgAcqIndexTrans(pkgAcquire *Owner, struct IndexTarget const * const Target,
- HashString const &ExpectedHash, indexRecords const *MetaIndexParser);
+ HashString const &ExpectedHash, indexRecords *MetaIndexParser);
};
/*}}}*/
/** \brief Information about an index file. */ /*{{{*/
diff --git a/apt-pkg/acquire.cc b/apt-pkg/acquire.cc
index a187a00ae..57cbba169 100644
--- a/apt-pkg/acquire.cc
+++ b/apt-pkg/acquire.cc
@@ -31,6 +31,7 @@
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
+#include <iomanip>
#include <dirent.h>
#include <sys/time.h>
@@ -821,7 +822,9 @@ bool pkgAcquireStatus::Pulse(pkgAcquire *Owner)
// Compute the total number of bytes to fetch
unsigned int Unknown = 0;
unsigned int Count = 0;
- for (pkgAcquire::ItemCIterator I = Owner->ItemsBegin(); I != Owner->ItemsEnd();
+ bool UnfetchedReleaseFiles = false;
+ for (pkgAcquire::ItemCIterator I = Owner->ItemsBegin();
+ I != Owner->ItemsEnd();
++I, ++Count)
{
TotalItems++;
@@ -832,6 +835,13 @@ bool pkgAcquireStatus::Pulse(pkgAcquire *Owner)
if ((*I)->Local == true)
continue;
+ // see if the method tells us to expect more
+ TotalItems += (*I)->ExpectedAdditionalItems;
+
+ // check if there are unfetched Release files
+ if ((*I)->Complete == false && (*I)->ExpectedAdditionalItems > 0)
+ UnfetchedReleaseFiles = true;
+
TotalBytes += (*I)->FileSize;
if ((*I)->Complete == true)
CurrentBytes += (*I)->FileSize;
@@ -843,6 +853,7 @@ bool pkgAcquireStatus::Pulse(pkgAcquire *Owner)
unsigned long long ResumeSize = 0;
for (pkgAcquire::Worker *I = Owner->WorkersBegin(); I != 0;
I = Owner->WorkerStep(I))
+ {
if (I->CurrentItem != 0 && I->CurrentItem->Owner->Complete == false)
{
CurrentBytes += I->CurrentSize;
@@ -853,6 +864,7 @@ bool pkgAcquireStatus::Pulse(pkgAcquire *Owner)
I->CurrentItem->Owner->Complete == false)
TotalBytes += I->CurrentSize;
}
+ }
// Normalize the figures and account for unknown size downloads
if (TotalBytes <= 0)
@@ -863,6 +875,12 @@ bool pkgAcquireStatus::Pulse(pkgAcquire *Owner)
// Wha?! Is not supposed to happen.
if (CurrentBytes > TotalBytes)
CurrentBytes = TotalBytes;
+
+ // debug
+ if (_config->FindB("Debug::acquire::progress", false) == true)
+ std::clog << " Bytes: "
+ << SizeToStr(CurrentBytes) << " / " << SizeToStr(TotalBytes)
+ << std::endl;
// Compute the CPS
struct timeval NewTime;
@@ -883,6 +901,14 @@ bool pkgAcquireStatus::Pulse(pkgAcquire *Owner)
Time = NewTime;
}
+ // calculate the percentage, if we have too little data assume 1%
+ if (TotalBytes > 0 && UnfetchedReleaseFiles)
+ Percent = 0;
+ else
+ // use both files and bytes because bytes can be unreliable
+ Percent = (0.8 * (CurrentBytes/float(TotalBytes)*100.0) +
+ 0.2 * (CurrentItems/float(TotalItems)*100.0));
+
int fd = _config->FindI("APT::Status-Fd",-1);
if(fd > 0)
{
@@ -900,13 +926,11 @@ bool pkgAcquireStatus::Pulse(pkgAcquire *Owner)
else
snprintf(msg,sizeof(msg), _("Retrieving file %li of %li"), i, TotalItems);
-
-
// build the status str
status << "dlstatus:" << i
- << ":" << (CurrentBytes/float(TotalBytes)*100.0)
- << ":" << msg
- << endl;
+ << ":" << std::setprecision(3) << Percent
+ << ":" << msg
+ << endl;
std::string const dlstatus = status.str();
FileFd::Write(fd, dlstatus.c_str(), dlstatus.size());
diff --git a/apt-pkg/acquire.h b/apt-pkg/acquire.h
index ef16d8556..0113021b2 100644
--- a/apt-pkg/acquire.h
+++ b/apt-pkg/acquire.h
@@ -714,6 +714,10 @@ class pkgAcquireStatus
/** \brief The number of items that have been successfully downloaded. */
unsigned long CurrentItems;
+ /** \brief The estimated percentage of the download (0-100)
+ */
+ double Percent;
+
public:
/** \brief If \b true, the download scheduler should call Pulse()
diff --git a/apt-pkg/algorithms.cc b/apt-pkg/algorithms.cc
index a7b676660..608ec7fce 100644
--- a/apt-pkg/algorithms.cc
+++ b/apt-pkg/algorithms.cc
@@ -445,19 +445,22 @@ void pkgProblemResolver::MakeScores()
|| (I->Flags & pkgCache::Flag::Important) == pkgCache::Flag::Important)
Score += PrioEssentials;
- // We transform the priority
- if (Cache[I].InstVerIter(Cache)->Priority <= 5)
- Score += PrioMap[Cache[I].InstVerIter(Cache)->Priority];
-
+ pkgCache::VerIterator const InstVer = Cache[I].InstVerIter(Cache);
+ // We apply priorities only to downloadable packages, all others are prio:extra
+ // as an obsolete prio:standard package can't be that standard anymore…
+ if (InstVer->Priority <= pkgCache::State::Extra && InstVer.Downloadable() == true)
+ Score += PrioMap[InstVer->Priority];
+ else
+ Score += PrioMap[pkgCache::State::Extra];
+
/* This helps to fix oddball problems with conflicting packages
- on the same level. We enhance the score of installed packages
- if those are not obsolete
- */
+ on the same level. We enhance the score of installed packages
+ if those are not obsolete */
if (I->CurrentVer != 0 && Cache[I].CandidateVer != 0 && Cache[I].CandidateVerIter(Cache).Downloadable())
Score += PrioInstalledAndNotObsolete;
// propagate score points along dependencies
- for (pkgCache::DepIterator D = Cache[I].InstVerIter(Cache).DependsList(); D.end() == false; ++D)
+ for (pkgCache::DepIterator D = InstVer.DependsList(); D.end() == false; ++D)
{
if (DepMap[D->Type] == 0)
continue;
diff --git a/apt-pkg/aptconfiguration.cc b/apt-pkg/aptconfiguration.cc
index 6ba047560..9982759c6 100644
--- a/apt-pkg/aptconfiguration.cc
+++ b/apt-pkg/aptconfiguration.cc
@@ -476,7 +476,7 @@ const Configuration::getCompressors(bool const Cached) {
std::vector<std::string> const comp = _config->FindVector("APT::Compressor");
for (std::vector<std::string>::const_iterator c = comp.begin();
c != comp.end(); ++c) {
- if (*c == "." || *c == "gzip" || *c == "bzip2" || *c == "lzma" || *c == "xz")
+ if (c->empty() || *c == "." || *c == "gzip" || *c == "bzip2" || *c == "lzma" || *c == "xz")
continue;
compressors.push_back(Compressor(c->c_str(), std::string(".").append(*c).c_str(), c->c_str(), "-9", "-d", 100));
}
diff --git a/apt-pkg/cachefilter.h b/apt-pkg/cachefilter.h
index 49d2855f5..d9b957c67 100644
--- a/apt-pkg/cachefilter.h
+++ b/apt-pkg/cachefilter.h
@@ -16,71 +16,14 @@
namespace APT {
namespace CacheFilter {
-#define PACKAGE_MATCHER_ABI_COMPAT 1
-#ifdef PACKAGE_MATCHER_ABI_COMPAT
-
-// PackageNameMatchesRegEx /*{{{*/
-class PackageNameMatchesRegEx {
- /** \brief dpointer placeholder (for later in case we need it) */
- void *d;
- regex_t* pattern;
-public:
- PackageNameMatchesRegEx(std::string const &Pattern);
- bool operator() (pkgCache::PkgIterator const &Pkg);
- bool operator() (pkgCache::GrpIterator const &Grp);
- ~PackageNameMatchesRegEx();
-};
- /*}}}*/
-// PackageNameMatchesFnmatch /*{{{*/
- class PackageNameMatchesFnmatch {
- /** \brief dpointer placeholder (for later in case we need it) */
- void *d;
- const std::string Pattern;
-public:
- PackageNameMatchesFnmatch(std::string const &Pattern)
- : Pattern(Pattern) {};
- bool operator() (pkgCache::PkgIterator const &Pkg);
- bool operator() (pkgCache::GrpIterator const &Grp);
- ~PackageNameMatchesFnmatch() {};
-};
- /*}}}*/
-// PackageArchitectureMatchesSpecification /*{{{*/
-/** \class PackageArchitectureMatchesSpecification
- \brief matching against architecture specification strings
-
- The strings are of the format \<kernel\>-\<cpu\> where either component,
- or the whole string, can be the wildcard "any" as defined in
- debian-policy §11.1 "Architecture specification strings".
-
- Examples: i386, mipsel, linux-any, any-amd64, any */
-class PackageArchitectureMatchesSpecification {
- std::string literal;
- std::string complete;
- bool isPattern;
- /** \brief dpointer placeholder (for later in case we need it) */
- void *d;
-public:
- /** \brief matching against architecture specification strings
- *
- * @param pattern is the architecture specification string
- * @param isPattern defines if the given \b pattern is a
- * architecture specification pattern to match others against
- * or if it is the fixed string and matched against patterns
- */
- PackageArchitectureMatchesSpecification(std::string const &pattern, bool const isPattern = true);
- bool operator() (char const * const &arch);
- bool operator() (pkgCache::PkgIterator const &Pkg);
- bool operator() (pkgCache::VerIterator const &Ver);
- ~PackageArchitectureMatchesSpecification();
-};
-
-#else
-
class PackageMatcher {
public:
- virtual bool operator() (pkgCache::PkgIterator const &Pkg) { return false; };
- virtual bool operator() (pkgCache::GrpIterator const &Grp) { return false; };
- virtual bool operator() (pkgCache::VerIterator const &Ver) { return false; };
+ virtual bool operator() (pkgCache::PkgIterator const &/*Pkg*/) {
+ return false; };
+ virtual bool operator() (pkgCache::GrpIterator const &/*Grp*/) {
+ return false; };
+ virtual bool operator() (pkgCache::VerIterator const &/*Ver*/) {
+ return false; };
virtual ~PackageMatcher() {};
};
@@ -139,7 +82,6 @@ public:
virtual bool operator() (pkgCache::VerIterator const &Ver);
virtual ~PackageArchitectureMatchesSpecification();
};
-#endif
/*}}}*/
}
}
diff --git a/apt-pkg/cacheset.cc b/apt-pkg/cacheset.cc
index d453a2bfb..5d7f28515 100644
--- a/apt-pkg/cacheset.cc
+++ b/apt-pkg/cacheset.cc
@@ -321,7 +321,8 @@ bool PackageContainerInterface::FromString(PackageContainerInterface * const pci
if (FromGroup(pci, Cache, str, helper) == false &&
FromTask(pci, Cache, str, helper) == false &&
#if (APT_PKG_MAJOR >= 4 && APT_PKG_MINOR >= 13)
- FromFnmatch(pci, Cache, str, helper) == false)
+ // FIXME: hm, hm, regexp/fnmatch incompatible?
+ FromFnmatch(pci, Cache, str, helper) == false &&
#endif
FromRegEx(pci, Cache, str, helper) == false)
{
@@ -391,6 +392,8 @@ bool VersionContainerInterface::FromModifierCommandLine(unsigned short &modID,
CacheSetHelper &helper) {
Version select = NEWEST;
std::string str = cmdline;
+ if (unlikely(str.empty() == true))
+ return false;
bool modifierPresent = false;
unsigned short fallback = modID;
for (std::list<Modifier>::const_iterator mod = mods.begin();
@@ -400,8 +403,8 @@ bool VersionContainerInterface::FromModifierCommandLine(unsigned short &modID,
size_t const alength = strlen(mod->Alias);
switch(mod->Pos) {
case Modifier::POSTFIX:
- if (str.compare(str.length() - alength, alength,
- mod->Alias, 0, alength) != 0)
+ if (str.length() <= alength ||
+ str.compare(str.length() - alength, alength, mod->Alias, 0, alength) != 0)
continue;
str.erase(str.length() - alength);
modID = mod->ID;
@@ -608,7 +611,7 @@ void CacheSetHelper::canNotFindRegEx(PackageContainerInterface * const /*pci*/,
}
#if (APT_PKG_MAJOR >= 4 && APT_PKG_MINOR >= 13)
// canNotFindFnmatch - handle the case no package is found by a fnmatch /*{{{*/
-void CacheSetHelper::canNotFindFnmatch(PackageContainerInterface * const pci, pkgCacheFile &Cache, std::string pattern) {
+ void CacheSetHelper::canNotFindFnmatch(PackageContainerInterface * const /*pci*/, pkgCacheFile &/*Cache*/, std::string pattern) {
if (ShowError == true)
_error->Insert(ErrorType, _("Couldn't find any package by glob '%s'"), pattern.c_str());
}
@@ -674,8 +677,8 @@ APT_CONST void CacheSetHelper::showRegExSelection(pkgCache::PkgIterator const &/
/*}}}*/
#if (APT_PKG_MAJOR >= 4 && APT_PKG_MINOR >= 13)
// showFnmatchSelection /*{{{*/
-APT_CONST void CacheSetHelper::showFnmatchSelection(pkgCache::PkgIterator const &pkg,
- std::string const &pattern) {
+APT_CONST void CacheSetHelper::showFnmatchSelection(pkgCache::PkgIterator const &/*pkg*/,
+ std::string const &/*pattern*/) {
}
/*}}}*/
#endif
diff --git a/apt-pkg/cdrom.cc b/apt-pkg/cdrom.cc
index 2635ede76..a5ad6a9ff 100644
--- a/apt-pkg/cdrom.cc
+++ b/apt-pkg/cdrom.cc
@@ -563,6 +563,15 @@ bool pkgCdrom::WriteSourceList(string Name,vector<string> &List,bool Source)
return true;
}
/*}}}*/
+bool pkgCdrom::UnmountCDROM(std::string const &CDROM, pkgCdromStatus * const log)/*{{{*/
+{
+ if (_config->FindB("APT::CDROM::NoMount",false) == true)
+ return true;
+ if (log != NULL)
+ log->Update(_("Unmounting CD-ROM...\n"), STEP_LAST);
+ return UnmountCdrom(CDROM);
+}
+ /*}}}*/
bool pkgCdrom::MountAndIdentCDROM(Configuration &Database, std::string &CDROM, std::string &ident, pkgCdromStatus * const log, bool const interactive)/*{{{*/
{
// Startup
@@ -583,9 +592,7 @@ bool pkgCdrom::MountAndIdentCDROM(Configuration &Database, std::string &CDROM, s
{
if (interactive == true)
{
- if(log != NULL)
- log->Update(_("Unmounting CD-ROM...\n"), STEP_LAST);
- UnmountCdrom(CDROM);
+ UnmountCDROM(CDROM, log);
if(log != NULL)
{
@@ -605,6 +612,9 @@ bool pkgCdrom::MountAndIdentCDROM(Configuration &Database, std::string &CDROM, s
return _error->Error("Failed to mount the cdrom.");
}
+ if (IsMounted(CDROM) == false)
+ return _error->Error("Failed to mount the cdrom.");
+
// Hash the CD to get an ID
if (log != NULL)
log->Update(_("Identifying... "), STEP_IDENT);
@@ -614,6 +624,7 @@ bool pkgCdrom::MountAndIdentCDROM(Configuration &Database, std::string &CDROM, s
ident = "";
if (log != NULL)
log->Update("\n");
+ UnmountCDROM(CDROM, NULL);
return false;
}
@@ -629,8 +640,11 @@ bool pkgCdrom::MountAndIdentCDROM(Configuration &Database, std::string &CDROM, s
if (FileExists(DFile) == true)
{
if (ReadConfigFile(Database,DFile) == false)
+ {
+ UnmountCDROM(CDROM, NULL);
return _error->Error("Unable to read the cdrom database %s",
DFile.c_str());
+ }
}
return true;
}
@@ -651,13 +665,7 @@ bool pkgCdrom::Ident(string &ident, pkgCdromStatus *log) /*{{{*/
}
// Unmount and finish
- if (_config->FindB("APT::CDROM::NoMount",false) == false)
- {
- if (log != NULL)
- log->Update(_("Unmounting CD-ROM...\n"), STEP_LAST);
- UnmountCdrom(CDROM);
- }
-
+ UnmountCDROM(CDROM, log);
return true;
}
/*}}}*/
@@ -682,11 +690,15 @@ bool pkgCdrom::Add(pkgCdromStatus *log) /*{{{*/
{
if (log != NULL)
log->Update("\n");
+ UnmountCDROM(CDROM, NULL);
return false;
}
if (chdir(StartDir.c_str()) != 0)
+ {
+ UnmountCDROM(CDROM, NULL);
return _error->Errno("chdir","Unable to change to %s", StartDir.c_str());
+ }
if (_config->FindB("Debug::aptcdrom",false) == true)
{
@@ -728,8 +740,7 @@ bool pkgCdrom::Add(pkgCdromStatus *log) /*{{{*/
if (List.empty() == true && SourceList.empty() == true)
{
- if (_config->FindB("APT::CDROM::NoMount",false) == false)
- UnmountCdrom(CDROM);
+ UnmountCDROM(CDROM, NULL);
return _error->Error(_("Unable to locate any package files, perhaps this is not a Debian Disc or the wrong architecture?"));
}
@@ -769,14 +780,14 @@ bool pkgCdrom::Add(pkgCdromStatus *log) /*{{{*/
{
if(log == NULL)
{
- if (_config->FindB("APT::CDROM::NoMount",false) == false)
- UnmountCdrom(CDROM);
+ UnmountCDROM(CDROM, NULL);
return _error->Error("No disc name found and no way to ask for it");
}
while(true) {
if(!log->AskCdromName(Name)) {
// user canceld
+ UnmountCDROM(CDROM, NULL);
return false;
}
cout << "Name: '" << Name << "'" << endl;
@@ -813,7 +824,10 @@ bool pkgCdrom::Add(pkgCdromStatus *log) /*{{{*/
string const partialListDir = listDir + "partial/";
if (CreateAPTDirectoryIfNeeded(_config->FindDir("Dir::State"), partialListDir) == false &&
CreateAPTDirectoryIfNeeded(listDir, partialListDir) == false)
+ {
+ UnmountCDROM(CDROM, NULL);
return _error->Errno("cdrom", _("List directory %spartial is missing."), listDir.c_str());
+ }
// take care of the signatures and copy them if they are ok
// (we do this before PackageCopy as it modifies "List" and "SourceList")
@@ -827,7 +841,10 @@ bool pkgCdrom::Add(pkgCdromStatus *log) /*{{{*/
if (Copy.CopyPackages(CDROM,Name,List, log) == false ||
SrcCopy.CopyPackages(CDROM,Name,SourceList, log) == false ||
TransCopy.CopyTranslations(CDROM,Name,TransList, log) == false)
+ {
+ UnmountCDROM(CDROM, NULL);
return false;
+ }
// reduce the List so that it takes less space in sources.list
ReduceSourcelist(CDROM,List);
@@ -837,13 +854,19 @@ bool pkgCdrom::Add(pkgCdromStatus *log) /*{{{*/
if (_config->FindB("APT::cdrom::NoAct",false) == false)
{
if (WriteDatabase(Database) == false)
+ {
+ UnmountCDROM(CDROM, NULL);
return false;
-
+ }
+
if(log != NULL)
log->Update(_("Writing new source list\n"), STEP_WRITE);
if (WriteSourceList(Name,List,false) == false ||
WriteSourceList(Name,SourceList,true) == false)
+ {
+ UnmountCDROM(CDROM, NULL);
return false;
+ }
}
// Print the sourcelist entries
@@ -855,8 +878,7 @@ bool pkgCdrom::Add(pkgCdromStatus *log) /*{{{*/
string::size_type Space = (*I).find(' ');
if (Space == string::npos)
{
- if (_config->FindB("APT::CDROM::NoMount",false) == false)
- UnmountCdrom(CDROM);
+ UnmountCDROM(CDROM, NULL);
return _error->Error("Internal error");
}
@@ -874,8 +896,7 @@ bool pkgCdrom::Add(pkgCdromStatus *log) /*{{{*/
string::size_type Space = (*I).find(' ');
if (Space == string::npos)
{
- if (_config->FindB("APT::CDROM::NoMount",false) == false)
- UnmountCdrom(CDROM);
+ UnmountCDROM(CDROM, NULL);
return _error->Error("Internal error");
}
@@ -888,12 +909,7 @@ bool pkgCdrom::Add(pkgCdromStatus *log) /*{{{*/
}
// Unmount and finish
- if (_config->FindB("APT::CDROM::NoMount",false) == false) {
- if (log != NULL)
- log->Update(_("Unmounting CD-ROM...\n"), STEP_LAST);
- UnmountCdrom(CDROM);
- }
-
+ UnmountCDROM(CDROM, log);
return true;
}
/*}}}*/
diff --git a/apt-pkg/cdrom.h b/apt-pkg/cdrom.h
index 0f2c2cd02..bd0902176 100644
--- a/apt-pkg/cdrom.h
+++ b/apt-pkg/cdrom.h
@@ -77,6 +77,7 @@ class pkgCdrom /*{{{*/
private:
APT_HIDDEN bool MountAndIdentCDROM(Configuration &Database, std::string &CDROM,
std::string &ident, pkgCdromStatus * const log, bool const interactive);
+ APT_HIDDEN bool UnmountCDROM(std::string const &CDROM, pkgCdromStatus * const log);
};
/*}}}*/
diff --git a/apt-pkg/contrib/configuration.cc b/apt-pkg/contrib/configuration.cc
index 00f6ad0f9..fbe180f8e 100644
--- a/apt-pkg/contrib/configuration.cc
+++ b/apt-pkg/contrib/configuration.cc
@@ -254,7 +254,9 @@ string Configuration::FindDir(const char *Name,const char *Default) const
// ---------------------------------------------------------------------
/* Returns a vector of config values under the given item */
#if (APT_PKG_MAJOR >= 4 && APT_PKG_MINOR < 13)
-vector<string> Configuration::FindVector(const char *Name) const { return FindVector(Name, ""); }
+vector<string> Configuration::FindVector(const char *Name) const {
+ return FindVector(Name, "");
+}
#endif
vector<string> Configuration::FindVector(const char *Name, std::string const &Default) const
{
diff --git a/apt-pkg/contrib/configuration.h b/apt-pkg/contrib/configuration.h
index c256139f4..6345c8a5d 100644
--- a/apt-pkg/contrib/configuration.h
+++ b/apt-pkg/contrib/configuration.h
@@ -84,12 +84,10 @@ class Configuration
* \param Default list of values separated by commas */
std::vector<std::string> FindVector(const char *Name, std::string const &Default) const;
std::vector<std::string> FindVector(std::string const &Name, std::string const &Default) const { return FindVector(Name.c_str(), Default); };
-#if (APT_PKG_MAJOR >= 4 && APT_PKG_MINOR >= 13)
- std::vector<std::string> FindVector(const char *Name) const { return FindVector(Name, ""); };
-#else
+#if (APT_PKG_MAJOR >= 4 && APT_PKG_MINOR < 13)
std::vector<std::string> FindVector(const char *Name) const;
#endif
- std::vector<std::string> FindVector(std::string const &Name) const { return FindVector(Name.c_str(), ""); };
+ std::vector<std::string> FindVector(std::string const &Name="") const { return FindVector(Name.c_str(), ""); };
int FindI(const char *Name,int const &Default = 0) const;
int FindI(std::string const &Name,int const &Default = 0) const {return FindI(Name.c_str(),Default);};
bool FindB(const char *Name,bool const &Default = false) const;
diff --git a/apt-pkg/contrib/fileutl.cc b/apt-pkg/contrib/fileutl.cc
index 188bb87ee..02b30dc1f 100644
--- a/apt-pkg/contrib/fileutl.cc
+++ b/apt-pkg/contrib/fileutl.cc
@@ -58,13 +58,10 @@
#include <bzlib.h>
#endif
#ifdef HAVE_LZMA
- #include <stdint.h>
#include <lzma.h>
#endif
-
-#ifdef WORDS_BIGENDIAN
-#include <inttypes.h>
-#endif
+#include <endian.h>
+#include <stdint.h>
#include <apti18n.h>
/*}}}*/
@@ -659,6 +656,22 @@ string flCombine(string Dir,string File)
return Dir + '/' + File;
}
/*}}}*/
+// flAbsPath - Return the absolute path of the filename /*{{{*/
+// ---------------------------------------------------------------------
+/* */
+string flAbsPath(string File)
+{
+ char *p = realpath(File.c_str(), NULL);
+ if (p == NULL)
+ {
+ _error->Errno("realpath", "flAbsPath failed");
+ return "";
+ }
+ std::string AbsPath(p);
+ free(p);
+ return AbsPath;
+}
+ /*}}}*/
// SetCloseExec - Set the close on exec flag /*{{{*/
// ---------------------------------------------------------------------
/* */
@@ -839,6 +852,27 @@ bool ExecWait(pid_t Pid,const char *Name,bool Reap)
}
/*}}}*/
+
+// StartsWithGPGClearTextSignature - Check if a file is Pgp/GPG clearsigned /*{{{*/
+// ---------------------------------------------------------------------
+/* */
+bool StartsWithGPGClearTextSignature(string const &FileName)
+{
+ static const char* SIGMSG = "-----BEGIN PGP SIGNED MESSAGE-----\n";
+ char buffer[strlen(SIGMSG)+1];
+ FILE* gpg = fopen(FileName.c_str(), "r");
+ if (gpg == NULL)
+ return false;
+
+ char const * const test = fgets(buffer, sizeof(buffer), gpg);
+ fclose(gpg);
+ if (test == NULL || strcmp(buffer, SIGMSG) != 0)
+ return false;
+
+ return true;
+}
+
+
class FileFdPrivate { /*{{{*/
public:
#ifdef HAVE_ZLIB
@@ -958,10 +992,10 @@ class FileFdPrivate { /*{{{*/
// FileFd::Open - Open a file /*{{{*/
// ---------------------------------------------------------------------
/* The most commonly used open mode combinations are given with Mode */
-bool FileFd::Open(string FileName,unsigned int const Mode,CompressMode Compress, unsigned long const Perms)
+bool FileFd::Open(string FileName,unsigned int const Mode,CompressMode Compress, unsigned long const AccessMode)
{
if (Mode == ReadOnlyGzip)
- return Open(FileName, ReadOnly, Gzip, Perms);
+ return Open(FileName, ReadOnly, Gzip, AccessMode);
if (Compress == Auto && (Mode & WriteOnly) == WriteOnly)
return FileFdError("Autodetection on %s only works in ReadOnly openmode!", FileName.c_str());
@@ -1028,9 +1062,9 @@ bool FileFd::Open(string FileName,unsigned int const Mode,CompressMode Compress,
if (compressor == compressors.end())
return FileFdError("Can't find a match for specified compressor mode for file %s", FileName.c_str());
- return Open(FileName, Mode, *compressor, Perms);
+ return Open(FileName, Mode, *compressor, AccessMode);
}
-bool FileFd::Open(string FileName,unsigned int const Mode,APT::Configuration::Compressor const &compressor, unsigned long const Perms)
+bool FileFd::Open(string FileName,unsigned int const Mode,APT::Configuration::Compressor const &compressor, unsigned long const AccessMode)
{
Close();
Flags = AutoClose;
@@ -1080,11 +1114,18 @@ bool FileFd::Open(string FileName,unsigned int const Mode,APT::Configuration::Co
TemporaryFileName = string(name);
free(name);
- if(Perms != 600 && fchmod(iFd, Perms) == -1)
+ // umask() will always set the umask and return the previous value, so
+ // we first set the umask and then reset it to the old value
+ mode_t const CurrentUmask = umask(0);
+ umask(CurrentUmask);
+ // calculate the actual file permissions (just like open/creat)
+ mode_t const FilePermissions = (AccessMode & ~CurrentUmask);
+
+ if(fchmod(iFd, FilePermissions) == -1)
return FileFdErrno("fchmod", "Could not change permissions for temporary file %s", TemporaryFileName.c_str());
}
else
- iFd = open(FileName.c_str(), fileflags, Perms);
+ iFd = open(FileName.c_str(), fileflags, AccessMode);
this->FileName = FileName;
if (iFd == -1 || OpenInternDescriptor(Mode, compressor) == false)
@@ -1353,7 +1394,10 @@ bool FileFd::OpenInternDescriptor(unsigned int const Mode, APT::Configuration::C
Args.push_back(a->c_str());
if (Comp == false && FileName.empty() == false)
{
- Args.push_back("--stdout");
+ // commands not needing arguments, do not need to be told about using standard output
+ // in reality, only testcases with tools like cat, rev, rot13, … are able to trigger this
+ if (compressor.CompressArgs.empty() == false && compressor.UncompressArgs.empty() == false)
+ Args.push_back("--stdout");
if (TemporaryFileName.empty() == false)
Args.push_back(TemporaryFileName.c_str());
else
@@ -1646,6 +1690,8 @@ bool FileFd::Write(int Fd, const void *From, unsigned long long Size)
/* */
bool FileFd::Seek(unsigned long long To)
{
+ Flags &= ~HitEof;
+
if (d != NULL && (d->pipe == true || d->InternalStream() == true))
{
// Our poor man seeking in pipes is costly, so try to avoid it
@@ -1705,7 +1751,6 @@ bool FileFd::Skip(unsigned long long Over)
{
if (d != NULL && (d->pipe == true || d->InternalStream() == true))
{
- d->seekpos += Over;
char buffer[1024];
while (Over != 0)
{
@@ -1869,19 +1914,13 @@ unsigned long long FileFd::Size()
FileFdErrno("lseek","Unable to seek to end of gzipped file");
return 0;
}
- size = 0;
+ uint32_t size = 0;
if (read(iFd, &size, 4) != 4)
{
FileFdErrno("read","Unable to read original size of gzipped file");
return 0;
}
-
-#ifdef WORDS_BIGENDIAN
- uint32_t tmp_size = size;
- uint8_t const * const p = (uint8_t const * const) &tmp_size;
- tmp_size = (p[3] << 24) | (p[2] << 16) | (p[1] << 8) | p[0];
- size = tmp_size;
-#endif
+ size = le32toh(size);
if (lseek(iFd, oldPos, SEEK_SET) < 0)
{
@@ -1909,7 +1948,6 @@ bool FileFd::Close()
{
if ((Flags & Compressed) != Compressed && iFd > 0 && close(iFd) != 0)
Res &= _error->Errno("close",_("Problem closing the file %s"), FileName.c_str());
-
if (d != NULL)
{
Res &= d->CloseDown(FileName);
@@ -2036,6 +2074,31 @@ std::string GetTempDir()
return string(tmpdir);
}
+FileFd* GetTempFile(std::string const &Prefix, bool ImmediateUnlink)
+{
+ char fn[512];
+ FileFd *Fd = new FileFd();
+
+ std::string tempdir = GetTempDir();
+ snprintf(fn, sizeof(fn), "%s/%s.XXXXXX",
+ tempdir.c_str(), Prefix.c_str());
+ int fd = mkstemp(fn);
+ if(ImmediateUnlink)
+ unlink(fn);
+ if (fd < 0)
+ {
+ _error->Errno("GetTempFile",_("Unable to mkstemp %s"), fn);
+ return NULL;
+ }
+ if (!Fd->OpenDescriptor(fd, FileFd::WriteOnly, FileFd::None, true))
+ {
+ _error->Errno("GetTempFile",_("Unable to write to %s"),fn);
+ return NULL;
+ }
+
+ return Fd;
+}
+
bool Rename(std::string From, std::string To)
{
if (rename(From.c_str(),To.c_str()) != 0)
@@ -2046,3 +2109,58 @@ bool Rename(std::string From, std::string To)
}
return true;
}
+
+bool Popen(const char* Args[], FileFd &Fd, pid_t &Child, FileFd::OpenMode Mode)
+{
+ int fd;
+ if (Mode != FileFd::ReadOnly && Mode != FileFd::WriteOnly)
+ return _error->Error("Popen supports ReadOnly (x)or WriteOnly mode only");
+
+ int Pipe[2] = {-1, -1};
+ if(pipe(Pipe) != 0)
+ {
+ return _error->Errno("pipe", _("Failed to create subprocess IPC"));
+ return NULL;
+ }
+ std::set<int> keep_fds;
+ keep_fds.insert(Pipe[0]);
+ keep_fds.insert(Pipe[1]);
+ Child = ExecFork(keep_fds);
+ if(Child < 0)
+ return _error->Errno("fork", "Failed to fork");
+ if(Child == 0)
+ {
+ if(Mode == FileFd::ReadOnly)
+ {
+ close(Pipe[0]);
+ fd = Pipe[1];
+ }
+ else if(Mode == FileFd::WriteOnly)
+ {
+ close(Pipe[1]);
+ fd = Pipe[0];
+ }
+
+ if(Mode == FileFd::ReadOnly)
+ {
+ dup2(fd, 1);
+ dup2(fd, 2);
+ } else if(Mode == FileFd::WriteOnly)
+ dup2(fd, 0);
+
+ execv(Args[0], (char**)Args);
+ _exit(100);
+ }
+ if(Mode == FileFd::ReadOnly)
+ {
+ close(Pipe[1]);
+ fd = Pipe[0];
+ } else if(Mode == FileFd::WriteOnly)
+ {
+ close(Pipe[0]);
+ fd = Pipe[1];
+ }
+ Fd.OpenDescriptor(fd, Mode, FileFd::None, true);
+
+ return true;
+}
diff --git a/apt-pkg/contrib/fileutl.h b/apt-pkg/contrib/fileutl.h
index f25ed3622..0b4d94885 100644
--- a/apt-pkg/contrib/fileutl.h
+++ b/apt-pkg/contrib/fileutl.h
@@ -103,10 +103,10 @@ class FileFd
return T;
}
- bool Open(std::string FileName,unsigned int const Mode,CompressMode Compress,unsigned long const Perms = 0666);
- bool Open(std::string FileName,unsigned int const Mode,APT::Configuration::Compressor const &compressor,unsigned long const Perms = 0666);
- inline bool Open(std::string const &FileName,unsigned int const Mode, unsigned long const Perms = 0666) {
- return Open(FileName, Mode, None, Perms);
+ bool Open(std::string FileName,unsigned int const Mode,CompressMode Compress,unsigned long const AccessMode = 0666);
+ bool Open(std::string FileName,unsigned int const Mode,APT::Configuration::Compressor const &compressor,unsigned long const AccessMode = 0666);
+ inline bool Open(std::string const &FileName,unsigned int const Mode, unsigned long const AccessMode = 0666) {
+ return Open(FileName, Mode, None, AccessMode);
};
bool OpenDescriptor(int Fd, unsigned int const Mode, CompressMode Compress, bool AutoClose=false);
bool OpenDescriptor(int Fd, unsigned int const Mode, APT::Configuration::Compressor const &compressor, bool AutoClose=false);
@@ -129,13 +129,13 @@ class FileFd
inline bool IsCompressed() {return (Flags & Compressed) == Compressed;};
inline std::string &Name() {return FileName;};
- FileFd(std::string FileName,unsigned int const Mode,unsigned long Perms = 0666) : iFd(-1), Flags(0), d(NULL)
+ FileFd(std::string FileName,unsigned int const Mode,unsigned long AccessMode = 0666) : iFd(-1), Flags(0), d(NULL)
{
- Open(FileName,Mode, None, Perms);
+ Open(FileName,Mode, None, AccessMode);
};
- FileFd(std::string FileName,unsigned int const Mode, CompressMode Compress, unsigned long Perms = 0666) : iFd(-1), Flags(0), d(NULL)
+ FileFd(std::string FileName,unsigned int const Mode, CompressMode Compress, unsigned long AccessMode = 0666) : iFd(-1), Flags(0), d(NULL)
{
- Open(FileName,Mode, Compress, Perms);
+ Open(FileName,Mode, Compress, AccessMode);
};
FileFd() : iFd(-1), Flags(AutoClose), d(NULL) {};
FileFd(int const Fd, unsigned int const Mode = ReadWrite, CompressMode Compress = None) : iFd(-1), Flags(0), d(NULL)
@@ -168,6 +168,8 @@ time_t GetModificationTime(std::string const &Path);
bool Rename(std::string From, std::string To);
std::string GetTempDir();
+FileFd* GetTempFile(std::string const &Prefix = "",
+ bool ImmediateUnlink = true);
/** \brief Ensure the existence of the given Path
*
@@ -191,6 +193,9 @@ pid_t ExecFork(std::set<int> keep_fds);
void MergeKeepFdsFromConfiguration(std::set<int> &keep_fds);
bool ExecWait(pid_t Pid,const char *Name,bool Reap = false);
+// check if the given file starts with a PGP cleartext signature
+bool StartsWithGPGClearTextSignature(std::string const &FileName);
+
// File string manipulators
std::string flNotDir(std::string File);
std::string flNotFile(std::string File);
@@ -198,7 +203,23 @@ std::string flNoLink(std::string File);
std::string flExtension(std::string File);
std::string flCombine(std::string Dir,std::string File);
+/** \brief Takes a file path and returns the absolute path
+ */
+std::string flAbsPath(std::string File);
+
// simple c++ glob
std::vector<std::string> Glob(std::string const &pattern, int flags=0);
+/** \brief Popen() implementation that execv() instead of using a shell
+ *
+ * \param Args the execv style command to run
+ * \param FileFd is a referenz to the FileFd to use for input or output
+ * \param Child a reference to the integer that stores the child pid
+ * Note that you must call ExecWait() or similar to cleanup
+ * \param Mode is either FileFd::ReadOnly or FileFd::WriteOnly
+ * \return true on success, false on failure with _error set
+ */
+bool Popen(const char* Args[], FileFd &Fd, pid_t &Child, FileFd::OpenMode Mode);
+
+
#endif
diff --git a/apt-pkg/contrib/hashes.cc b/apt-pkg/contrib/hashes.cc
index 1fce0d75f..15f83615d 100644
--- a/apt-pkg/contrib/hashes.cc
+++ b/apt-pkg/contrib/hashes.cc
@@ -133,7 +133,7 @@ bool Hashes::AddFD(int const Fd,unsigned long long Size, bool const addMD5,
bool const addSHA1, bool const addSHA256, bool const addSHA512)
{
unsigned char Buf[64*64];
- bool const ToEOF = (Size == 0);
+ bool const ToEOF = (Size == UntilEOF);
while (Size != 0 || ToEOF)
{
unsigned long long n = sizeof(Buf);
diff --git a/apt-pkg/contrib/hashes.h b/apt-pkg/contrib/hashes.h
index 5cd1af03b..7a62f8a8f 100644
--- a/apt-pkg/contrib/hashes.h
+++ b/apt-pkg/contrib/hashes.h
@@ -78,6 +78,8 @@ class Hashes
SHA256Summation SHA256;
SHA512Summation SHA512;
+ static const int UntilEOF = 0;
+
inline bool Add(const unsigned char *Data,unsigned long long Size)
{
return MD5.Add(Data,Size) && SHA1.Add(Data,Size) && SHA256.Add(Data,Size) && SHA512.Add(Data,Size);
diff --git a/apt-pkg/contrib/macros.h b/apt-pkg/contrib/macros.h
index 2d6448e5e..b268ce24c 100644
--- a/apt-pkg/contrib/macros.h
+++ b/apt-pkg/contrib/macros.h
@@ -138,7 +138,7 @@
// Non-ABI-Breaks should only increase RELEASE number.
// See also buildlib/libversion.mak
#define APT_PKG_MAJOR 4
-#define APT_PKG_MINOR 12
+#define APT_PKG_MINOR 13
#define APT_PKG_RELEASE 0
#endif
diff --git a/apt-pkg/contrib/netrc.cc b/apt-pkg/contrib/netrc.cc
index feaed67c8..1e3778f45 100644
--- a/apt-pkg/contrib/netrc.cc
+++ b/apt-pkg/contrib/netrc.cc
@@ -152,18 +152,6 @@ static int parsenetrc_string (char *host, std::string &login, std::string &passw
return retcode;
}
-// for some unknown reason this method is exported so keep a compatible interface for now …
-int parsenetrc (char *host, char *login, char *password, char *netrcfile = NULL)
-{
- std::string login_string, password_string;
- int const ret = parsenetrc_string(host, login_string, password_string, netrcfile);
- if (ret < 0)
- return ret;
- strncpy(login, login_string.c_str(), LOGINSIZE - 1);
- strncpy(password, password_string.c_str(), PASSWORDSIZE - 1);
- return ret;
-}
-
void maybe_add_auth (URI &Uri, string NetRCFile)
{
diff --git a/apt-pkg/contrib/netrc.h b/apt-pkg/contrib/netrc.h
index dbeb45386..b5b56f5d4 100644
--- a/apt-pkg/contrib/netrc.h
+++ b/apt-pkg/contrib/netrc.h
@@ -27,9 +27,5 @@
class URI;
-// FIXME: kill this export on the next ABI break - strongly doubt its in use anyway
-// outside of the apt itself, its really a internal interface
-APT_DEPRECATED int parsenetrc (char *host, char *login, char *password, char *filename);
-
void maybe_add_auth (URI &Uri, std::string NetRCFile);
#endif
diff --git a/apt-pkg/deb/debindexfile.cc b/apt-pkg/deb/debindexfile.cc
index bb6884123..37efa05b0 100644
--- a/apt-pkg/deb/debindexfile.cc
+++ b/apt-pkg/deb/debindexfile.cc
@@ -30,6 +30,7 @@
#include <apt-pkg/pkgcachegen.h>
#include <apt-pkg/pkgrecords.h>
#include <apt-pkg/srcrecords.h>
+#include <apt-pkg/sptr.h>
#include <stdio.h>
#include <iostream>
@@ -667,6 +668,96 @@ APT_CONST bool debStatusIndex::Exists() const
}
/*}}}*/
+// debDebPkgFile - Single .deb file /*{{{*/
+// ---------------------------------------------------------------------
+debDebPkgFileIndex::debDebPkgFileIndex(std::string DebFile)
+ : pkgIndexFile(true), DebFile(DebFile)
+{
+ DebFileFullPath = flAbsPath(DebFile);
+}
+
+std::string debDebPkgFileIndex::ArchiveURI(std::string /*File*/) const
+{
+ return "file:" + DebFileFullPath;
+}
+
+bool debDebPkgFileIndex::Exists() const
+{
+ return FileExists(DebFile);
+}
+bool debDebPkgFileIndex::Merge(pkgCacheGenerator& Gen, OpProgress* Prog) const
+{
+ if(Prog)
+ Prog->SubProgress(0, "Reading deb file");
+
+ // get the control data out of the deb file vid dpkg -I
+ // ... can I haz libdpkg?
+ const char *Args[5] = {"/usr/bin/dpkg",
+ "-I",
+ DebFile.c_str(),
+ "control",
+ NULL};
+ FileFd PipeFd;
+ pid_t Child;
+ if(Popen(Args, PipeFd, Child, FileFd::ReadOnly) == false)
+ return _error->Error("Popen failed");
+ // FIXME: static buffer
+ char buf[8*1024];
+ unsigned long long n = 0;
+ if(PipeFd.Read(buf, sizeof(buf)-1, &n) == false)
+ return _error->Errno("read", "Failed to read dpkg pipe");
+ ExecWait(Child, "Popen");
+
+ // now write the control data to a tempfile
+ SPtr<FileFd> DebControl = GetTempFile("deb-file-" + DebFile);
+ if(DebControl == NULL)
+ return false;
+ DebControl->Write(buf, n);
+ // append size of the file
+ FileFd Fd(DebFile, FileFd::ReadOnly);
+ string Size;
+ strprintf(Size, "Size: %llu\n", Fd.Size());
+ DebControl->Write(Size.c_str(), Size.size());
+ // and rewind for the listparser
+ DebControl->Seek(0);
+
+ // and give it to the list parser
+ debDebFileParser Parser(DebControl, DebFile);
+ if(Gen.SelectFile(DebFile, "local", *this) == false)
+ return _error->Error("Problem with SelectFile %s", DebFile.c_str());
+
+ pkgCache::PkgFileIterator File = Gen.GetCurFile();
+ File->Size = DebControl->Size();
+ File->mtime = DebControl->ModificationTime();
+
+ if (Gen.MergeList(Parser) == false)
+ return _error->Error("Problem with MergeLister for %s", DebFile.c_str());
+
+ return true;
+}
+pkgCache::PkgFileIterator debDebPkgFileIndex::FindInCache(pkgCache &Cache) const
+{
+ // FIXME: we could simply always return pkgCache::PkgFileIterator(Cache);
+ // to indicate its never in the cache which will force a Merge()
+ pkgCache::PkgFileIterator File = Cache.FileBegin();
+ for (; File.end() == false; ++File)
+ {
+ if (File.FileName() == NULL || DebFile != File.FileName())
+ continue;
+
+ return File;
+ }
+
+ return File;
+}
+unsigned long debDebPkgFileIndex::Size() const
+{
+ struct stat buf;
+ if(stat(DebFile.c_str(), &buf) != 0)
+ return 0;
+ return buf.st_size;
+}
+ /*}}}*/
// debDscFileIndex stuff
debDscFileIndex::debDscFileIndex(std::string &DscFile)
@@ -735,6 +826,15 @@ class debIFTypeStatus : public pkgIndexFile::Type
};
debIFTypeStatus() {Label = "Debian dpkg status file";};
};
+class debIFTypeDebPkgFile : public pkgIndexFile::Type
+{
+ public:
+ virtual pkgRecords::Parser *CreatePkgParser(pkgCache::PkgFileIterator File) const
+ {
+ return new debDebFileRecordParser(File.FileName(),*File.Cache());
+ };
+ debIFTypeDebPkgFile() {Label = "deb Package file";};
+};
class debIFTypeDscFile : public pkgIndexFile::Type
{
public:
@@ -758,6 +858,7 @@ static debIFTypeSrc _apt_Src;
static debIFTypePkg _apt_Pkg;
static debIFTypeTrans _apt_Trans;
static debIFTypeStatus _apt_Status;
+static debIFTypeDebPkgFile _apt_DebPkgFile;
// file based pseudo indexes
static debIFTypeDscFile _apt_DscFile;
static debIFTypeDebianSourceDir _apt_DebianSourceDir;
@@ -778,6 +879,10 @@ const pkgIndexFile::Type *debStatusIndex::GetType() const
{
return &_apt_Status;
}
+const pkgIndexFile::Type *debDebPkgFileIndex::GetType() const
+{
+ return &_apt_DebPkgFile;
+}
const pkgIndexFile::Type *debDscFileIndex::GetType() const
{
return &_apt_DscFile;
@@ -786,5 +891,4 @@ const pkgIndexFile::Type *debDebianSourceDirIndex::GetType() const
{
return &_apt_DebianSourceDir;
}
-
/*}}}*/
diff --git a/apt-pkg/deb/debindexfile.h b/apt-pkg/deb/debindexfile.h
index 64ca558d2..18322dc1b 100644
--- a/apt-pkg/deb/debindexfile.h
+++ b/apt-pkg/deb/debindexfile.h
@@ -164,6 +164,36 @@ class debSourcesIndex : public pkgIndexFile
virtual ~debSourcesIndex() {};
};
+class debDebPkgFileIndex : public pkgIndexFile
+{
+ private:
+ void *d;
+ std::string DebFile;
+ std::string DebFileFullPath;
+
+ public:
+ virtual const Type *GetType() const APT_CONST;
+
+ virtual std::string Describe(bool /*Short*/) const {
+ return DebFile;
+ }
+
+ // Interface for the Cache Generator
+ virtual bool Exists() const;
+ virtual bool HasPackages() const {
+ return true;
+ };
+ virtual unsigned long Size() const;
+ virtual bool Merge(pkgCacheGenerator &Gen,OpProgress *Prog) const;
+ virtual pkgCache::PkgFileIterator FindInCache(pkgCache &Cache) const;
+
+ // Interface for acquire
+ virtual std::string ArchiveURI(std::string /*File*/) const;
+
+ debDebPkgFileIndex(std::string DebFile);
+ virtual ~debDebPkgFileIndex() {};
+};
+
class debDscFileIndex : public pkgIndexFile
{
private:
diff --git a/apt-pkg/deb/deblistparser.cc b/apt-pkg/deb/deblistparser.cc
index a1bcfb710..d5e3ccb65 100644
--- a/apt-pkg/deb/deblistparser.cc
+++ b/apt-pkg/deb/deblistparser.cc
@@ -959,3 +959,23 @@ bool debListParser::SameVersion(unsigned short const Hash, /*{{{*/
}
/*}}}*/
#endif
+
+
+debDebFileParser::debDebFileParser(FileFd *File, std::string const &DebFile)
+ : debListParser(File, ""), DebFile(DebFile)
+{
+}
+
+bool debDebFileParser::UsePackage(pkgCache::PkgIterator &Pkg,
+ pkgCache::VerIterator &Ver)
+{
+ bool res = debListParser::UsePackage(Pkg, Ver);
+ // we use the full file path as a provides so that the file is found
+ // by its name
+ if(NewProvidesAllArch(Ver, DebFile, Ver.VerStr()) == false)
+ return false;
+ return res;
+}
+
+
+
diff --git a/apt-pkg/deb/deblistparser.h b/apt-pkg/deb/deblistparser.h
index baace79fe..92ec048b1 100644
--- a/apt-pkg/deb/deblistparser.h
+++ b/apt-pkg/deb/deblistparser.h
@@ -56,7 +56,8 @@ class debListParser : public pkgCacheGenerator::ListParser
bool ParseProvides(pkgCache::VerIterator &Ver);
bool NewProvidesAllArch(pkgCache::VerIterator &Ver, std::string const &Package, std::string const &Version);
static bool GrabWord(std::string Word,WordList *List,unsigned char &Out);
-
+ APT_HIDDEN unsigned char ParseMultiArch(bool const showErrors);
+
public:
static unsigned char GetPrio(std::string Str);
@@ -101,9 +102,17 @@ class debListParser : public pkgCacheGenerator::ListParser
debListParser(FileFd *File, std::string const &Arch = "");
virtual ~debListParser() {};
+};
- private:
- APT_HIDDEN unsigned char ParseMultiArch(bool const showErrors);
+class debDebFileParser : public debListParser
+{
+ private:
+ std::string DebFile;
+
+ public:
+ debDebFileParser(FileFd *File, std::string const &DebFile);
+ virtual bool UsePackage(pkgCache::PkgIterator &Pkg,
+ pkgCache::VerIterator &Ver);
};
#endif
diff --git a/apt-pkg/deb/debmetaindex.cc b/apt-pkg/deb/debmetaindex.cc
index 6fd12add8..b4839ada4 100644
--- a/apt-pkg/deb/debmetaindex.cc
+++ b/apt-pkg/deb/debmetaindex.cc
@@ -471,6 +471,15 @@ class debSLTypeDebian : public pkgSourceList::Type
}
};
+debDebFileMetaIndex::debDebFileMetaIndex(std::string const &DebFile)
+ : metaIndex(DebFile, "local-uri", "deb-dist"), DebFile(DebFile)
+{
+ DebIndex = new debDebPkgFileIndex(DebFile);
+ Indexes = new vector<pkgIndexFile *>();
+ Indexes->push_back(DebIndex);
+}
+
+
class debSLTypeDeb : public debSLTypeDebian
{
public:
@@ -507,5 +516,25 @@ class debSLTypeDebSrc : public debSLTypeDebian
}
};
+class debSLTypeDebFile : public pkgSourceList::Type
+{
+ public:
+
+ bool CreateItem(vector<metaIndex *> &List, string const &URI,
+ string const &/*Dist*/, string const &/*Section*/,
+ std::map<string, string> const &/*Options*/) const
+ {
+ metaIndex *mi = new debDebFileMetaIndex(URI);
+ List.push_back(mi);
+ return true;
+ }
+
+ debSLTypeDebFile()
+ {
+ Name = "deb-file";
+ Label = "Debian Deb File";
+ }
+};
debSLTypeDeb _apt_DebType;
debSLTypeDebSrc _apt_DebSrcType;
+debSLTypeDebFile _apt_DebFileType;
diff --git a/apt-pkg/deb/debmetaindex.h b/apt-pkg/deb/debmetaindex.h
index 2286fa8b2..0e70bba87 100644
--- a/apt-pkg/deb/debmetaindex.h
+++ b/apt-pkg/deb/debmetaindex.h
@@ -18,6 +18,7 @@
class pkgAcquire;
class pkgIndexFile;
+class debDebPkgFileIndex;
class debReleaseIndex : public metaIndex {
public:
@@ -71,4 +72,27 @@ class debReleaseIndex : public metaIndex {
void PushSectionEntry(const debSectionEntry *Entry);
};
+class debDebFileMetaIndex : public metaIndex
+{
+ private:
+ std::string DebFile;
+ debDebPkgFileIndex *DebIndex;
+ public:
+ virtual std::string ArchiveURI(std::string const& /*File*/) const {
+ return DebFile;
+ }
+ virtual bool GetIndexes(pkgAcquire* /*Owner*/, const bool& /*GetAll=false*/) const {
+ return true;
+ }
+ virtual std::vector<pkgIndexFile *> *GetIndexFiles() {
+ return Indexes;
+ }
+ virtual bool IsTrusted() const {
+ return true;
+ }
+ debDebFileMetaIndex(std::string const &DebFile);
+ virtual ~debDebFileMetaIndex() {};
+
+};
+
#endif
diff --git a/apt-pkg/deb/debrecords.h b/apt-pkg/deb/debrecords.h
index bdac6c90b..d572bc5c2 100644
--- a/apt-pkg/deb/debrecords.h
+++ b/apt-pkg/deb/debrecords.h
@@ -29,17 +29,16 @@ class debRecordParser : public pkgRecords::Parser
{
/** \brief dpointer placeholder (for later in case we need it) */
void *d;
-
+
+ protected:
FileFd File;
pkgTagFile Tags;
pkgTagSection Section;
- protected:
-
virtual bool Jump(pkgCache::VerFileIterator const &Ver);
virtual bool Jump(pkgCache::DescFileIterator const &Desc);
- public:
+ public:
// These refer to the archive file for the Version
virtual std::string FileName();
@@ -66,4 +65,15 @@ class debRecordParser : public pkgRecords::Parser
virtual ~debRecordParser() {};
};
+// custom record parser that reads deb files directly
+class debDebFileRecordParser : public debRecordParser
+{
+ public:
+ virtual std::string FileName() {
+ return File.Name();
+ }
+ debDebFileRecordParser(std::string FileName,pkgCache &Cache)
+ : debRecordParser(FileName, Cache) {};
+};
+
#endif
diff --git a/apt-pkg/deb/debsrcrecords.cc b/apt-pkg/deb/debsrcrecords.cc
index 8aad81e3c..7b9a828d3 100644
--- a/apt-pkg/deb/debsrcrecords.cc
+++ b/apt-pkg/deb/debsrcrecords.cc
@@ -18,6 +18,7 @@
#include <apt-pkg/aptconfiguration.h>
#include <apt-pkg/srcrecords.h>
#include <apt-pkg/tagfile.h>
+#include <apt-pkg/hashes.h>
#include <apt-pkg/gpgv.h>
#include <ctype.h>
@@ -122,64 +123,86 @@ bool debSrcRecordParser::BuildDepends(std::vector<pkgSrcRecords::Parser::BuildDe
bool debSrcRecordParser::Files(std::vector<pkgSrcRecords::File> &List)
{
List.erase(List.begin(),List.end());
+
+ // map from the Hashsum field to the hashsum function,
+ // unfortunately this is not a 1:1 mapping from
+ // Hashes::SupporedHashes as e.g. Files is a historic name for the md5
+ const std::pair<const char*, const char*> SourceHashFields[] = {
+ std::make_pair( "Checksums-Sha512", "SHA512"),
+ std::make_pair( "Checksums-Sha256", "SHA256"),
+ std::make_pair( "Checksums-Sha1", "SHA1"),
+ std::make_pair( "Files", "MD5Sum"), // historic Name
+ };
- string Files = Sect.FindS("Files");
- if (Files.empty() == true)
- return false;
-
- // Stash the / terminated directory prefix
- string Base = Sect.FindS("Directory");
- if (Base.empty() == false && Base[Base.length()-1] != '/')
- Base += '/';
-
- std::vector<std::string> const compExts = APT::Configuration::getCompressorExtensions();
-
- // Iterate over the entire list grabbing each triplet
- const char *C = Files.c_str();
- while (*C != 0)
- {
- pkgSrcRecords::File F;
- string Size;
-
- // Parse each of the elements
- if (ParseQuoteWord(C,F.MD5Hash) == false ||
- ParseQuoteWord(C,Size) == false ||
- ParseQuoteWord(C,F.Path) == false)
- return _error->Error("Error parsing file record");
-
- // Parse the size and append the directory
- F.Size = atoi(Size.c_str());
- F.Path = Base + F.Path;
-
- // Try to guess what sort of file it is we are getting.
- string::size_type Pos = F.Path.length()-1;
- while (1)
- {
- string::size_type Tmp = F.Path.rfind('.',Pos);
- if (Tmp == string::npos)
- break;
- if (F.Type == "tar") {
- // source v3 has extension 'debian.tar.*' instead of 'diff.*'
- if (string(F.Path, Tmp+1, Pos-Tmp) == "debian")
- F.Type = "diff";
- break;
- }
- F.Type = string(F.Path,Tmp+1,Pos-Tmp);
-
- if (std::find(compExts.begin(), compExts.end(), std::string(".").append(F.Type)) != compExts.end() ||
- F.Type == "tar")
- {
- Pos = Tmp-1;
- continue;
- }
+ for (unsigned int i=0;
+ i < sizeof(SourceHashFields)/sizeof(SourceHashFields[0]);
+ i++)
+ {
+ string Files = Sect.FindS(SourceHashFields[i].first);
+ if (Files.empty() == true)
+ continue;
+
+ // Stash the / terminated directory prefix
+ string Base = Sect.FindS("Directory");
+ if (Base.empty() == false && Base[Base.length()-1] != '/')
+ Base += '/';
+
+ std::vector<std::string> const compExts = APT::Configuration::getCompressorExtensions();
+
+ // Iterate over the entire list grabbing each triplet
+ const char *C = Files.c_str();
+ while (*C != 0)
+ {
+ pkgSrcRecords::File F;
+ string Size;
+
+ // Parse each of the elements
+ std::string RawHash;
+ if (ParseQuoteWord(C, RawHash) == false ||
+ ParseQuoteWord(C, Size) == false ||
+ ParseQuoteWord(C, F.Path) == false)
+ return _error->Error("Error parsing '%s' record",
+ SourceHashFields[i].first);
+ // assign full hash string
+ F.Hash = HashString(SourceHashFields[i].second, RawHash).toStr();
+ // API compat hack
+ if(strcmp(SourceHashFields[i].second, "MD5Sum") == 0)
+ F.MD5Hash = RawHash;
+
+ // Parse the size and append the directory
+ F.Size = atoi(Size.c_str());
+ F.Path = Base + F.Path;
+
+ // Try to guess what sort of file it is we are getting.
+ string::size_type Pos = F.Path.length()-1;
+ while (1)
+ {
+ string::size_type Tmp = F.Path.rfind('.',Pos);
+ if (Tmp == string::npos)
+ break;
+ if (F.Type == "tar") {
+ // source v3 has extension 'debian.tar.*' instead of 'diff.*'
+ if (string(F.Path, Tmp+1, Pos-Tmp) == "debian")
+ F.Type = "diff";
+ break;
+ }
+ F.Type = string(F.Path,Tmp+1,Pos-Tmp);
+
+ if (std::find(compExts.begin(), compExts.end(), std::string(".").append(F.Type)) != compExts.end() ||
+ F.Type == "tar")
+ {
+ Pos = Tmp-1;
+ continue;
+ }
- break;
- }
+ break;
+ }
- List.push_back(F);
+ List.push_back(F);
+ }
+ break;
}
-
- return true;
+ return (List.size() > 0);
}
/*}}}*/
// SrcRecordParser::~SrcRecordParser - Destructor /*{{{*/
diff --git a/apt-pkg/deb/dpkgpm.cc b/apt-pkg/deb/dpkgpm.cc
index c3e7e1d1d..32ef343aa 100644
--- a/apt-pkg/deb/dpkgpm.cc
+++ b/apt-pkg/deb/dpkgpm.cc
@@ -517,7 +517,7 @@ bool pkgDPkgPM::RunScriptsWithPkgs(const char *Cnf)
void pkgDPkgPM::DoStdin(int master)
{
unsigned char input_buf[256] = {0,};
- ssize_t len = read(0, input_buf, sizeof(input_buf));
+ ssize_t len = read(STDIN_FILENO, input_buf, sizeof(input_buf));
if (len)
FileFd::Write(master, input_buf, len);
else
@@ -1053,14 +1053,15 @@ void pkgDPkgPM::StartPtyMagic()
}
// setup the pty and stuff
- struct winsize win;
+ struct winsize win;
- // if tcgetattr does not return zero there was a error
- // and we do not do any pty magic
+ // if tcgetattr for both stdin/stdout returns 0 (no error)
+ // we do the pty magic
_error->PushToStack();
- if (tcgetattr(STDOUT_FILENO, &d->tt) == 0)
+ if (tcgetattr(STDIN_FILENO, &d->tt) == 0 &&
+ tcgetattr(STDOUT_FILENO, &d->tt) == 0)
{
- if (ioctl(1, TIOCGWINSZ, (char *)&win) < 0)
+ if (ioctl(STDOUT_FILENO, TIOCGWINSZ, (char *)&win) < 0)
{
_error->Errno("ioctl", _("ioctl(TIOCGWINSZ) failed"));
} else if (openpty(&d->master, &d->slave, NULL, &d->tt, &win) < 0)
@@ -1617,7 +1618,7 @@ void pkgDPkgPM::WriteApportReport(const char *pkgpath, const char *errormsg)
string::size_type pos;
FILE *report;
- if (_config->FindB("Dpkg::ApportFailureReport", false) == false)
+ if (_config->FindB("Dpkg::ApportFailureReport", true) == false)
{
std::clog << "configured to not write apport reports" << std::endl;
return;
diff --git a/apt-pkg/indexrecords.cc b/apt-pkg/indexrecords.cc
index 5353d1098..68ebdce08 100644
--- a/apt-pkg/indexrecords.cc
+++ b/apt-pkg/indexrecords.cc
@@ -53,7 +53,7 @@ APT_PURE time_t indexRecords::GetValidUntil() const
return this->ValidUntil;
}
-APT_PURE const indexRecords::checkSum *indexRecords::Lookup(const string MetaKey)
+APT_PURE indexRecords::checkSum *indexRecords::Lookup(const string MetaKey)
{
std::map<std::string, indexRecords::checkSum* >::const_iterator sum = Entries.find(MetaKey);
if (sum == Entries.end())
diff --git a/apt-pkg/indexrecords.h b/apt-pkg/indexrecords.h
index e31f889ad..2260a4ae1 100644
--- a/apt-pkg/indexrecords.h
+++ b/apt-pkg/indexrecords.h
@@ -41,7 +41,7 @@ class indexRecords
indexRecords(const std::string ExpectedDist);
// Lookup function
- virtual const checkSum *Lookup(const std::string MetaKey);
+ virtual checkSum *Lookup(const std::string MetaKey);
/** \brief tests if a checksum for this file is available */
bool Exists(std::string const &MetaKey) const;
std::vector<std::string> MetaKeys();
diff --git a/apt-pkg/init.cc b/apt-pkg/init.cc
index 3a35f852e..241628632 100644
--- a/apt-pkg/init.cc
+++ b/apt-pkg/init.cc
@@ -86,6 +86,7 @@ bool pkgInitConfig(Configuration &Cnf)
Cnf.Set("Dir::Ignore-Files-Silently::", "\\.dpkg-[a-z]+$");
Cnf.Set("Dir::Ignore-Files-Silently::", "\\.save$");
Cnf.Set("Dir::Ignore-Files-Silently::", "\\.orig$");
+ Cnf.Set("Dir::Ignore-Files-Silently::", "\\.distUpgrade$");
// Default cdrom mount point
Cnf.CndSet("Acquire::cdrom::mount", "/media/cdrom/");
diff --git a/apt-pkg/install-progress.cc b/apt-pkg/install-progress.cc
index 8bb587f67..cf6c85912 100644
--- a/apt-pkg/install-progress.cc
+++ b/apt-pkg/install-progress.cc
@@ -256,14 +256,14 @@ PackageManagerFancy::TermSize
PackageManagerFancy::GetTerminalSize()
{
struct winsize win;
- PackageManagerFancy::TermSize s;
+ PackageManagerFancy::TermSize s = { 0, 0 };
// FIXME: get from "child_pty" instead?
if(ioctl(STDOUT_FILENO, TIOCGWINSZ, (char *)&win) != 0)
return s;
if(_config->FindB("Debug::InstallProgress::Fancy", false) == true)
- std::cerr << "GetTerminalSize: " << win.ws_row << std::endl;
+ std::cerr << "GetTerminalSize: " << win.ws_row << " x " << win.ws_col << std::endl;
s.rows = win.ws_row;
s.columns = win.ws_col;
@@ -275,6 +275,9 @@ void PackageManagerFancy::SetupTerminalScrollArea(int nr_rows)
if(_config->FindB("Debug::InstallProgress::Fancy", false) == true)
std::cerr << "SetupTerminalScrollArea: " << nr_rows << std::endl;
+ if (unlikely(nr_rows <= 1))
+ return;
+
// scroll down a bit to avoid visual glitch when the screen
// area shrinks by one row
std::cout << "\n";
@@ -296,28 +299,30 @@ void PackageManagerFancy::SetupTerminalScrollArea(int nr_rows)
// setup tty size to ensure xterm/linux console are working properly too
// see bug #731738
struct winsize win;
- ioctl(child_pty, TIOCGWINSZ, (char *)&win);
- win.ws_row = nr_rows - 1;
- ioctl(child_pty, TIOCSWINSZ, (char *)&win);
+ if (ioctl(child_pty, TIOCGWINSZ, (char *)&win) != -1)
+ {
+ win.ws_row = nr_rows - 1;
+ ioctl(child_pty, TIOCSWINSZ, (char *)&win);
+ }
}
void PackageManagerFancy::HandleSIGWINCH(int)
{
- int nr_terminal_rows = GetTerminalSize().rows;
+ int const nr_terminal_rows = GetTerminalSize().rows;
SetupTerminalScrollArea(nr_terminal_rows);
+ DrawStatusLine();
}
void PackageManagerFancy::Start(int a_child_pty)
{
child_pty = a_child_pty;
- int nr_terminal_rows = GetTerminalSize().rows;
- if (nr_terminal_rows > 0)
- SetupTerminalScrollArea(nr_terminal_rows);
+ int const nr_terminal_rows = GetTerminalSize().rows;
+ SetupTerminalScrollArea(nr_terminal_rows);
}
void PackageManagerFancy::Stop()
{
- int nr_terminal_rows = GetTerminalSize().rows;
+ int const nr_terminal_rows = GetTerminalSize().rows;
if (nr_terminal_rows > 0)
{
SetupTerminalScrollArea(nr_terminal_rows + 1);
@@ -358,7 +363,13 @@ bool PackageManagerFancy::StatusChanged(std::string PackageName,
HumanReadableAction))
return false;
- PackageManagerFancy::TermSize size = GetTerminalSize();
+ return DrawStatusLine();
+}
+bool PackageManagerFancy::DrawStatusLine()
+{
+ PackageManagerFancy::TermSize const size = GetTerminalSize();
+ if (unlikely(size.rows < 1 || size.columns < 1))
+ return false;
static std::string save_cursor = "\033[s";
static std::string restore_cursor = "\033[u";
@@ -388,7 +399,7 @@ bool PackageManagerFancy::StatusChanged(std::string PackageName,
{
int padding = 4;
float progressbar_size = size.columns - padding - progress_str.size();
- float current_percent = (float)StepsDone/(float)TotalSteps;
+ float current_percent = percentage / 100.0;
std::cout << " "
<< GetTextProgressStr(current_percent, progressbar_size)
<< " ";
diff --git a/apt-pkg/install-progress.h b/apt-pkg/install-progress.h
index 112b034fb..5d1a20e9b 100644
--- a/apt-pkg/install-progress.h
+++ b/apt-pkg/install-progress.h
@@ -1,6 +1,8 @@
#ifndef PKGLIB_IPROGRESS_H
#define PKGLIB_IPROGRESS_H
+#include <apt-pkg/macros.h>
+
#include <string>
#include <unistd.h>
#include <signal.h>
@@ -120,6 +122,7 @@ namespace Progress {
private:
static void staticSIGWINCH(int);
static std::vector<PackageManagerFancy*> instances;
+ APT_HIDDEN bool DrawStatusLine();
protected:
void SetupTerminalScrollArea(int nr_rows);
diff --git a/apt-pkg/makefile b/apt-pkg/makefile
index 1d456873b..5603b51ed 100644
--- a/apt-pkg/makefile
+++ b/apt-pkg/makefile
@@ -11,6 +11,7 @@ include ../buildlib/defaults.mak
# The library name and version (indirectly used from init.h)
include ../buildlib/libversion.mak
+
LIBRARY=apt-pkg
MAJOR=$(LIBAPTPKG_MAJOR)
MINOR=$(LIBAPTPKG_RELEASE)
@@ -26,50 +27,7 @@ SLIBS+= -llzma
endif
APT_DOMAIN:=libapt-pkg$(LIBAPTPKG_MAJOR)
-# Source code for the contributed non-core things
-SOURCE = contrib/mmap.cc contrib/error.cc contrib/strutl.cc \
- contrib/configuration.cc contrib/progress.cc contrib/cmndline.cc \
- contrib/hashsum.cc contrib/md5.cc contrib/sha1.cc \
- contrib/sha2_internal.cc contrib/hashes.cc \
- contrib/cdromutl.cc contrib/crc-16.cc contrib/netrc.cc \
- contrib/fileutl.cc contrib/gpgv.cc
-HEADERS = mmap.h error.h configuration.h fileutl.h cmndline.h netrc.h \
- md5.h crc-16.h cdromutl.h strutl.h sptr.h sha1.h sha2.h sha256.h \
- sha2_internal.h hashes.h hashsum_template.h \
- macros.h weakptr.h gpgv.h
-
-# Source code for the core main library
-SOURCE+= pkgcache.cc version.cc depcache.cc \
- orderlist.cc tagfile.cc sourcelist.cc packagemanager.cc \
- pkgrecords.cc algorithms.cc acquire.cc\
- acquire-worker.cc acquire-method.cc init.cc clean.cc \
- srcrecords.cc cachefile.cc versionmatch.cc policy.cc \
- pkgsystem.cc indexfile.cc pkgcachegen.cc acquire-item.cc \
- indexrecords.cc vendor.cc vendorlist.cc cdrom.cc indexcopy.cc \
- aptconfiguration.cc cachefilter.cc cacheset.cc edsp.cc \
- install-progress.cc upgrade.cc update.cc
-HEADERS+= algorithms.h depcache.h pkgcachegen.h cacheiterators.h \
- orderlist.h sourcelist.h packagemanager.h tagfile.h \
- init.h pkgcache.h version.h progress.h pkgrecords.h \
- acquire.h acquire-worker.h acquire-item.h acquire-method.h \
- clean.h srcrecords.h cachefile.h versionmatch.h policy.h \
- pkgsystem.h indexfile.h metaindex.h indexrecords.h vendor.h \
- vendorlist.h cdrom.h indexcopy.h aptconfiguration.h \
- cachefilter.h cacheset.h edsp.h install-progress.h \
- upgrade.h update.h
-
-# Source code for the debian specific components
-# In theory the deb headers do not need to be exported..
-SOURCE+= deb/deblistparser.cc deb/debrecords.cc deb/dpkgpm.cc \
- deb/debsrcrecords.cc deb/debversion.cc deb/debsystem.cc \
- deb/debindexfile.cc deb/debindexfile.cc deb/debmetaindex.cc
-HEADERS+= debversion.h debsrcrecords.h dpkgpm.h debrecords.h \
- deblistparser.h debsystem.h debindexfile.h debmetaindex.h
-
-# Source code for the APT resolver interface specific components
-SOURCE+= edsp/edsplistparser.cc edsp/edspindexfile.cc edsp/edspsystem.cc
-HEADERS+= edsplistparser.h edspindexfile.h edspsystem.h
-
-HEADERS := $(addprefix apt-pkg/,$(HEADERS))
+SOURCE = $(wildcard *.cc */*.cc)
+HEADERS = $(addprefix apt-pkg/,$(notdir $(wildcard *.h */*.h)))
include $(LIBRARY_H)
diff --git a/apt-pkg/packagemanager.cc b/apt-pkg/packagemanager.cc
index 5d6bc6bd2..0ec9f3309 100644
--- a/apt-pkg/packagemanager.cc
+++ b/apt-pkg/packagemanager.cc
@@ -28,6 +28,7 @@
#include <apt-pkg/pkgcache.h>
#include <apt-pkg/cacheiterators.h>
#include <apt-pkg/strutl.h>
+#include <apt-pkg/install-progress.h>
#include <stddef.h>
#include <list>
diff --git a/apt-pkg/packagemanager.h b/apt-pkg/packagemanager.h
index 344ed9192..8a51a455c 100644
--- a/apt-pkg/packagemanager.h
+++ b/apt-pkg/packagemanager.h
@@ -44,6 +44,11 @@ class pkgDepCache;
class pkgSourceList;
class pkgOrderList;
class pkgRecords;
+namespace APT {
+ namespace Progress {
+ class PackageManager;
+ };
+};
class pkgPackageManager : protected pkgCache::Namespace
diff --git a/apt-pkg/pkgcache.cc b/apt-pkg/pkgcache.cc
index 91b75f52e..5088712a2 100644
--- a/apt-pkg/pkgcache.cc
+++ b/apt-pkg/pkgcache.cc
@@ -54,7 +54,7 @@ pkgCache::Header::Header()
/* Whenever the structures change the major version should be bumped,
whenever the generator changes the minor version should be bumped. */
- MajorVersion = 8;
+ MajorVersion = 9;
#if (APT_PKG_MAJOR >= 4 && APT_PKG_MINOR >= 13)
MinorVersion = 2;
#else
diff --git a/apt-pkg/pkgcache.h b/apt-pkg/pkgcache.h
index 5e8a9630a..151de7d25 100644
--- a/apt-pkg/pkgcache.h
+++ b/apt-pkg/pkgcache.h
@@ -138,7 +138,7 @@ class pkgCache /*{{{*/
/** \brief priority of a package version
Zero is used for unparsable or absent Priority fields. */
- enum VerPriority {Important=1,Required=2,Standard=3,Optional=4,Extra=5};
+ enum VerPriority {Required=1,Important=2,Standard=3,Optional=4,Extra=5};
enum PkgSelectedState {Unknown=0,Install=1,Hold=2,DeInstall=3,Purge=4};
enum PkgInstState {Ok=0,ReInstReq=1,HoldInst=2,HoldReInstReq=3};
enum PkgCurrentState {NotInstalled=0,UnPacked=1,HalfConfigured=2,
diff --git a/apt-pkg/sourcelist.h b/apt-pkg/sourcelist.h
index 0ebf4e080..261dd8161 100644
--- a/apt-pkg/sourcelist.h
+++ b/apt-pkg/sourcelist.h
@@ -52,7 +52,15 @@ class pkgAcquire;
class pkgIndexFile;
class metaIndex;
-class pkgSourceList
+class pkgSource
+{
+ protected:
+
+ std::vector<metaIndex *> SrcList;
+
+};
+
+class pkgSourceList : public pkgSource
{
public:
diff --git a/apt-pkg/srcrecords.h b/apt-pkg/srcrecords.h
index 9915debfe..58a5e242f 100644
--- a/apt-pkg/srcrecords.h
+++ b/apt-pkg/srcrecords.h
@@ -33,6 +33,7 @@ class pkgSrcRecords
struct File
{
std::string MD5Hash;
+ std::string Hash;
unsigned long Size;
std::string Path;
std::string Type;