summaryrefslogtreecommitdiff
path: root/apt-pkg
diff options
context:
space:
mode:
Diffstat (limited to 'apt-pkg')
-rw-r--r--apt-pkg/acquire-item.cc74
-rw-r--r--apt-pkg/acquire-method.cc41
-rw-r--r--apt-pkg/acquire-method.h3
-rw-r--r--apt-pkg/acquire-worker.cc62
-rw-r--r--apt-pkg/acquire.cc43
-rw-r--r--apt-pkg/algorithms.cc56
-rw-r--r--apt-pkg/algorithms.h5
-rw-r--r--apt-pkg/aptconfiguration.cc80
-rw-r--r--apt-pkg/cachefile.cc34
-rw-r--r--apt-pkg/cachefilter.cc4
-rw-r--r--apt-pkg/cacheset.h12
-rw-r--r--apt-pkg/cdrom.cc27
-rw-r--r--apt-pkg/clean.cc11
-rw-r--r--apt-pkg/contrib/configuration.cc149
-rw-r--r--apt-pkg/contrib/configuration.h2
-rw-r--r--apt-pkg/contrib/fileutl.cc436
-rw-r--r--apt-pkg/contrib/fileutl.h2
-rw-r--r--apt-pkg/contrib/mmap.cc1
-rw-r--r--apt-pkg/contrib/netrc.cc3
-rw-r--r--apt-pkg/contrib/sha2_internal.cc8
-rw-r--r--apt-pkg/contrib/strutl.cc63
-rw-r--r--apt-pkg/deb/debindexfile.cc6
-rw-r--r--apt-pkg/deb/deblistparser.cc27
-rw-r--r--apt-pkg/deb/debmetaindex.cc36
-rw-r--r--apt-pkg/deb/dpkgpm.cc39
-rw-r--r--apt-pkg/depcache.cc35
-rw-r--r--apt-pkg/edsp/edspsystem.cc2
-rw-r--r--apt-pkg/indexrecords.cc5
-rw-r--r--apt-pkg/init.cc2
-rw-r--r--apt-pkg/makefile8
-rw-r--r--apt-pkg/packagemanager.cc16
-rw-r--r--apt-pkg/pkgcachegen.cc14
-rw-r--r--apt-pkg/srcrecords.h1
33 files changed, 905 insertions, 402 deletions
diff --git a/apt-pkg/acquire-item.cc b/apt-pkg/acquire-item.cc
index 9ea1519f1..a30e98858 100644
--- a/apt-pkg/acquire-item.cc
+++ b/apt-pkg/acquire-item.cc
@@ -189,14 +189,14 @@ void pkgAcquire::Item::ReportMirrorFailure(string FailCode)
/*}}}*/
// AcqSubIndex::AcqSubIndex - Constructor /*{{{*/
// ---------------------------------------------------------------------
-/* Get the Index file first and see if there are languages available
- * If so, create a pkgAcqIndexTrans for the found language(s).
- */
+/* Get a sub-index file based on checksums from a 'master' file and
+ possibly query additional files */
pkgAcqSubIndex::pkgAcqSubIndex(pkgAcquire *Owner, string const &URI,
string const &URIDesc, string const &ShortDesc,
HashString const &ExpectedHash)
: Item(Owner), ExpectedHash(ExpectedHash)
{
+ /* XXX: Beware: Currently this class does nothing (of value) anymore ! */
Debug = _config->FindB("Debug::pkgAcquire::SubIndex",false);
DestFile = _config->FindDir("Dir::State::lists") + "partial/";
@@ -236,17 +236,7 @@ void pkgAcqSubIndex::Failed(string Message,pkgAcquire::MethodConfig *Cnf) /*{{{*
Status = StatDone;
Dequeue();
- // No good Index is provided, so try guessing
- std::vector<std::string> langs = APT::Configuration::getLanguages(true);
- for (std::vector<std::string>::const_iterator l = langs.begin();
- l != langs.end(); ++l)
- {
- if (*l == "none") continue;
- string const file = "Translation-" + *l;
- new pkgAcqIndexTrans(Owner, Desc.URI.substr(0, Desc.URI.rfind('/')+1).append(file),
- Desc.Description.erase(Desc.Description.rfind(' ')+1).append(file),
- file);
- }
+ // No good Index is provided
}
/*}}}*/
void pkgAcqSubIndex::Done(string Message,unsigned long long Size,string Md5Hash, /*{{{*/
@@ -305,38 +295,7 @@ bool pkgAcqSubIndex::ParseIndex(string const &IndexFile) /*{{{*/
indexRecords SubIndexParser;
if (FileExists(IndexFile) == false || SubIndexParser.Load(IndexFile) == false)
return false;
-
- std::vector<std::string> lang = APT::Configuration::getLanguages(true);
- for (std::vector<std::string>::const_iterator l = lang.begin();
- l != lang.end(); ++l)
- {
- if (*l == "none")
- continue;
-
- string file = "Translation-" + *l;
- indexRecords::checkSum const *Record = SubIndexParser.Lookup(file);
- HashString expected;
- if (Record == NULL)
- {
- // FIXME: the Index file provided by debian currently only includes bz2 records
- Record = SubIndexParser.Lookup(file + ".bz2");
- if (Record == NULL)
- continue;
- }
- else
- {
- expected = Record->Hash;
- if (expected.empty() == true)
- continue;
- }
-
- IndexTarget target;
- target.Description = Desc.Description.erase(Desc.Description.rfind(' ')+1).append(file);
- target.MetaKey = file;
- target.ShortDesc = file;
- target.URI = Desc.URI.substr(0, Desc.URI.rfind('/')+1).append(file);
- new pkgAcqIndexTrans(Owner, &target, expected, &SubIndexParser);
- }
+ // so something with the downloaded index
return true;
}
/*}}}*/
@@ -1385,6 +1344,18 @@ void pkgAcqMetaIndex::QueueIndexes(bool verify) /*{{{*/
return;
}
#endif
+ bool transInRelease = false;
+ {
+ std::vector<std::string> const keys = MetaIndexParser->MetaKeys();
+ for (std::vector<std::string>::const_iterator k = keys.begin(); k != keys.end(); ++k)
+ // FIXME: Feels wrong to check for hardcoded string here, but what should we do else…
+ if (k->find("Translation-") != std::string::npos)
+ {
+ transInRelease = true;
+ break;
+ }
+ }
+
for (vector <struct IndexTarget*>::const_iterator Target = IndexTargets->begin();
Target != IndexTargets->end();
++Target)
@@ -1422,8 +1393,15 @@ void pkgAcqMetaIndex::QueueIndexes(bool verify) /*{{{*/
if ((*Target)->IsSubIndex() == true)
new pkgAcqSubIndex(Owner, (*Target)->URI, (*Target)->Description,
(*Target)->ShortDesc, ExpectedIndexHash);
- else
- new pkgAcqIndexTrans(Owner, *Target, ExpectedIndexHash, MetaIndexParser);
+ else if (transInRelease == false || MetaIndexParser->Exists((*Target)->MetaKey) == true)
+ {
+ if (_config->FindB("Acquire::PDiffs",true) == true && transInRelease == true &&
+ MetaIndexParser->Exists(string((*Target)->MetaKey).append(".diff/Index")) == true)
+ new pkgAcqDiffIndex(Owner, (*Target)->URI, (*Target)->Description,
+ (*Target)->ShortDesc, ExpectedIndexHash);
+ else
+ new pkgAcqIndexTrans(Owner, *Target, ExpectedIndexHash, MetaIndexParser);
+ }
continue;
}
diff --git a/apt-pkg/acquire-method.cc b/apt-pkg/acquire-method.cc
index 2041fd9e9..5bc1c159a 100644
--- a/apt-pkg/acquire-method.cc
+++ b/apt-pkg/acquire-method.cc
@@ -95,12 +95,7 @@ void pkgAcqMethod::Fail(string Err,bool Transient)
{
std::cout << "400 URI Failure\nURI: " << Queue->Uri << "\n"
<< "Message: " << Err << " " << IP << "\n";
- // Dequeue
- FetchItem *Tmp = Queue;
- Queue = Queue->Next;
- delete Tmp;
- if (Tmp == QueueBack)
- QueueBack = Queue;
+ Dequeue();
}
else
std::cout << "400 URI Failure\nURI: <UNKNOWN>\nMessage: " << Err << "\n";
@@ -211,13 +206,7 @@ void pkgAcqMethod::URIDone(FetchResult &Res, FetchResult *Alt)
}
std::cout << "\n" << std::flush;
-
- // Dequeue
- FetchItem *Tmp = Queue;
- Queue = Queue->Next;
- delete Tmp;
- if (Tmp == QueueBack)
- QueueBack = Queue;
+ Dequeue();
}
/*}}}*/
// AcqMethod::MediaFail - Syncronous request for new media /*{{{*/
@@ -423,26 +412,14 @@ void pkgAcqMethod::Status(const char *Format,...)
/*}}}*/
// AcqMethod::Redirect - Send a redirect message /*{{{*/
// ---------------------------------------------------------------------
-/* This method sends the redirect message and also manipulates the queue
- to keep the pipeline synchronized. */
+/* This method sends the redirect message and dequeues the item as
+ * the worker will enqueue again later on to the right queue */
void pkgAcqMethod::Redirect(const string &NewURI)
{
std::cout << "103 Redirect\nURI: " << Queue->Uri << "\n"
<< "New-URI: " << NewURI << "\n"
<< "\n" << std::flush;
-
- // Change the URI for the request.
- Queue->Uri = NewURI;
-
- /* To keep the pipeline synchronized, move the current request to
- the end of the queue, past the end of the current pipeline. */
- FetchItem *I;
- for (I = Queue; I->Next != 0; I = I->Next) ;
- I->Next = Queue;
- Queue = Queue->Next;
- I->Next->Next = 0;
- if (QueueBack == 0)
- QueueBack = I->Next;
+ Dequeue();
}
/*}}}*/
// AcqMethod::FetchResult::FetchResult - Constructor /*{{{*/
@@ -465,3 +442,11 @@ void pkgAcqMethod::FetchResult::TakeHashes(Hashes &Hash)
SHA512Sum = Hash.SHA512.Result();
}
/*}}}*/
+void pkgAcqMethod::Dequeue() { /*{{{*/
+ FetchItem const * const Tmp = Queue;
+ Queue = Queue->Next;
+ if (Tmp == QueueBack)
+ QueueBack = Queue;
+ delete Tmp;
+}
+ /*}}}*/
diff --git a/apt-pkg/acquire-method.h b/apt-pkg/acquire-method.h
index 2dd9ad685..00f99e0a0 100644
--- a/apt-pkg/acquire-method.h
+++ b/apt-pkg/acquire-method.h
@@ -104,6 +104,9 @@ class pkgAcqMethod
pkgAcqMethod(const char *Ver,unsigned long Flags = 0);
virtual ~pkgAcqMethod() {};
+
+ private:
+ void Dequeue();
};
/** @} */
diff --git a/apt-pkg/acquire-worker.cc b/apt-pkg/acquire-worker.cc
index 3bb977e14..9d90b08bc 100644
--- a/apt-pkg/acquire-worker.cc
+++ b/apt-pkg/acquire-worker.cc
@@ -244,6 +244,21 @@ bool pkgAcquire::Worker::RunMessages()
string NewURI = LookupTag(Message,"New-URI",URI.c_str());
Itm->URI = NewURI;
+
+ ItemDone();
+
+ pkgAcquire::Item *Owner = Itm->Owner;
+ pkgAcquire::ItemDesc Desc = *Itm;
+
+ // Change the status so that it can be dequeued
+ Owner->Status = pkgAcquire::Item::StatIdle;
+ // Mark the item as done (taking care of all queues)
+ // and then put it in the main queue again
+ OwnerQ->ItemDone(Itm);
+ OwnerQ->Owner->Enqueue(Desc);
+
+ if (Log != 0)
+ Log->Done(Desc);
break;
}
@@ -431,7 +446,9 @@ bool pkgAcquire::Worker::MediaChange(string Message)
<< Drive << ":" // drive
<< msg.str() // l10n message
<< endl;
- write(status_fd, status.str().c_str(), status.str().size());
+
+ std::string const dlstatus = status.str();
+ FileFd::Write(status_fd, dlstatus.c_str(), dlstatus.size());
}
if (Log == 0 || Log->MediaChange(LookupTag(Message,"Media"),
@@ -465,40 +482,19 @@ bool pkgAcquire::Worker::SendConfiguration()
if (OutFd == -1)
return false;
-
- string Message = "601 Configuration\n";
- Message.reserve(2000);
- /* Write out all of the configuration directives by walking the
+ /* Write out all of the configuration directives by walking the
configuration tree */
- const Configuration::Item *Top = _config->Tree(0);
- for (; Top != 0;)
- {
- if (Top->Value.empty() == false)
- {
- string Line = "Config-Item: " + QuoteString(Top->FullTag(),"=\"\n") + "=";
- Line += QuoteString(Top->Value,"\n") + '\n';
- Message += Line;
- }
-
- if (Top->Child != 0)
- {
- Top = Top->Child;
- continue;
- }
-
- while (Top != 0 && Top->Next == 0)
- Top = Top->Parent;
- if (Top != 0)
- Top = Top->Next;
- }
- Message += '\n';
+ std::ostringstream Message;
+ Message << "601 Configuration\n";
+ _config->Dump(Message, NULL, "Config-Item: %F=%V\n", false);
+ Message << '\n';
if (Debug == true)
- clog << " -> " << Access << ':' << QuoteString(Message,"\n") << endl;
- OutQueue += Message;
- OutReady = true;
-
+ clog << " -> " << Access << ':' << QuoteString(Message.str(),"\n") << endl;
+ OutQueue += Message.str();
+ OutReady = true;
+
return true;
}
/*}}}*/
@@ -536,10 +532,10 @@ bool pkgAcquire::Worker::OutFdReady()
Res = write(OutFd,OutQueue.c_str(),OutQueue.length());
}
while (Res < 0 && errno == EINTR);
-
+
if (Res <= 0)
return MethodFailure();
-
+
OutQueue.erase(0,Res);
if (OutQueue.empty() == true)
OutReady = false;
diff --git a/apt-pkg/acquire.cc b/apt-pkg/acquire.cc
index 573a85c2f..a8a5abd34 100644
--- a/apt-pkg/acquire.cc
+++ b/apt-pkg/acquire.cc
@@ -244,11 +244,19 @@ void pkgAcquire::Dequeue(Item *Itm)
{
Queue *I = Queues;
bool Res = false;
- for (; I != 0; I = I->Next)
- Res |= I->Dequeue(Itm);
-
if (Debug == true)
clog << "Dequeuing " << Itm->DestFile << endl;
+
+ for (; I != 0; I = I->Next)
+ {
+ if (I->Dequeue(Itm))
+ {
+ Res = true;
+ if (Debug == true)
+ clog << "Dequeued from " << I->Name << endl;
+ }
+ }
+
if (Res == true)
ToFetch--;
}
@@ -269,9 +277,30 @@ string pkgAcquire::QueueName(string Uri,MethodConfig const *&Config)
/* Single-Instance methods get exactly one queue per URI. This is
also used for the Access queue method */
if (Config->SingleInstance == true || QueueMode == QueueAccess)
- return U.Access;
+ return U.Access;
- return U.Access + ':' + U.Host;
+ string AccessSchema = U.Access + ':',
+ FullQueueName = AccessSchema + U.Host;
+ unsigned int Instances = 0, SchemaLength = AccessSchema.length();
+
+ Queue *I = Queues;
+ for (; I != 0; I = I->Next) {
+ // if the queue already exists, re-use it
+ if (I->Name == FullQueueName)
+ return FullQueueName;
+
+ if (I->Name.compare(0, SchemaLength, AccessSchema) == 0)
+ Instances++;
+ }
+
+ if (Debug) {
+ clog << "Found " << Instances << " instances of " << U.Access << endl;
+ }
+
+ if (Instances >= (unsigned int)_config->FindI("Acquire::QueueHost::Limit",10))
+ return U.Access;
+
+ return FullQueueName;
}
/*}}}*/
// Acquire::GetConfig - Fetch the configuration information /*{{{*/
@@ -872,7 +901,9 @@ bool pkgAcquireStatus::Pulse(pkgAcquire *Owner)
<< ":" << (CurrentBytes/float(TotalBytes)*100.0)
<< ":" << msg
<< endl;
- write(fd, status.str().c_str(), status.str().size());
+
+ std::string const dlstatus = status.str();
+ FileFd::Write(fd, dlstatus.c_str(), dlstatus.size());
}
return true;
diff --git a/apt-pkg/algorithms.cc b/apt-pkg/algorithms.cc
index ed3534f0d..2d710097a 100644
--- a/apt-pkg/algorithms.cc
+++ b/apt-pkg/algorithms.cc
@@ -58,6 +58,12 @@ pkgSimulate::pkgSimulate(pkgDepCache *Cache) : pkgPackageManager(Cache),
FileNames[I] = Jnk;
}
/*}}}*/
+// Simulate::~Simulate - Destructor /*{{{*/
+pkgSimulate::~pkgSimulate()
+{
+ delete[] Flags;
+}
+ /*}}}*/
// Simulate::Describe - Describe a package /*{{{*/
// ---------------------------------------------------------------------
/* Parameter Current == true displays the current package version,
@@ -556,7 +562,8 @@ void pkgProblemResolver::MakeScores()
essantial package above most other packages but low enough
to allow an obsolete essential packages to be removed by
a conflicts on a powerfull normal package (ie libc6) */
- if ((I->Flags & pkgCache::Flag::Essential) == pkgCache::Flag::Essential)
+ if ((I->Flags & pkgCache::Flag::Essential) == pkgCache::Flag::Essential
+ || (I->Flags & pkgCache::Flag::Important) == pkgCache::Flag::Important)
Score += PrioEssentials;
// We transform the priority
@@ -631,7 +638,8 @@ void pkgProblemResolver::MakeScores()
{
if ((Flags[I->ID] & Protected) != 0)
Scores[I->ID] += AddProtected;
- if ((I->Flags & pkgCache::Flag::Essential) == pkgCache::Flag::Essential)
+ if ((I->Flags & pkgCache::Flag::Essential) == pkgCache::Flag::Essential ||
+ (I->Flags & pkgCache::Flag::Important) == pkgCache::Flag::Important)
Scores[I->ID] += AddEssential;
}
}
@@ -1430,6 +1438,13 @@ static int PrioComp(const void *A,const void *B)
if ((L.ParentPkg()->Flags & pkgCache::Flag::Essential) != pkgCache::Flag::Essential &&
(R.ParentPkg()->Flags & pkgCache::Flag::Essential) == pkgCache::Flag::Essential)
return -1;
+
+ if ((L.ParentPkg()->Flags & pkgCache::Flag::Important) == pkgCache::Flag::Important &&
+ (R.ParentPkg()->Flags & pkgCache::Flag::Important) != pkgCache::Flag::Important)
+ return 1;
+ if ((L.ParentPkg()->Flags & pkgCache::Flag::Important) != pkgCache::Flag::Important &&
+ (R.ParentPkg()->Flags & pkgCache::Flag::Important) == pkgCache::Flag::Important)
+ return -1;
if (L->Priority != R->Priority)
return R->Priority - L->Priority;
@@ -1444,7 +1459,7 @@ void pkgPrioSortList(pkgCache &Cache,pkgCache::Version **List)
qsort(List,Count,sizeof(*List),PrioComp);
}
/*}}}*/
-// ListUpdate - update the cache files /*{{{*/
+// ListUpdate - construct Fetcher and update the cache files /*{{{*/
// ---------------------------------------------------------------------
/* This is a simple wrapper to update the cache. it will fetch stuff
* from the network (or any other sources defined in sources.list)
@@ -1453,7 +1468,6 @@ bool ListUpdate(pkgAcquireStatus &Stat,
pkgSourceList &List,
int PulseInterval)
{
- pkgAcquire::RunResult res;
pkgAcquire Fetcher;
if (Fetcher.Setup(&Stat, _config->FindDir("Dir::State::Lists")) == false)
return false;
@@ -1462,11 +1476,24 @@ bool ListUpdate(pkgAcquireStatus &Stat,
if (List.GetIndexes(&Fetcher) == false)
return false;
+ return AcquireUpdate(Fetcher, PulseInterval, true);
+}
+ /*}}}*/
+// AcquireUpdate - take Fetcher and update the cache files /*{{{*/
+// ---------------------------------------------------------------------
+/* This is a simple wrapper to update the cache with a provided acquire
+ * If you only need control over Status and the used SourcesList use
+ * ListUpdate method instead.
+ */
+bool AcquireUpdate(pkgAcquire &Fetcher, int const PulseInterval,
+ bool const RunUpdateScripts, bool const ListCleanup)
+{
// Run scripts
- RunScripts("APT::Update::Pre-Invoke");
-
- // check arguments
- if(PulseInterval>0)
+ if (RunUpdateScripts == true)
+ RunScripts("APT::Update::Pre-Invoke");
+
+ pkgAcquire::RunResult res;
+ if(PulseInterval > 0)
res = Fetcher.Run(PulseInterval);
else
res = Fetcher.Run();
@@ -1503,7 +1530,7 @@ bool ListUpdate(pkgAcquireStatus &Stat,
// Clean out any old list files
// Keep "APT::Get::List-Cleanup" name for compatibility, but
// this is really a global option for the APT library now
- if (!TransientNetworkFailure && !Failed &&
+ if (!TransientNetworkFailure && !Failed && ListCleanup == true &&
(_config->FindB("APT::Get::List-Cleanup",true) == true &&
_config->FindB("APT::List-Cleanup",true) == true))
{
@@ -1520,11 +1547,14 @@ bool ListUpdate(pkgAcquireStatus &Stat,
// Run the success scripts if all was fine
- if(!TransientNetworkFailure && !Failed)
- RunScripts("APT::Update::Post-Invoke-Success");
+ if (RunUpdateScripts == true)
+ {
+ if(!TransientNetworkFailure && !Failed)
+ RunScripts("APT::Update::Post-Invoke-Success");
- // Run the other scripts
- RunScripts("APT::Update::Post-Invoke");
+ // Run the other scripts
+ RunScripts("APT::Update::Post-Invoke");
+ }
return true;
}
/*}}}*/
diff --git a/apt-pkg/algorithms.h b/apt-pkg/algorithms.h
index 37eacf1f8..aff8a68f2 100644
--- a/apt-pkg/algorithms.h
+++ b/apt-pkg/algorithms.h
@@ -78,6 +78,7 @@ private:
public:
pkgSimulate(pkgDepCache *Cache);
+ ~pkgSimulate();
};
/*}}}*/
class pkgProblemResolver /*{{{*/
@@ -147,5 +148,7 @@ bool pkgMinimizeUpgrade(pkgDepCache &Cache);
void pkgPrioSortList(pkgCache &Cache,pkgCache::Version **List);
bool ListUpdate(pkgAcquireStatus &progress, pkgSourceList &List, int PulseInterval=0);
-
+bool AcquireUpdate(pkgAcquire &Fetcher, int const PulseInterval = 0,
+ bool const RunUpdateScripts = true, bool const ListCleanup = true);
+
#endif
diff --git a/apt-pkg/aptconfiguration.cc b/apt-pkg/aptconfiguration.cc
index b5ad74831..d763546f8 100644
--- a/apt-pkg/aptconfiguration.cc
+++ b/apt-pkg/aptconfiguration.cc
@@ -47,6 +47,7 @@ const Configuration::getCompressionTypes(bool const &Cached) {
_config->CndSet("Acquire::CompressionTypes::gz","gzip");
setDefaultConfigurationForCompressors();
+ std::vector<APT::Configuration::Compressor> const compressors = getCompressors();
// accept non-list order as override setting for config settings on commandline
std::string const overrideOrder = _config->Find("Acquire::CompressionTypes::Order","");
@@ -60,15 +61,17 @@ const Configuration::getCompressionTypes(bool const &Cached) {
if ((*o).empty() == true)
continue;
// ignore types we have no method ready to use
- if (_config->Exists(std::string("Acquire::CompressionTypes::").append(*o)) == false)
+ std::string const method = std::string("Acquire::CompressionTypes::").append(*o);
+ if (_config->Exists(method) == false)
continue;
// ignore types we have no app ready to use
- std::string const appsetting = std::string("Dir::Bin::").append(*o);
- if (_config->Exists(appsetting) == true) {
- std::string const app = _config->FindFile(appsetting.c_str(), "");
- if (app.empty() == false && FileExists(app) == false)
- continue;
- }
+ std::string const app = _config->Find(method);
+ std::vector<APT::Configuration::Compressor>::const_iterator c = compressors.begin();
+ for (; c != compressors.end(); ++c)
+ if (c->Name == app)
+ break;
+ if (c == compressors.end())
+ continue;
types.push_back(*o);
}
@@ -84,12 +87,12 @@ const Configuration::getCompressionTypes(bool const &Cached) {
if (std::find(types.begin(),types.end(),Types->Tag) != types.end())
continue;
// ignore types we have no app ready to use
- std::string const appsetting = std::string("Dir::Bin::").append(Types->Value);
- if (appsetting.empty() == false && _config->Exists(appsetting) == true) {
- std::string const app = _config->FindFile(appsetting.c_str(), "");
- if (app.empty() == false && FileExists(app) == false)
- continue;
- }
+ std::vector<APT::Configuration::Compressor>::const_iterator c = compressors.begin();
+ for (; c != compressors.end(); ++c)
+ if (c->Name == Types->Value)
+ break;
+ if (c == compressors.end())
+ continue;
types.push_back(Types->Tag);
}
@@ -141,7 +144,7 @@ std::vector<std::string> const Configuration::getLanguages(bool const &All,
if (D != 0) {
builtin.push_back("none");
for (struct dirent *Ent = readdir(D); Ent != 0; Ent = readdir(D)) {
- string const name = Ent->d_name;
+ string const name = SubstVar(Ent->d_name, "%5f", "_");
size_t const foundDash = name.rfind("-");
size_t const foundUnderscore = name.rfind("_", foundDash);
if (foundDash == string::npos || foundUnderscore == string::npos ||
@@ -376,7 +379,7 @@ std::vector<std::string> const Configuration::getArchitectures(bool const &Cache
dup2(nullfd, STDIN_FILENO);
dup2(external[1], STDOUT_FILENO);
dup2(nullfd, STDERR_FILENO);
- execv(Args[0], (char**) &Args[0]);
+ execvp(Args[0], (char**) &Args[0]);
_error->WarningE("getArchitecture", "Can't detect foreign architectures supported by dpkg!");
_exit(100);
}
@@ -392,7 +395,9 @@ std::vector<std::string> const Configuration::getArchitectures(bool const &Cache
if (arch[0] != '\0') {
char const* archend = arch;
for (; isspace(*archend) == 0 && *archend != '\0'; ++archend);
- archs.push_back(string(arch, (archend - arch)));
+ string a(arch, (archend - arch));
+ if (std::find(archs.begin(), archs.end(), a) == archs.end())
+ archs.push_back(a);
}
arch = strtok(NULL, " ");
}
@@ -430,9 +435,30 @@ bool const Configuration::checkArchitecture(std::string const &Arch) {
// setDefaultConfigurationForCompressors /*{{{*/
void Configuration::setDefaultConfigurationForCompressors() {
// Set default application paths to check for optional compression types
- _config->CndSet("Dir::Bin::lzma", "/usr/bin/lzma");
- _config->CndSet("Dir::Bin::xz", "/usr/bin/xz");
_config->CndSet("Dir::Bin::bzip2", "/bin/bzip2");
+ _config->CndSet("Dir::Bin::xz", "/usr/bin/xz");
+ if (FileExists(_config->FindFile("Dir::Bin::xz")) == true) {
+ _config->Clear("Dir::Bin::lzma");
+ _config->Set("APT::Compressor::lzma::Binary", "xz");
+ if (_config->Exists("APT::Compressor::lzma::CompressArg") == false) {
+ _config->Set("APT::Compressor::lzma::CompressArg::", "--format=lzma");
+ _config->Set("APT::Compressor::lzma::CompressArg::", "-9");
+ }
+ if (_config->Exists("APT::Compressor::lzma::UncompressArg") == false) {
+ _config->Set("APT::Compressor::lzma::UncompressArg::", "--format=lzma");
+ _config->Set("APT::Compressor::lzma::UncompressArg::", "-d");
+ }
+ } else {
+ _config->CndSet("Dir::Bin::lzma", "/usr/bin/lzma");
+ if (_config->Exists("APT::Compressor::lzma::CompressArg") == false) {
+ _config->Set("APT::Compressor::lzma::CompressArg::", "--suffix=");
+ _config->Set("APT::Compressor::lzma::CompressArg::", "-9");
+ }
+ if (_config->Exists("APT::Compressor::lzma::UncompressArg") == false) {
+ _config->Set("APT::Compressor::lzma::UncompressArg::", "--suffix=");
+ _config->Set("APT::Compressor::lzma::UncompressArg::", "-d");
+ }
+ }
}
/*}}}*/
// getCompressors - Return Vector of usbale compressors /*{{{*/
@@ -451,15 +477,23 @@ const Configuration::getCompressors(bool const Cached) {
setDefaultConfigurationForCompressors();
- compressors.push_back(Compressor(".", "", "", "", "", 1));
+ compressors.push_back(Compressor(".", "", "", NULL, NULL, 1));
if (_config->Exists("Dir::Bin::gzip") == false || FileExists(_config->FindFile("Dir::Bin::gzip")) == true)
compressors.push_back(Compressor("gzip",".gz","gzip","-9n","-d",2));
+#ifdef HAVE_ZLIB
+ else
+ compressors.push_back(Compressor("gzip",".gz","false", NULL, NULL, 2));
+#endif
if (_config->Exists("Dir::Bin::bzip2") == false || FileExists(_config->FindFile("Dir::Bin::bzip2")) == true)
compressors.push_back(Compressor("bzip2",".bz2","bzip2","-9","-d",3));
- if (_config->Exists("Dir::Bin::lzma") == false || FileExists(_config->FindFile("Dir::Bin::lzma")) == true)
- compressors.push_back(Compressor("lzma",".lzma","lzma","-9","-d",4));
+#ifdef HAVE_BZ2
+ else
+ compressors.push_back(Compressor("bzip2",".bz2","false", NULL, NULL, 3));
+#endif
if (_config->Exists("Dir::Bin::xz") == false || FileExists(_config->FindFile("Dir::Bin::xz")) == true)
- compressors.push_back(Compressor("xz",".xz","xz","-6","-d",5));
+ compressors.push_back(Compressor("xz",".xz","xz","-6","-d",4));
+ if (_config->Exists("Dir::Bin::lzma") == false || FileExists(_config->FindFile("Dir::Bin::lzma")) == true)
+ compressors.push_back(Compressor("lzma",".lzma","lzma","-9","-d",5));
std::vector<std::string> const comp = _config->FindVector("APT::Compressor");
for (std::vector<std::string>::const_iterator c = comp.begin();
@@ -492,7 +526,7 @@ Configuration::Compressor::Compressor(char const *name, char const *extension,
char const *binary,
char const *compressArg, char const *uncompressArg,
unsigned short const cost) {
- std::string const config = std::string("APT:Compressor::").append(name).append("::");
+ std::string const config = std::string("APT::Compressor::").append(name).append("::");
Name = _config->Find(std::string(config).append("Name"), name);
Extension = _config->Find(std::string(config).append("Extension"), extension);
Binary = _config->Find(std::string(config).append("Binary"), binary);
diff --git a/apt-pkg/cachefile.cc b/apt-pkg/cachefile.cc
index dfbd8b1d8..7c2276185 100644
--- a/apt-pkg/cachefile.cc
+++ b/apt-pkg/cachefile.cc
@@ -178,6 +178,40 @@ void pkgCacheFile::RemoveCaches()
unlink(pkgcache.c_str());
if (srcpkgcache.empty() == false && RealFileExists(srcpkgcache) == true)
unlink(srcpkgcache.c_str());
+ if (pkgcache.empty() == false)
+ {
+ std::string cachedir = flNotFile(pkgcache);
+ std::string cachefile = flNotDir(pkgcache);
+ if (cachedir.empty() != true && cachefile.empty() != true && DirectoryExists(cachedir) == true)
+ {
+ cachefile.append(".");
+ std::vector<std::string> caches = GetListOfFilesInDir(cachedir, false);
+ for (std::vector<std::string>::const_iterator file = caches.begin(); file != caches.end(); ++file)
+ {
+ std::string nuke = flNotDir(*file);
+ if (strncmp(cachefile.c_str(), nuke.c_str(), cachefile.length()) != 0)
+ continue;
+ unlink(file->c_str());
+ }
+ }
+ }
+
+ if (srcpkgcache.empty() == true)
+ return;
+
+ std::string cachedir = flNotFile(srcpkgcache);
+ std::string cachefile = flNotDir(srcpkgcache);
+ if (cachedir.empty() == true || cachefile.empty() == true || DirectoryExists(cachedir) == false)
+ return;
+ cachefile.append(".");
+ std::vector<std::string> caches = GetListOfFilesInDir(cachedir, false);
+ for (std::vector<std::string>::const_iterator file = caches.begin(); file != caches.end(); ++file)
+ {
+ std::string nuke = flNotDir(*file);
+ if (strncmp(cachefile.c_str(), nuke.c_str(), cachefile.length()) != 0)
+ continue;
+ unlink(file->c_str());
+ }
}
/*}}}*/
// CacheFile::Close - close the cache files /*{{{*/
diff --git a/apt-pkg/cachefilter.cc b/apt-pkg/cachefilter.cc
index 9ec3fa699..fb444208c 100644
--- a/apt-pkg/cachefilter.cc
+++ b/apt-pkg/cachefilter.cc
@@ -10,11 +10,11 @@
#include <apt-pkg/error.h>
#include <apt-pkg/pkgcache.h>
-#include <apti18n.h>
-
#include <string>
#include <regex.h>
+
+#include <apti18n.h>
/*}}}*/
namespace APT {
namespace CacheFilter {
diff --git a/apt-pkg/cacheset.h b/apt-pkg/cacheset.h
index 91d7eec1c..5b9900603 100644
--- a/apt-pkg/cacheset.h
+++ b/apt-pkg/cacheset.h
@@ -186,11 +186,13 @@ public: /*{{{*/
pkgCache::PkgIterator getPkg(void) const { return *_iter; }
inline pkgCache::PkgIterator operator*(void) const { return *_iter; };
operator typename Container::iterator(void) const { return _iter; }
- operator typename PackageContainer<Container>::const_iterator() { return PackageContainer<Container>::const_iterator(_iter); }
+ operator typename PackageContainer<Container>::const_iterator() { return typename PackageContainer<Container>::const_iterator(_iter); }
inline iterator& operator++() { ++_iter; return *this; }
inline iterator operator++(int) { iterator tmp(*this); operator++(); return tmp; }
inline bool operator!=(iterator const &i) const { return _iter != i._iter; };
inline bool operator==(iterator const &i) const { return _iter == i._iter; };
+ inline iterator& operator=(iterator const &i) { _iter = i._iter; return *this; };
+ inline iterator& operator=(typename Container::iterator const &i) { _iter = i; return *this; };
friend std::ostream& operator<<(std::ostream& out, iterator i) { return operator<<(out, *i); }
};
/*}}}*/
@@ -201,7 +203,9 @@ public: /*{{{*/
bool empty() const { return _cont.empty(); };
void clear() { return _cont.clear(); };
+ //FIXME: on ABI break, replace the first with the second without bool
void erase(iterator position) { _cont.erase((typename Container::iterator)position); };
+ iterator& erase(iterator &position, bool) { return position = _cont.erase((typename Container::iterator)position); };
size_t erase(const pkgCache::PkgIterator x) { return _cont.erase(x); };
void erase(iterator first, iterator last) { _cont.erase(first, last); };
size_t size() const { return _cont.size(); };
@@ -502,11 +506,13 @@ public: /*{{{*/
pkgCache::VerIterator getVer(void) const { return *_iter; }
inline pkgCache::VerIterator operator*(void) const { return *_iter; };
operator typename Container::iterator(void) const { return _iter; }
- operator typename VersionContainer<Container>::const_iterator() { return VersionContainer<Container>::const_iterator(_iter); }
+ operator typename VersionContainer<Container>::const_iterator() { return typename VersionContainer<Container>::const_iterator(_iter); }
inline iterator& operator++() { ++_iter; return *this; }
inline iterator operator++(int) { iterator tmp(*this); operator++(); return tmp; }
inline bool operator!=(iterator const &i) const { return _iter != i._iter; };
inline bool operator==(iterator const &i) const { return _iter == i._iter; };
+ inline iterator& operator=(iterator const &i) { _iter = i._iter; return *this; };
+ inline iterator& operator=(typename Container::iterator const &i) { _iter = i; return *this; };
friend std::ostream& operator<<(std::ostream& out, iterator i) { return operator<<(out, *i); }
};
/*}}}*/
@@ -516,7 +522,9 @@ public: /*{{{*/
void insert(const_iterator begin, const_iterator end) { _cont.insert(begin, end); };
bool empty() const { return _cont.empty(); };
void clear() { return _cont.clear(); };
+ //FIXME: on ABI break, replace the first with the second without bool
void erase(iterator position) { _cont.erase((typename Container::iterator)position); };
+ iterator& erase(iterator &position, bool) { return position = _cont.erase((typename Container::iterator)position); };
size_t erase(const pkgCache::VerIterator x) { return _cont.erase(x); };
void erase(iterator first, iterator last) { _cont.erase(first, last); };
size_t size() const { return _cont.size(); };
diff --git a/apt-pkg/cdrom.cc b/apt-pkg/cdrom.cc
index 4462d4e24..c10ca6bd1 100644
--- a/apt-pkg/cdrom.cc
+++ b/apt-pkg/cdrom.cc
@@ -409,28 +409,12 @@ bool pkgCdrom::WriteDatabase(Configuration &Cnf)
/* Write out all of the configuration directives by walking the
configuration tree */
- const Configuration::Item *Top = Cnf.Tree(0);
- for (; Top != 0;)
- {
- // Print the config entry
- if (Top->Value.empty() == false)
- Out << Top->FullTag() + " \"" << Top->Value << "\";" << endl;
-
- if (Top->Child != 0)
- {
- Top = Top->Child;
- continue;
- }
-
- while (Top != 0 && Top->Next == 0)
- Top = Top->Parent;
- if (Top != 0)
- Top = Top->Next;
- }
+ _config->Dump(Out, NULL, "%f \"%v\";\n", false);
Out.close();
-
- link(DFile.c_str(),string(DFile + '~').c_str());
+
+ if (FileExists(DFile) == true && link(DFile.c_str(),string(DFile + '~').c_str()) != 0)
+ return _error->Errno("link", "Failed to link %s to %s~", DFile.c_str(), DFile.c_str());
if (rename(NewFile.c_str(),DFile.c_str()) != 0)
return _error->Errno("rename","Failed to rename %s.new to %s",
DFile.c_str(),DFile.c_str());
@@ -697,7 +681,8 @@ bool pkgCdrom::Add(pkgCdromStatus *log) /*{{{*/
return false;
}
- chdir(StartDir.c_str());
+ if (chdir(StartDir.c_str()) != 0)
+ return _error->Errno("chdir","Unable to change to %s", StartDir.c_str());
if (_config->FindB("Debug::aptcdrom",false) == true)
{
diff --git a/apt-pkg/clean.cc b/apt-pkg/clean.cc
index ed8fa1aa9..9c167eaa5 100644
--- a/apt-pkg/clean.cc
+++ b/apt-pkg/clean.cc
@@ -54,9 +54,11 @@ bool pkgArchiveCleaner::Go(std::string Dir,pkgCache &Cache)
struct stat St;
if (stat(Dir->d_name,&St) != 0)
{
- chdir(StartDir.c_str());
+ _error->Errno("stat",_("Unable to stat %s."),Dir->d_name);
closedir(D);
- return _error->Errno("stat",_("Unable to stat %s."),Dir->d_name);
+ if (chdir(StartDir.c_str()) != 0)
+ return _error->Errno("chdir", _("Unable to change to %s"), StartDir.c_str());
+ return false;
}
// Grab the package name
@@ -115,8 +117,9 @@ bool pkgArchiveCleaner::Go(std::string Dir,pkgCache &Cache)
Erase(Dir->d_name,Pkg,Ver,St);
};
- chdir(StartDir.c_str());
closedir(D);
- return true;
+ if (chdir(StartDir.c_str()) != 0)
+ return _error->Errno("chdir", _("Unable to change to %s"), StartDir.c_str());
+ return true;
}
/*}}}*/
diff --git a/apt-pkg/contrib/configuration.cc b/apt-pkg/contrib/configuration.cc
index 36866a35a..4de17e3e1 100644
--- a/apt-pkg/contrib/configuration.cc
+++ b/apt-pkg/contrib/configuration.cc
@@ -171,48 +171,60 @@ string Configuration::Find(const char *Name,const char *Default) const
string Configuration::FindFile(const char *Name,const char *Default) const
{
const Item *RootItem = Lookup("RootDir");
- std::string rootDir = (RootItem == 0) ? "" : RootItem->Value;
- if(rootDir.size() > 0 && rootDir[rootDir.size() - 1] != '/')
- rootDir.push_back('/');
+ std::string result = (RootItem == 0) ? "" : RootItem->Value;
+ if(result.empty() == false && result[result.size() - 1] != '/')
+ result.push_back('/');
const Item *Itm = Lookup(Name);
if (Itm == 0 || Itm->Value.empty() == true)
{
- if (Default == 0)
- return rootDir;
- else
- return rootDir + Default;
+ if (Default != 0)
+ result.append(Default);
}
-
- string val = Itm->Value;
- while (Itm->Parent != 0)
+ else
{
- if (Itm->Parent->Value.empty() == true)
+ string val = Itm->Value;
+ while (Itm->Parent != 0)
{
- Itm = Itm->Parent;
- continue;
- }
+ if (Itm->Parent->Value.empty() == true)
+ {
+ Itm = Itm->Parent;
+ continue;
+ }
+
+ // Absolute
+ if (val.length() >= 1 && val[0] == '/')
+ {
+ if (val.compare(0, 9, "/dev/null") == 0)
+ val.erase(9);
+ break;
+ }
- // Absolute
- if (val.length() >= 1 && val[0] == '/')
- break;
+ // ~/foo or ./foo
+ if (val.length() >= 2 && (val[0] == '~' || val[0] == '.') && val[1] == '/')
+ break;
- // ~/foo or ./foo
- if (val.length() >= 2 && (val[0] == '~' || val[0] == '.') && val[1] == '/')
- break;
-
- // ../foo
- if (val.length() >= 3 && val[0] == '.' && val[1] == '.' && val[2] == '/')
- break;
-
- if (Itm->Parent->Value.end()[-1] != '/')
- val.insert(0, "/");
+ // ../foo
+ if (val.length() >= 3 && val[0] == '.' && val[1] == '.' && val[2] == '/')
+ break;
+
+ if (Itm->Parent->Value.end()[-1] != '/')
+ val.insert(0, "/");
- val.insert(0, Itm->Parent->Value);
- Itm = Itm->Parent;
+ val.insert(0, Itm->Parent->Value);
+ Itm = Itm->Parent;
+ }
+ result.append(val);
}
- return rootDir + val;
+ // do some normalisation by removing // and /./ from the path
+ size_t found = string::npos;
+ while ((found = result.find("/./")) != string::npos)
+ result.replace(found, 3, "/");
+ while ((found = result.find("//")) != string::npos)
+ result.replace(found, 2, "/");
+
+ return result;
}
/*}}}*/
// Configuration::FindDir - Find a directory name /*{{{*/
@@ -222,7 +234,12 @@ string Configuration::FindDir(const char *Name,const char *Default) const
{
string Res = FindFile(Name,Default);
if (Res.end()[-1] != '/')
+ {
+ size_t const found = Res.rfind("/dev/null");
+ if (found != string::npos && found == Res.size() - 9)
+ return Res; // /dev/null returning
return Res + '/';
+ }
return Res;
}
/*}}}*/
@@ -482,24 +499,80 @@ bool Configuration::ExistsAny(const char *Name) const
/* Dump the entire configuration space */
void Configuration::Dump(ostream& str)
{
- /* Write out all of the configuration directives by walking the
+ Dump(str, NULL, "%f \"%v\";\n", true);
+}
+void Configuration::Dump(ostream& str, char const * const root,
+ char const * const formatstr, bool const emptyValue)
+{
+ const Configuration::Item* Top = Tree(root);
+ if (Top == 0)
+ return;
+ const Configuration::Item* const Root = (root == NULL) ? NULL : Top;
+ std::vector<std::string> const format = VectorizeString(formatstr, '%');
+
+ /* Write out all of the configuration directives by walking the
configuration tree */
- const Configuration::Item *Top = Tree(0);
- for (; Top != 0;)
- {
- str << Top->FullTag() << " \"" << Top->Value << "\";" << endl;
-
+ do {
+ if (emptyValue == true || Top->Value.empty() == emptyValue)
+ {
+ std::vector<std::string>::const_iterator f = format.begin();
+ str << *f;
+ for (++f; f != format.end(); ++f)
+ {
+ if (f->empty() == true)
+ {
+ ++f;
+ str << '%' << *f;
+ continue;
+ }
+ char const type = (*f)[0];
+ if (type == 'f')
+ str << Top->FullTag();
+ else if (type == 't')
+ str << Top->Tag;
+ else if (type == 'v')
+ str << Top->Value;
+ else if (type == 'F')
+ str << QuoteString(Top->FullTag(), "=\"\n");
+ else if (type == 'T')
+ str << QuoteString(Top->Tag, "=\"\n");
+ else if (type == 'V')
+ str << QuoteString(Top->Value, "=\"\n");
+ else if (type == 'n')
+ str << "\n";
+ else if (type == 'N')
+ str << "\t";
+ else
+ str << '%' << type;
+ str << f->c_str() + 1;
+ }
+ }
+
if (Top->Child != 0)
{
Top = Top->Child;
continue;
}
-
+
while (Top != 0 && Top->Next == 0)
Top = Top->Parent;
if (Top != 0)
Top = Top->Next;
- }
+
+ if (Root != NULL)
+ {
+ const Configuration::Item* I = Top;
+ while(I != 0)
+ {
+ if (I == Root)
+ break;
+ else
+ I = I->Parent;
+ }
+ if (I == 0)
+ break;
+ }
+ } while (Top != 0);
}
/*}}}*/
diff --git a/apt-pkg/contrib/configuration.h b/apt-pkg/contrib/configuration.h
index 4c2e75041..ea94c2fe6 100644
--- a/apt-pkg/contrib/configuration.h
+++ b/apt-pkg/contrib/configuration.h
@@ -103,6 +103,8 @@ class Configuration
inline void Dump() { Dump(std::clog); };
void Dump(std::ostream& str);
+ void Dump(std::ostream& str, char const * const root,
+ char const * const format, bool const emptyValue);
Configuration(const Item *Root);
Configuration();
diff --git a/apt-pkg/contrib/fileutl.cc b/apt-pkg/contrib/fileutl.cc
index 529e7d655..c7f78cdfb 100644
--- a/apt-pkg/contrib/fileutl.cc
+++ b/apt-pkg/contrib/fileutl.cc
@@ -44,14 +44,11 @@
#include <set>
#include <algorithm>
-// FIXME: Compressor Fds have some speed disadvantages and are a bit buggy currently,
-// so while the current implementation satisfies the testcases it is not a real option
-// to disable it for now
-#define APT_USE_ZLIB 1
-#if APT_USE_ZLIB
-#include <zlib.h>
-#else
-#pragma message "Usage of zlib is DISABLED!"
+#ifdef HAVE_ZLIB
+ #include <zlib.h>
+#endif
+#ifdef HAVE_BZ2
+ #include <bzlib.h>
#endif
#ifdef WORDS_BIGENDIAN
@@ -65,19 +62,50 @@ using namespace std;
class FileFdPrivate {
public:
-#if APT_USE_ZLIB
+#ifdef HAVE_ZLIB
gzFile gz;
#else
void* gz;
#endif
+#ifdef HAVE_BZ2
+ BZFILE* bz2;
+#else
+ void* bz2;
+#endif
int compressed_fd;
pid_t compressor_pid;
bool pipe;
APT::Configuration::Compressor compressor;
unsigned int openmode;
unsigned long long seekpos;
- FileFdPrivate() : gz(NULL), compressed_fd(-1), compressor_pid(-1), pipe(false),
+ FileFdPrivate() : gz(NULL), bz2(NULL),
+ compressed_fd(-1), compressor_pid(-1), pipe(false),
openmode(0), seekpos(0) {};
+ bool CloseDown(std::string const &FileName)
+ {
+ bool Res = true;
+#ifdef HAVE_ZLIB
+ if (gz != NULL) {
+ int const e = gzclose(gz);
+ gz = NULL;
+ // gzdclose() on empty files always fails with "buffer error" here, ignore that
+ if (e != 0 && e != Z_BUF_ERROR)
+ Res &= _error->Errno("close",_("Problem closing the gzip file %s"), FileName.c_str());
+ }
+#endif
+#ifdef HAVE_BZ2
+ if (bz2 != NULL) {
+ BZ2_bzclose(bz2);
+ bz2 = NULL;
+ }
+#endif
+ if (compressor_pid > 0)
+ ExecWait(compressor_pid, "FileFdCompressor", true);
+ compressor_pid = -1;
+
+ return Res;
+ }
+ ~FileFdPrivate() { CloseDown(""); }
};
// RunScripts - Run a set of scripts from a configuration subtree /*{{{*/
@@ -387,6 +415,13 @@ std::vector<string> GetListOfFilesInDir(string const &Dir, std::vector<string> c
{
if (RealFileExists(File.c_str()) == false)
{
+ // do not show ignoration warnings for directories
+ if (
+#ifdef _DIRENT_HAVE_D_TYPE
+ Ent->d_type == DT_DIR ||
+#endif
+ DirectoryExists(File.c_str()) == true)
+ continue;
if (SilentIgnore.Match(Ent->d_name) == false)
_error->Notice(_("Ignoring '%s' in directory '%s' as it is not a regular file"), Ent->d_name, Dir.c_str());
continue;
@@ -458,6 +493,80 @@ std::vector<string> GetListOfFilesInDir(string const &Dir, std::vector<string> c
std::sort(List.begin(),List.end());
return List;
}
+std::vector<string> GetListOfFilesInDir(string const &Dir, bool SortList)
+{
+ bool const Debug = _config->FindB("Debug::GetListOfFilesInDir", false);
+ if (Debug == true)
+ std::clog << "Accept in " << Dir << " all regular files" << std::endl;
+
+ std::vector<string> List;
+
+ if (DirectoryExists(Dir.c_str()) == false)
+ {
+ _error->Error(_("List of files can't be created as '%s' is not a directory"), Dir.c_str());
+ return List;
+ }
+
+ DIR *D = opendir(Dir.c_str());
+ if (D == 0)
+ {
+ _error->Errno("opendir",_("Unable to read %s"),Dir.c_str());
+ return List;
+ }
+
+ for (struct dirent *Ent = readdir(D); Ent != 0; Ent = readdir(D))
+ {
+ // skip "hidden" files
+ if (Ent->d_name[0] == '.')
+ continue;
+
+ // Make sure it is a file and not something else
+ string const File = flCombine(Dir,Ent->d_name);
+#ifdef _DIRENT_HAVE_D_TYPE
+ if (Ent->d_type != DT_REG)
+#endif
+ {
+ if (RealFileExists(File.c_str()) == false)
+ {
+ if (Debug == true)
+ std::clog << "Bad file: " << Ent->d_name << " → it is not a real file" << std::endl;
+ continue;
+ }
+ }
+
+ // Skip bad filenames ala run-parts
+ const char *C = Ent->d_name;
+ for (; *C != 0; ++C)
+ if (isalpha(*C) == 0 && isdigit(*C) == 0
+ && *C != '_' && *C != '-' && *C != '.')
+ break;
+
+ // we don't reach the end of the name -> bad character included
+ if (*C != 0)
+ {
+ if (Debug == true)
+ std::clog << "Bad file: " << Ent->d_name << " → bad character »" << *C << "« in filename" << std::endl;
+ continue;
+ }
+
+ // skip filenames which end with a period. These are never valid
+ if (*(C - 1) == '.')
+ {
+ if (Debug == true)
+ std::clog << "Bad file: " << Ent->d_name << " → Period as last character" << std::endl;
+ continue;
+ }
+
+ if (Debug == true)
+ std::clog << "Accept file: " << Ent->d_name << " in " << Dir << std::endl;
+ List.push_back(File);
+ }
+ closedir(D);
+
+ if (SortList == true)
+ std::sort(List.begin(),List.end());
+ return List;
+}
/*}}}*/
// SafeGetCWD - This is a safer getcwd that returns a dynamic string /*{{{*/
// ---------------------------------------------------------------------
@@ -754,7 +863,6 @@ bool FileFd::Open(string FileName,unsigned int const Mode,CompressMode Compress,
if (Compress == Auto && (Mode & WriteOnly) == WriteOnly)
return _error->Error("Autodetection on %s only works in ReadOnly openmode!", FileName.c_str());
- // FIXME: Denote inbuilt compressors somehow - as we don't need to have the binaries for them
std::vector<APT::Configuration::Compressor> const compressors = APT::Configuration::getCompressors();
std::vector<APT::Configuration::Compressor>::const_iterator compressor = compressors.begin();
if (Compress == Auto)
@@ -822,8 +930,6 @@ bool FileFd::Open(string FileName,unsigned int const Mode,CompressMode Compress,
bool FileFd::Open(string FileName,unsigned int const Mode,APT::Configuration::Compressor const &compressor, unsigned long const Perms)
{
Close();
- d = new FileFdPrivate;
- d->openmode = Mode;
Flags = AutoClose;
if ((Mode & WriteOnly) != WriteOnly && (Mode & (Atomic | Create | Empty | Exclusive)) != 0)
@@ -917,8 +1023,6 @@ bool FileFd::OpenDescriptor(int Fd, unsigned int const Mode, CompressMode Compre
bool FileFd::OpenDescriptor(int Fd, unsigned int const Mode, APT::Configuration::Compressor const &compressor, bool AutoClose)
{
Close();
- d = new FileFdPrivate;
- d->openmode = Mode;
Flags = (AutoClose) ? FileFd::AutoClose : 0;
iFd = Fd;
this->FileName = "";
@@ -932,32 +1036,71 @@ bool FileFd::OpenDescriptor(int Fd, unsigned int const Mode, APT::Configuration:
}
bool FileFd::OpenInternDescriptor(unsigned int const Mode, APT::Configuration::Compressor const &compressor)
{
- d->compressor = compressor;
if (compressor.Name == "." || compressor.Binary.empty() == true)
return true;
-#if APT_USE_ZLIB
- else if (compressor.Name == "gzip")
+
+ if (d == NULL)
+ {
+ d = new FileFdPrivate();
+ d->openmode = Mode;
+ d->compressor = compressor;
+ }
+
+#ifdef HAVE_ZLIB
+ if (compressor.Name == "gzip")
{
+ if (d->gz != NULL)
+ {
+ gzclose(d->gz);
+ d->gz = NULL;
+ }
if ((Mode & ReadWrite) == ReadWrite)
d->gz = gzdopen(iFd, "r+");
else if ((Mode & WriteOnly) == WriteOnly)
d->gz = gzdopen(iFd, "w");
else
- d->gz = gzdopen (iFd, "r");
+ d->gz = gzdopen(iFd, "r");
if (d->gz == NULL)
return false;
Flags |= Compressed;
return true;
}
#endif
+#ifdef HAVE_BZ2
+ if (compressor.Name == "bzip2")
+ {
+ if (d->bz2 != NULL)
+ {
+ BZ2_bzclose(d->bz2);
+ d->bz2 = NULL;
+ }
+ if ((Mode & ReadWrite) == ReadWrite)
+ d->bz2 = BZ2_bzdopen(iFd, "r+");
+ else if ((Mode & WriteOnly) == WriteOnly)
+ d->bz2 = BZ2_bzdopen(iFd, "w");
+ else
+ d->bz2 = BZ2_bzdopen(iFd, "r");
+ if (d->bz2 == NULL)
+ return false;
+ Flags |= Compressed;
+ return true;
+ }
+#endif
+
+ // collect zombies here in case we reopen
+ if (d->compressor_pid > 0)
+ ExecWait(d->compressor_pid, "FileFdCompressor", true);
if ((Mode & ReadWrite) == ReadWrite)
+ {
+ Flags |= Fail;
return _error->Error("ReadWrite mode is not supported for file %s", FileName.c_str());
+ }
bool const Comp = (Mode & WriteOnly) == WriteOnly;
- // Handle 'decompression' of empty files
if (Comp == false)
{
+ // Handle 'decompression' of empty files
struct stat Buf;
fstat(iFd, &Buf);
if (Buf.st_size == 0 && S_ISFIFO(Buf.st_mode) == false)
@@ -966,13 +1109,19 @@ bool FileFd::OpenInternDescriptor(unsigned int const Mode, APT::Configuration::C
// We don't need the file open - instead let the compressor open it
// as he properly knows better how to efficiently read from 'his' file
if (FileName.empty() == false)
+ {
close(iFd);
+ iFd = -1;
+ }
}
// Create a data pipe
int Pipe[2] = {-1,-1};
if (pipe(Pipe) != 0)
+ {
+ Flags |= Fail;
return _error->Errno("pipe",_("Failed to create subprocess IPC"));
+ }
for (int J = 0; J != 2; J++)
SetCloseExec(Pipe[J],true);
@@ -999,6 +1148,12 @@ bool FileFd::OpenInternDescriptor(unsigned int const Mode, APT::Configuration::C
dup2(d->compressed_fd,STDIN_FILENO);
dup2(Pipe[1],STDOUT_FILENO);
}
+ int const nullfd = open("/dev/null", O_WRONLY);
+ if (nullfd != -1)
+ {
+ dup2(nullfd,STDERR_FILENO);
+ close(nullfd);
+ }
SetCloseExec(STDOUT_FILENO,false);
SetCloseExec(STDIN_FILENO,false);
@@ -1028,7 +1183,7 @@ bool FileFd::OpenInternDescriptor(unsigned int const Mode, APT::Configuration::C
close(Pipe[0]);
else
close(Pipe[1]);
- if (Comp == true || FileName.empty() == true)
+ if ((Comp == true || FileName.empty() == true) && d->compressed_fd != -1)
close(d->compressed_fd);
return true;
@@ -1041,6 +1196,12 @@ bool FileFd::OpenInternDescriptor(unsigned int const Mode, APT::Configuration::C
FileFd::~FileFd()
{
Close();
+ if (d != NULL)
+ {
+ d->CloseDown(FileName);
+ delete d;
+ d = NULL;
+ }
}
/*}}}*/
// FileFd::Read - Read a bit of the file /*{{{*/
@@ -1056,9 +1217,14 @@ bool FileFd::Read(void *To,unsigned long long Size,unsigned long long *Actual)
*((char *)To) = '\0';
do
{
-#if APT_USE_ZLIB
- if (d->gz != NULL)
- Res = gzread(d->gz,To,Size);
+#ifdef HAVE_ZLIB
+ if (d != NULL && d->gz != NULL)
+ Res = gzread(d->gz,To,Size);
+ else
+#endif
+#ifdef HAVE_BZ2
+ if (d != NULL && d->bz2 != NULL)
+ Res = BZ2_bzread(d->bz2,To,Size);
else
#endif
Res = read(iFd,To,Size);
@@ -1068,8 +1234,8 @@ bool FileFd::Read(void *To,unsigned long long Size,unsigned long long *Actual)
if (errno == EINTR)
continue;
Flags |= Fail;
-#if APT_USE_ZLIB
- if (d->gz != NULL)
+#ifdef HAVE_ZLIB
+ if (d != NULL && d->gz != NULL)
{
int err;
char const * const errmsg = gzerror(d->gz, &err);
@@ -1077,12 +1243,22 @@ bool FileFd::Read(void *To,unsigned long long Size,unsigned long long *Actual)
return _error->Error("gzread: %s (%d: %s)", _("Read error"), err, errmsg);
}
#endif
+#ifdef HAVE_BZ2
+ if (d != NULL && d->bz2 != NULL)
+ {
+ int err;
+ char const * const errmsg = BZ2_bzerror(d->bz2, &err);
+ if (err != BZ_IO_ERROR)
+ return _error->Error("BZ2_bzread: %s (%d: %s)", _("Read error"), err, errmsg);
+ }
+#endif
return _error->Errno("read",_("Read error"));
}
To = (char *)To + Res;
Size -= Res;
- d->seekpos += Res;
+ if (d != NULL)
+ d->seekpos += Res;
if (Actual != 0)
*Actual += Res;
}
@@ -1109,8 +1285,8 @@ bool FileFd::Read(void *To,unsigned long long Size,unsigned long long *Actual)
char* FileFd::ReadLine(char *To, unsigned long long const Size)
{
*To = '\0';
-#if APT_USE_ZLIB
- if (d->gz != NULL)
+#ifdef HAVE_ZLIB
+ if (d != NULL && d->gz != NULL)
return gzgets(d->gz, To, Size);
#endif
@@ -1140,23 +1316,47 @@ bool FileFd::Write(const void *From,unsigned long long Size)
errno = 0;
do
{
-#if APT_USE_ZLIB
- if (d->gz != NULL)
+#ifdef HAVE_ZLIB
+ if (d != NULL && d->gz != NULL)
Res = gzwrite(d->gz,From,Size);
else
#endif
+#ifdef HAVE_BZ2
+ if (d != NULL && d->bz2 != NULL)
+ Res = BZ2_bzwrite(d->bz2,(void*)From,Size);
+ else
+#endif
Res = write(iFd,From,Size);
if (Res < 0 && errno == EINTR)
continue;
if (Res < 0)
{
Flags |= Fail;
+#ifdef HAVE_ZLIB
+ if (d != NULL && d->gz != NULL)
+ {
+ int err;
+ char const * const errmsg = gzerror(d->gz, &err);
+ if (err != Z_ERRNO)
+ return _error->Error("gzwrite: %s (%d: %s)", _("Write error"), err, errmsg);
+ }
+#endif
+#ifdef HAVE_BZ2
+ if (d != NULL && d->bz2 != NULL)
+ {
+ int err;
+ char const * const errmsg = BZ2_bzerror(d->bz2, &err);
+ if (err != BZ_IO_ERROR)
+ return _error->Error("BZ2_bzwrite: %s (%d: %s)", _("Write error"), err, errmsg);
+ }
+#endif
return _error->Errno("write",_("Write error"));
}
From = (char *)From + Res;
Size -= Res;
- d->seekpos += Res;
+ if (d != NULL)
+ d->seekpos += Res;
}
while (Res > 0 && Size > 0);
@@ -1166,13 +1366,39 @@ bool FileFd::Write(const void *From,unsigned long long Size)
Flags |= Fail;
return _error->Error(_("write, still have %llu to write but couldn't"), Size);
}
+bool FileFd::Write(int Fd, const void *From, unsigned long long Size)
+{
+ int Res;
+ errno = 0;
+ do
+ {
+ Res = write(Fd,From,Size);
+ if (Res < 0 && errno == EINTR)
+ continue;
+ if (Res < 0)
+ return _error->Errno("write",_("Write error"));
+
+ From = (char *)From + Res;
+ Size -= Res;
+ }
+ while (Res > 0 && Size > 0);
+
+ if (Size == 0)
+ return true;
+
+ return _error->Error(_("write, still have %llu to write but couldn't"), Size);
+}
/*}}}*/
// FileFd::Seek - Seek in the file /*{{{*/
// ---------------------------------------------------------------------
/* */
bool FileFd::Seek(unsigned long long To)
{
- if (d->pipe == true)
+ if (d != NULL && (d->pipe == true
+#ifdef HAVE_BZ2
+ || d->bz2 != NULL
+#endif
+ ))
{
// Our poor man seeking in pipes is costly, so try to avoid it
unsigned long long seekpos = Tell();
@@ -1182,9 +1408,17 @@ bool FileFd::Seek(unsigned long long To)
return Skip(To - seekpos);
if ((d->openmode & ReadOnly) != ReadOnly)
+ {
+ Flags |= Fail;
return _error->Error("Reopen is only implemented for read-only files!");
- close(iFd);
- iFd = 0;
+ }
+#ifdef HAVE_BZ2
+ if (d->bz2 != NULL)
+ BZ2_bzclose(d->bz2);
+#endif
+ if (iFd != -1)
+ close(iFd);
+ iFd = -1;
if (TemporaryFileName.empty() == false)
iFd = open(TemporaryFileName.c_str(), O_RDONLY);
else if (FileName.empty() == false)
@@ -1194,12 +1428,18 @@ bool FileFd::Seek(unsigned long long To)
if (d->compressed_fd > 0)
if (lseek(d->compressed_fd, 0, SEEK_SET) != 0)
iFd = d->compressed_fd;
- if (iFd <= 0)
+ if (iFd < 0)
+ {
+ Flags |= Fail;
return _error->Error("Reopen is not implemented for pipes opened with FileFd::OpenDescriptor()!");
+ }
}
if (OpenInternDescriptor(d->openmode, d->compressor) == false)
+ {
+ Flags |= Fail;
return _error->Error("Seek on file %s because it couldn't be reopened", FileName.c_str());
+ }
if (To != 0)
return Skip(To);
@@ -1208,8 +1448,8 @@ bool FileFd::Seek(unsigned long long To)
return true;
}
int res;
-#if APT_USE_ZLIB
- if (d->gz)
+#ifdef HAVE_ZLIB
+ if (d != NULL && d->gz)
res = gzseek(d->gz,To,SEEK_SET);
else
#endif
@@ -1220,7 +1460,8 @@ bool FileFd::Seek(unsigned long long To)
return _error->Error("Unable to seek to %llu", To);
}
- d->seekpos = To;
+ if (d != NULL)
+ d->seekpos = To;
return true;
}
/*}}}*/
@@ -1229,7 +1470,11 @@ bool FileFd::Seek(unsigned long long To)
/* */
bool FileFd::Skip(unsigned long long Over)
{
- if (d->pipe == true)
+ if (d != NULL && (d->pipe == true
+#ifdef HAVE_BZ2
+ || d->bz2 != NULL
+#endif
+ ))
{
d->seekpos += Over;
char buffer[1024];
@@ -1237,15 +1482,18 @@ bool FileFd::Skip(unsigned long long Over)
{
unsigned long long toread = std::min((unsigned long long) sizeof(buffer), Over);
if (Read(buffer, toread) == false)
+ {
+ Flags |= Fail;
return _error->Error("Unable to seek ahead %llu",Over);
+ }
Over -= toread;
}
return true;
}
int res;
-#if APT_USE_ZLIB
- if (d->gz != NULL)
+#ifdef HAVE_ZLIB
+ if (d != NULL && d->gz != NULL)
res = gzseek(d->gz,Over,SEEK_CUR);
else
#endif
@@ -1255,7 +1503,8 @@ bool FileFd::Skip(unsigned long long Over)
Flags |= Fail;
return _error->Error("Unable to seek ahead %llu",Over);
}
- d->seekpos = res;
+ if (d != NULL)
+ d->seekpos = res;
return true;
}
@@ -1265,11 +1514,13 @@ bool FileFd::Skip(unsigned long long Over)
/* */
bool FileFd::Truncate(unsigned long long To)
{
- if (d->gz != NULL)
+#if defined HAVE_ZLIB || defined HAVE_BZ2
+ if (d != NULL && (d->gz != NULL || d->bz2 != NULL))
{
Flags |= Fail;
- return _error->Error("Truncating gzipped files is not implemented (%s)", FileName.c_str());
+ return _error->Error("Truncating compressed files is not implemented (%s)", FileName.c_str());
}
+#endif
if (ftruncate(iFd,To) != 0)
{
Flags |= Fail;
@@ -1288,19 +1539,27 @@ unsigned long long FileFd::Tell()
// seeking around, but not all users of FileFd use always Seek() and co
// so d->seekpos isn't always true and we can just use it as a hint if
// we have nothing else, but not always as an authority…
- if (d->pipe == true)
+ if (d != NULL && (d->pipe == true
+#ifdef HAVE_BZ2
+ || d->bz2 != NULL
+#endif
+ ))
return d->seekpos;
off_t Res;
-#if APT_USE_ZLIB
- if (d->gz != NULL)
+#ifdef HAVE_ZLIB
+ if (d != NULL && d->gz != NULL)
Res = gztell(d->gz);
else
#endif
Res = lseek(iFd,0,SEEK_CUR);
if (Res == (off_t)-1)
+ {
+ Flags |= Fail;
_error->Errno("lseek","Failed to determine the current file position");
- d->seekpos = Res;
+ }
+ if (d != NULL)
+ d->seekpos = Res;
return Res;
}
/*}}}*/
@@ -1310,17 +1569,24 @@ unsigned long long FileFd::Tell()
unsigned long long FileFd::FileSize()
{
struct stat Buf;
- if (d->pipe == false && fstat(iFd,&Buf) != 0)
+ if ((d == NULL || d->pipe == false) && fstat(iFd,&Buf) != 0)
+ {
+ Flags |= Fail;
return _error->Errno("fstat","Unable to determine the file size");
+ }
// for compressor pipes st_size is undefined and at 'best' zero
- if (d->pipe == true || S_ISFIFO(Buf.st_mode))
+ if ((d != NULL && d->pipe == true) || S_ISFIFO(Buf.st_mode))
{
// we set it here, too, as we get the info here for free
// in theory the Open-methods should take care of it already
- d->pipe = true;
+ if (d != NULL)
+ d->pipe = true;
if (stat(FileName.c_str(), &Buf) != 0)
+ {
+ Flags |= Fail;
return _error->Errno("stat","Unable to determine the file size");
+ }
}
return Buf.st_size;
@@ -1335,7 +1601,11 @@ unsigned long long FileFd::Size()
// for compressor pipes st_size is undefined and at 'best' zero,
// so we 'read' the content and 'seek' back - see there
- if (d->pipe == true)
+ if (d != NULL && (d->pipe == true
+#ifdef HAVE_BZ2
+ || (d->bz2 && size > 0)
+#endif
+ ))
{
unsigned long long const oldSeek = Tell();
char ignore[1000];
@@ -1346,11 +1616,11 @@ unsigned long long FileFd::Size()
size = Tell();
Seek(oldSeek);
}
-#if APT_USE_ZLIB
+#ifdef HAVE_ZLIB
// only check gzsize if we are actually a gzip file, just checking for
// "gz" is not sufficient as uncompressed files could be opened with
// gzopen in "direct" mode as well
- else if (d->gz && !gzdirect(d->gz) && size > 0)
+ else if (d != NULL && d->gz && !gzdirect(d->gz) && size > 0)
{
off_t const oldPos = lseek(iFd,0,SEEK_CUR);
/* unfortunately zlib.h doesn't provide a gzsize(), so we have to do
@@ -1358,10 +1628,16 @@ unsigned long long FileFd::Size()
* bits of the file */
// FIXME: Size for gz-files is limited by 32bit… no largefile support
if (lseek(iFd, -4, SEEK_END) < 0)
- return _error->Errno("lseek","Unable to seek to end of gzipped file");
+ {
+ Flags |= Fail;
+ return _error->Errno("lseek","Unable to seek to end of gzipped file");
+ }
size = 0L;
if (read(iFd, &size, 4) != 4)
- return _error->Errno("read","Unable to read original size of gzipped file");
+ {
+ Flags |= Fail;
+ return _error->Errno("read","Unable to read original size of gzipped file");
+ }
#ifdef WORDS_BIGENDIAN
uint32_t tmp_size = size;
@@ -1371,7 +1647,10 @@ unsigned long long FileFd::Size()
#endif
if (lseek(iFd, oldPos, SEEK_SET) < 0)
- return _error->Errno("lseek","Unable to seek in gzipped file");
+ {
+ Flags |= Fail;
+ return _error->Errno("lseek","Unable to seek in gzipped file");
+ }
return size;
}
@@ -1386,20 +1665,23 @@ unsigned long long FileFd::Size()
time_t FileFd::ModificationTime()
{
struct stat Buf;
- if (d->pipe == false && fstat(iFd,&Buf) != 0)
+ if ((d == NULL || d->pipe == false) && fstat(iFd,&Buf) != 0)
{
+ Flags |= Fail;
_error->Errno("fstat","Unable to determine the modification time of file %s", FileName.c_str());
return 0;
}
// for compressor pipes st_size is undefined and at 'best' zero
- if (d->pipe == true || S_ISFIFO(Buf.st_mode))
+ if ((d != NULL && d->pipe == true) || S_ISFIFO(Buf.st_mode))
{
// we set it here, too, as we get the info here for free
// in theory the Open-methods should take care of it already
- d->pipe = true;
+ if (d != NULL)
+ d->pipe = true;
if (stat(FileName.c_str(), &Buf) != 0)
{
+ Flags |= Fail;
_error->Errno("fstat","Unable to determine the modification time of file %s", FileName.c_str());
return 0;
}
@@ -1419,16 +1701,15 @@ bool FileFd::Close()
bool Res = true;
if ((Flags & AutoClose) == AutoClose)
{
-#if APT_USE_ZLIB
- if (d != NULL && d->gz != NULL) {
- int const e = gzclose(d->gz);
- // gzdclose() on empty files always fails with "buffer error" here, ignore that
- if (e != 0 && e != Z_BUF_ERROR)
- Res &= _error->Errno("close",_("Problem closing the gzip file %s"), FileName.c_str());
- } else
-#endif
- if (iFd > 0 && close(iFd) != 0)
- Res &= _error->Errno("close",_("Problem closing the file %s"), FileName.c_str());
+ 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);
+ delete d;
+ d = NULL;
+ }
}
if ((Flags & Replace) == Replace && iFd >= 0) {
@@ -1446,14 +1727,8 @@ bool FileFd::Close()
if (unlink(FileName.c_str()) != 0)
Res &= _error->WarningE("unlnk",_("Problem unlinking the file %s"), FileName.c_str());
- if (d != NULL)
- {
- if (d->compressor_pid > 0)
- ExecWait(d->compressor_pid, "FileFdCompressor", true);
- delete d;
- d = NULL;
- }
-
+ if (Res == false)
+ Flags |= Fail;
return Res;
}
/*}}}*/
@@ -1464,7 +1739,10 @@ bool FileFd::Sync()
{
#ifdef _POSIX_SYNCHRONIZED_IO
if (fsync(iFd) != 0)
+ {
+ Flags |= Fail;
return _error->Errno("sync",_("Problem syncing the file"));
+ }
#endif
return true;
}
diff --git a/apt-pkg/contrib/fileutl.h b/apt-pkg/contrib/fileutl.h
index 3814cfe44..426664d3a 100644
--- a/apt-pkg/contrib/fileutl.h
+++ b/apt-pkg/contrib/fileutl.h
@@ -78,6 +78,7 @@ class FileFd
bool Read(void *To,unsigned long long Size,unsigned long long *Actual = 0);
char* ReadLine(char *To, unsigned long long const Size);
bool Write(const void *From,unsigned long long Size);
+ bool static Write(int Fd, const void *From, unsigned long long Size);
bool Seek(unsigned long long To);
bool Skip(unsigned long long To);
bool Truncate(unsigned long long To);
@@ -171,6 +172,7 @@ std::vector<std::string> GetListOfFilesInDir(std::string const &Dir, std::string
bool const &SortList, bool const &AllowNoExt=false);
std::vector<std::string> GetListOfFilesInDir(std::string const &Dir, std::vector<std::string> const &Ext,
bool const &SortList);
+std::vector<std::string> GetListOfFilesInDir(std::string const &Dir, bool SortList);
std::string SafeGetCWD();
void SetCloseExec(int Fd,bool Close);
void SetNonBlock(int Fd,bool Block);
diff --git a/apt-pkg/contrib/mmap.cc b/apt-pkg/contrib/mmap.cc
index 160718ea5..2d12b6fe9 100644
--- a/apt-pkg/contrib/mmap.cc
+++ b/apt-pkg/contrib/mmap.cc
@@ -84,6 +84,7 @@ bool MMap::Map(FileFd &Fd)
if ((Flags & ReadOnly) != ReadOnly)
return _error->Error("Compressed file %s can only be mapped readonly", Fd.Name().c_str());
Base = new unsigned char[iSize];
+ SyncToFd = new FileFd();
if (Fd.Seek(0L) == false || Fd.Read(Base, iSize) == false)
return _error->Error("Compressed file %s can't be read into mmap", Fd.Name().c_str());
return true;
diff --git a/apt-pkg/contrib/netrc.cc b/apt-pkg/contrib/netrc.cc
index cb7d36088..56e59d84b 100644
--- a/apt-pkg/contrib/netrc.cc
+++ b/apt-pkg/contrib/netrc.cc
@@ -68,8 +68,7 @@ int parsenetrc (char *host, char *login, char *password, char *netrcfile = NULL)
if (!home)
return -1;
- asprintf (&netrcfile, "%s%s%s", home, DIR_CHAR, NETRC);
- if(!netrcfile)
+ if (asprintf (&netrcfile, "%s%s%s", home, DIR_CHAR, NETRC) == -1 || netrcfile == NULL)
return -1;
else
netrc_alloc = true;
diff --git a/apt-pkg/contrib/sha2_internal.cc b/apt-pkg/contrib/sha2_internal.cc
index 6d27e8f2b..83b5a98d3 100644
--- a/apt-pkg/contrib/sha2_internal.cc
+++ b/apt-pkg/contrib/sha2_internal.cc
@@ -552,7 +552,9 @@ void SHA256_Update(SHA256_CTX* context, const sha2_byte *data, size_t len) {
}
while (len >= SHA256_BLOCK_LENGTH) {
/* Process as many complete blocks as we can */
- SHA256_Transform(context, (sha2_word32*)data);
+ sha2_byte buffer[SHA256_BLOCK_LENGTH];
+ MEMCPY_BCOPY(buffer, data, SHA256_BLOCK_LENGTH);
+ SHA256_Transform(context, (sha2_word32*)buffer);
context->bitcount += SHA256_BLOCK_LENGTH << 3;
len -= SHA256_BLOCK_LENGTH;
data += SHA256_BLOCK_LENGTH;
@@ -879,7 +881,9 @@ void SHA512_Update(SHA512_CTX* context, const sha2_byte *data, size_t len) {
}
while (len >= SHA512_BLOCK_LENGTH) {
/* Process as many complete blocks as we can */
- SHA512_Transform(context, (sha2_word64*)data);
+ sha2_byte buffer[SHA512_BLOCK_LENGTH];
+ MEMCPY_BCOPY(buffer, data, SHA512_BLOCK_LENGTH);
+ SHA512_Transform(context, (sha2_word64*)buffer);
ADDINC128(context->bitcount, SHA512_BLOCK_LENGTH << 3);
len -= SHA512_BLOCK_LENGTH;
data += SHA512_BLOCK_LENGTH;
diff --git a/apt-pkg/contrib/strutl.cc b/apt-pkg/contrib/strutl.cc
index 861cdcbeb..ca096d736 100644
--- a/apt-pkg/contrib/strutl.cc
+++ b/apt-pkg/contrib/strutl.cc
@@ -23,6 +23,7 @@
#include <ctype.h>
#include <string.h>
+#include <sstream>
#include <stdio.h>
#include <algorithm>
#include <unistd.h>
@@ -910,17 +911,17 @@ bool StrToTime(const string &Val,time_t &Result)
// Handle RFC 1123 time
Month[0] = 0;
- if (sscanf(I," %d %3s %d %d:%d:%d GMT",&Tm.tm_mday,Month,&Tm.tm_year,
+ if (sscanf(I," %2d %3s %4d %2d:%2d:%2d GMT",&Tm.tm_mday,Month,&Tm.tm_year,
&Tm.tm_hour,&Tm.tm_min,&Tm.tm_sec) != 6)
{
// Handle RFC 1036 time
- if (sscanf(I," %d-%3s-%d %d:%d:%d GMT",&Tm.tm_mday,Month,
+ if (sscanf(I," %2d-%3s-%3d %2d:%2d:%2d GMT",&Tm.tm_mday,Month,
&Tm.tm_year,&Tm.tm_hour,&Tm.tm_min,&Tm.tm_sec) == 6)
Tm.tm_year += 1900;
else
{
// asctime format
- if (sscanf(I," %3s %d %d:%d:%d %d",Month,&Tm.tm_mday,
+ if (sscanf(I," %3s %2d %2d:%2d:%2d %4d",Month,&Tm.tm_mday,
&Tm.tm_hour,&Tm.tm_min,&Tm.tm_sec,&Tm.tm_year) != 6)
{
// 'ftp' time
@@ -1168,34 +1169,50 @@ unsigned long RegexChoice(RxChoiceList *Rxs,const char **ListBegin,
return Hits;
}
/*}}}*/
-// ioprintf - C format string outputter to C++ iostreams /*{{{*/
+// {str,io}printf - C format string outputter to C++ strings/iostreams /*{{{*/
// ---------------------------------------------------------------------
/* This is used to make the internationalization strings easier to translate
and to allow reordering of parameters */
-void ioprintf(ostream &out,const char *format,...)
+static bool iovprintf(ostream &out, const char *format,
+ va_list &args, ssize_t &size) {
+ char *S = (char*)malloc(size);
+ ssize_t const n = vsnprintf(S, size, format, args);
+ if (n > -1 && n < size) {
+ out << S;
+ free(S);
+ return true;
+ } else {
+ if (n > -1)
+ size = n + 1;
+ else
+ size *= 2;
+ }
+ free(S);
+ return false;
+}
+void ioprintf(ostream &out,const char *format,...)
{
va_list args;
- va_start(args,format);
-
- // sprintf the description
- char S[4096];
- vsnprintf(S,sizeof(S),format,args);
- out << S;
+ ssize_t size = 400;
+ while (true) {
+ va_start(args,format);
+ if (iovprintf(out, format, args, size) == true)
+ return;
+ va_end(args);
+ }
}
- /*}}}*/
-// strprintf - C format string outputter to C++ strings /*{{{*/
-// ---------------------------------------------------------------------
-/* This is used to make the internationalization strings easier to translate
- and to allow reordering of parameters */
-void strprintf(string &out,const char *format,...)
+void strprintf(string &out,const char *format,...)
{
va_list args;
- va_start(args,format);
-
- // sprintf the description
- char S[4096];
- vsnprintf(S,sizeof(S),format,args);
- out = string(S);
+ ssize_t size = 400;
+ std::ostringstream outstr;
+ while (true) {
+ va_start(args,format);
+ if (iovprintf(outstr, format, args, size) == true)
+ break;
+ va_end(args);
+ }
+ out = outstr.str();
}
/*}}}*/
// safe_snprintf - Safer snprintf /*{{{*/
diff --git a/apt-pkg/deb/debindexfile.cc b/apt-pkg/deb/debindexfile.cc
index 5dc2a2ac2..76c740341 100644
--- a/apt-pkg/deb/debindexfile.cc
+++ b/apt-pkg/deb/debindexfile.cc
@@ -161,7 +161,7 @@ unsigned long debSourcesIndex::Size() const
/* we need to ignore errors here; if the lists are absent, just return 0 */
_error->PushToStack();
- FileFd f = FileFd (IndexFile("Sources"), FileFd::ReadOnly, FileFd::Extension);
+ FileFd f(IndexFile("Sources"), FileFd::ReadOnly, FileFd::Extension);
if (!f.Failed())
size = f.Size();
@@ -290,7 +290,7 @@ unsigned long debPackagesIndex::Size() const
/* we need to ignore errors here; if the lists are absent, just return 0 */
_error->PushToStack();
- FileFd f = FileFd (IndexFile("Packages"), FileFd::ReadOnly, FileFd::Extension);
+ FileFd f(IndexFile("Packages"), FileFd::ReadOnly, FileFd::Extension);
if (!f.Failed())
size = f.Size();
@@ -488,7 +488,7 @@ unsigned long debTranslationsIndex::Size() const
/* we need to ignore errors here; if the lists are absent, just return 0 */
_error->PushToStack();
- FileFd f = FileFd (IndexFile(Language), FileFd::ReadOnly, FileFd::Extension);
+ FileFd f(IndexFile(Language), FileFd::ReadOnly, FileFd::Extension);
if (!f.Failed())
size = f.Size();
diff --git a/apt-pkg/deb/deblistparser.cc b/apt-pkg/deb/deblistparser.cc
index bdb50f6bf..7bef6772c 100644
--- a/apt-pkg/deb/deblistparser.cc
+++ b/apt-pkg/deb/deblistparser.cc
@@ -215,15 +215,22 @@ string debListParser::DescriptionLanguage()
*/
MD5SumValue debListParser::Description_md5()
{
- string value = Section.FindS("Description-md5");
-
- if (value.empty())
+ string const value = Section.FindS("Description-md5");
+ if (value.empty() == true)
{
MD5Summation md5;
md5.Add((Description() + "\n").c_str());
return md5.Result();
- } else
- return MD5SumValue(value);
+ }
+ else if (likely(value.size() == 32))
+ {
+ if (likely(value.find_first_not_of("0123456789abcdefABCDEF") == string::npos))
+ return MD5SumValue(value);
+ _error->Error("Malformed Description-md5 line; includes invalid character '%s'", value.c_str());
+ return MD5SumValue();
+ }
+ _error->Error("Malformed Description-md5 line; doesn't have the required length (32 != %d) '%s'", (int)value.size(), value.c_str());
+ return MD5SumValue();
}
/*}}}*/
// ListParser::UsePackage - Update a package structure /*{{{*/
@@ -249,8 +256,14 @@ bool debListParser::UsePackage(pkgCache::PkgIterator &Pkg,
return false;
if (strcmp(Pkg.Name(),"apt") == 0)
- Pkg->Flags |= pkgCache::Flag::Important;
-
+ {
+ if ((essential == "native" && Pkg->Arch != 0 && myArch == Pkg.Arch()) ||
+ essential == "all")
+ Pkg->Flags |= pkgCache::Flag::Essential | pkgCache::Flag::Important;
+ else
+ Pkg->Flags |= pkgCache::Flag::Important;
+ }
+
if (ParseStatus(Pkg,Ver) == false)
return false;
return true;
diff --git a/apt-pkg/deb/debmetaindex.cc b/apt-pkg/deb/debmetaindex.cc
index 5d3a80aa5..bcc617da7 100644
--- a/apt-pkg/deb/debmetaindex.cc
+++ b/apt-pkg/deb/debmetaindex.cc
@@ -128,7 +128,7 @@ string debReleaseIndex::TranslationIndexURISuffix(const char *Type, const string
{
string Res ="";
if (Dist[Dist.size() - 1] != '/')
- Res += Section + "/i18n/";
+ Res += Section + "/i18n/Translation-";
return Res + Type;
}
@@ -210,31 +210,17 @@ vector <struct IndexTarget *>* debReleaseIndex::ComputeIndexTargets() const {
if (lang.empty() == true)
return IndexTargets;
- // get the Translations:
- // - if its a dists-style repository get the i18n/Index first
- // - if its flat try to acquire files by guessing
- if (Dist[Dist.size() - 1] == '/') {
- for (std::set<std::string>::const_iterator s = sections.begin();
- s != sections.end(); ++s) {
- for (std::vector<std::string>::const_iterator l = lang.begin();
- l != lang.end(); ++l) {
- IndexTarget * Target = new OptionalIndexTarget();
- Target->ShortDesc = "Translation-" + *l;
- Target->MetaKey = TranslationIndexURISuffix(l->c_str(), *s);
- Target->URI = TranslationIndexURI(l->c_str(), *s);
- Target->Description = Info (Target->ShortDesc.c_str(), *s);
- IndexTargets->push_back(Target);
- }
- }
- } else {
- for (std::set<std::string>::const_iterator s = sections.begin();
- s != sections.end(); ++s) {
- IndexTarget * Target = new OptionalSubIndexTarget();
- Target->ShortDesc = "TranslationIndex";
- Target->MetaKey = TranslationIndexURISuffix("Index", *s);
- Target->URI = TranslationIndexURI("Index", *s);
+ // get the Translation-* files, later we will skip download of non-existent if we have an index
+ for (std::set<std::string>::const_iterator s = sections.begin();
+ s != sections.end(); ++s) {
+ for (std::vector<std::string>::const_iterator l = lang.begin();
+ l != lang.end(); ++l) {
+ IndexTarget * Target = new OptionalIndexTarget();
+ Target->ShortDesc = "Translation-" + *l;
+ Target->MetaKey = TranslationIndexURISuffix(l->c_str(), *s);
+ Target->URI = TranslationIndexURI(l->c_str(), *s);
Target->Description = Info (Target->ShortDesc.c_str(), *s);
- IndexTargets->push_back (Target);
+ IndexTargets->push_back(Target);
}
}
diff --git a/apt-pkg/deb/dpkgpm.cc b/apt-pkg/deb/dpkgpm.cc
index 653e14190..7e937a85b 100644
--- a/apt-pkg/deb/dpkgpm.cc
+++ b/apt-pkg/deb/dpkgpm.cc
@@ -424,7 +424,7 @@ void pkgDPkgPM::DoStdin(int master)
unsigned char input_buf[256] = {0,};
ssize_t len = read(0, input_buf, sizeof(input_buf));
if (len)
- write(master, input_buf, len);
+ FileFd::Write(master, input_buf, len);
else
d->stdin_is_dev_null = true;
}
@@ -450,7 +450,7 @@ void pkgDPkgPM::DoTerminalPty(int master)
}
if(len <= 0)
return;
- write(1, term_buf, len);
+ FileFd::Write(1, term_buf, len);
if(d->term_out)
fwrite(term_buf, len, sizeof(char), d->term_out);
}
@@ -525,7 +525,7 @@ void pkgDPkgPM::ProcessDpkgStatusLine(int OutStatusFd, char *line)
<< ":" << s
<< endl;
if(OutStatusFd > 0)
- write(OutStatusFd, status.str().c_str(), status.str().size());
+ FileFd::Write(OutStatusFd, status.str().c_str(), status.str().size());
if (Debug == true)
std::clog << "send: '" << status.str() << "'" << endl;
@@ -549,7 +549,7 @@ void pkgDPkgPM::ProcessDpkgStatusLine(int OutStatusFd, char *line)
<< ":" << list[3]
<< endl;
if(OutStatusFd > 0)
- write(OutStatusFd, status.str().c_str(), status.str().size());
+ FileFd::Write(OutStatusFd, status.str().c_str(), status.str().size());
if (Debug == true)
std::clog << "send: '" << status.str() << "'" << endl;
pkgFailures++;
@@ -563,7 +563,7 @@ void pkgDPkgPM::ProcessDpkgStatusLine(int OutStatusFd, char *line)
<< ":" << list[3]
<< endl;
if(OutStatusFd > 0)
- write(OutStatusFd, status.str().c_str(), status.str().size());
+ FileFd::Write(OutStatusFd, status.str().c_str(), status.str().size());
if (Debug == true)
std::clog << "send: '" << status.str() << "'" << endl;
return;
@@ -591,7 +591,7 @@ void pkgDPkgPM::ProcessDpkgStatusLine(int OutStatusFd, char *line)
<< ":" << s
<< endl;
if(OutStatusFd > 0)
- write(OutStatusFd, status.str().c_str(), status.str().size());
+ FileFd::Write(OutStatusFd, status.str().c_str(), status.str().size());
if (Debug == true)
std::clog << "send: '" << status.str() << "'" << endl;
}
@@ -862,6 +862,8 @@ static int racy_pselect(int nfds, fd_set *readfds, fd_set *writefds,
*/
bool pkgDPkgPM::Go(int OutStatusFd)
{
+ pkgPackageManager::SigINTStop = false;
+
// Generate the base argument list for dpkg
std::vector<const char *> Args;
unsigned long StartSize = 0;
@@ -907,7 +909,7 @@ bool pkgDPkgPM::Go(int OutStatusFd)
dup2(nullfd, STDIN_FILENO);
dup2(nullfd, STDOUT_FILENO);
dup2(nullfd, STDERR_FILENO);
- execv(Args[0], (char**) &Args[0]);
+ execvp(Args[0], (char**) &Args[0]);
_error->WarningE("dpkgGo", "Can't detect if dpkg supports multi-arch!");
_exit(2);
}
@@ -1053,7 +1055,8 @@ bool pkgDPkgPM::Go(int OutStatusFd)
}
int fd[2];
- pipe(fd);
+ if (pipe(fd) != 0)
+ return _error->Errno("pipe","Failed to create IPC pipe to dpkg");
#define ADDARG(X) Args.push_back(X); Size += strlen(X)
#define ADDARGC(X) Args.push_back(X); Size += sizeof(X) - 1
@@ -1234,7 +1237,7 @@ bool pkgDPkgPM::Go(int OutStatusFd)
<< (PackagesDone/float(PackagesTotal)*100.0)
<< ":" << _("Running dpkg")
<< endl;
- write(OutStatusFd, status.str().c_str(), status.str().size());
+ FileFd::Write(OutStatusFd, status.str().c_str(), status.str().size());
}
Child = ExecFork();
@@ -1431,9 +1434,8 @@ bool pkgDPkgPM::Go(int OutStatusFd)
}
void SigINT(int sig) {
- if (_config->FindB("APT::Immediate-Configure-All",false))
- pkgPackageManager::SigINTStop = true;
-}
+ pkgPackageManager::SigINTStop = true;
+}
/*}}}*/
// pkgDpkgPM::Reset - Dump the contents of the command list /*{{{*/
// ---------------------------------------------------------------------
@@ -1448,6 +1450,12 @@ void pkgDPkgPM::Reset()
/* */
void pkgDPkgPM::WriteApportReport(const char *pkgpath, const char *errormsg)
{
+ // If apport doesn't exist or isn't installed do nothing
+ // This e.g. prevents messages in 'universes' without apport
+ pkgCache::PkgIterator apportPkg = Cache.FindPkg("apport");
+ if (apportPkg.end() == true || apportPkg->CurrentVer == 0)
+ return;
+
string pkgname, reportfile, srcpkgname, pkgver, arch;
string::size_type pos;
FILE *report;
@@ -1566,7 +1574,7 @@ void pkgDPkgPM::WriteApportReport(const char *pkgpath, const char *errormsg)
if(strstr(strbuf,"Package:") == strbuf)
{
char pkgname[255], version[255];
- if(sscanf(strbuf, "Package: %s %s", pkgname, version) == 2)
+ if(sscanf(strbuf, "Package: %254s %254s", pkgname, version) == 2)
if(strcmp(pkgver.c_str(), version) == 0)
{
fclose(report);
@@ -1637,7 +1645,10 @@ void pkgDPkgPM::WriteApportReport(const char *pkgpath, const char *errormsg)
const char *ops_str[] = {"Install", "Configure","Remove","Purge"};
fprintf(report, "AptOrdering:\n");
for (vector<Item>::iterator I = List.begin(); I != List.end(); ++I)
- fprintf(report, " %s: %s\n", (*I).Pkg.Name(), ops_str[(*I).Op]);
+ if ((*I).Pkg != NULL)
+ fprintf(report, " %s: %s\n", (*I).Pkg.Name(), ops_str[(*I).Op]);
+ else
+ fprintf(report, " %s: %s\n", "NULL", ops_str[(*I).Op]);
// attach dmesg log (to learn about segfaults)
if (FileExists("/bin/dmesg"))
diff --git a/apt-pkg/depcache.cc b/apt-pkg/depcache.cc
index fdfd1c713..56194e244 100644
--- a/apt-pkg/depcache.cc
+++ b/apt-pkg/depcache.cc
@@ -964,6 +964,13 @@ struct CompareProviders {
else if ((B->Flags & pkgCache::Flag::Essential) == pkgCache::Flag::Essential)
return true;
}
+ if ((A->Flags & pkgCache::Flag::Important) != (B->Flags & pkgCache::Flag::Important))
+ {
+ if ((A->Flags & pkgCache::Flag::Important) == pkgCache::Flag::Important)
+ return false;
+ else if ((B->Flags & pkgCache::Flag::Important) == pkgCache::Flag::Important)
+ return true;
+ }
// higher priority seems like a good idea
if (AV->Priority != BV->Priority)
return AV->Priority < BV->Priority;
@@ -1146,9 +1153,8 @@ bool pkgDepCache::MarkInstall(PkgIterator const &Pkg,bool AutoInst,
}
/* This bit is for processing the possibilty of an install/upgrade
- fixing the problem */
- if (Start->Type != Dep::DpkgBreaks &&
- (DepState[Start->ID] & DepCVer) == DepCVer)
+ fixing the problem for "positive" dependencies */
+ if (Start.IsNegative() == false && (DepState[Start->ID] & DepCVer) == DepCVer)
{
APT::VersionList verlist;
pkgCache::VerIterator Cand = PkgState[Start.TargetPkg()->ID].CandidateVerIter(*this);
@@ -1159,7 +1165,7 @@ bool pkgDepCache::MarkInstall(PkgIterator const &Pkg,bool AutoInst,
pkgCache::VerIterator V = Prv.OwnerVer();
pkgCache::VerIterator Cand = PkgState[Prv.OwnerPkg()->ID].CandidateVerIter(*this);
if (Cand.end() == true || V != Cand ||
- VS().CheckDep(Cand.VerStr(), Start->CompareOp, Start.TargetVer()) == false)
+ VS().CheckDep(Prv.ProvideVersion(), Start->CompareOp, Start.TargetVer()) == false)
continue;
verlist.insert(Cand);
}
@@ -1192,13 +1198,13 @@ bool pkgDepCache::MarkInstall(PkgIterator const &Pkg,bool AutoInst,
}
continue;
}
-
- /* For conflicts we just de-install the package and mark as auto,
- Conflicts may not have or groups. For dpkg's Breaks we try to
- upgrade the package. */
- if (Start.IsNegative() == true)
+ /* Negative dependencies have no or-group
+ If the dependency isn't versioned, we try if an upgrade might solve the problem.
+ Otherwise we remove the offender if needed */
+ else if (Start.IsNegative() == true && Start->Type != pkgCache::Dep::Obsoletes)
{
SPtrArray<Version *> List = Start.AllTargets();
+ pkgCache::PkgIterator TrgPkg = Start.TargetPkg();
for (Version **I = List; *I != 0; I++)
{
VerIterator Ver(*this,*I);
@@ -1209,15 +1215,17 @@ bool pkgDepCache::MarkInstall(PkgIterator const &Pkg,bool AutoInst,
if (PkgState[Pkg->ID].InstallVer == 0)
continue;
- if (PkgState[Pkg->ID].CandidateVer != *I &&
- Start->Type == Dep::DpkgBreaks &&
+ if ((Start->Version != 0 || TrgPkg != Pkg) &&
+ PkgState[Pkg->ID].CandidateVer != PkgState[Pkg->ID].InstallVer &&
+ PkgState[Pkg->ID].CandidateVer != *I &&
MarkInstall(Pkg,true,Depth + 1, false, ForceImportantDeps) == true)
continue;
- else if (MarkDelete(Pkg,false,Depth + 1, false) == false)
+ else if ((Start->Type == pkgCache::Dep::Conflicts || Start->Type == pkgCache::Dep::DpkgBreaks) &&
+ MarkDelete(Pkg,false,Depth + 1, false) == false)
break;
}
continue;
- }
+ }
}
return Dep.end() == true;
@@ -1642,6 +1650,7 @@ bool pkgDepCache::MarkRequired(InRootSetFunc &userFunc)
{
if(!(PkgState[p->ID].Flags & Flag::Auto) ||
(p->Flags & Flag::Essential) ||
+ (p->Flags & Flag::Important) ||
userFunc.InRootSet(p) ||
// be nice even then a required package violates the policy (#583517)
// and do the full mark process also for required packages
diff --git a/apt-pkg/edsp/edspsystem.cc b/apt-pkg/edsp/edspsystem.cc
index 6b9207451..aae969d9d 100644
--- a/apt-pkg/edsp/edspsystem.cc
+++ b/apt-pkg/edsp/edspsystem.cc
@@ -91,7 +91,7 @@ signed edspSystem::Score(Configuration const &Cnf)
{
if (Cnf.Find("edsp::scenario", "") == "stdin")
return 1000;
- if (FileExists(Cnf.FindFile("edsp::scenario","")) == true)
+ if (RealFileExists(Cnf.FindFile("edsp::scenario","")) == true)
return 1000;
return -1000;
}
diff --git a/apt-pkg/indexrecords.cc b/apt-pkg/indexrecords.cc
index cdb9250e8..af2639beb 100644
--- a/apt-pkg/indexrecords.cc
+++ b/apt-pkg/indexrecords.cc
@@ -44,7 +44,10 @@ time_t indexRecords::GetValidUntil() const
const indexRecords::checkSum *indexRecords::Lookup(const string MetaKey)
{
- return Entries[MetaKey];
+ std::map<std::string, indexRecords::checkSum* >::const_iterator sum = Entries.find(MetaKey);
+ if (sum == Entries.end())
+ return NULL;
+ return sum->second;
}
bool indexRecords::Exists(string const &MetaKey) const
diff --git a/apt-pkg/init.cc b/apt-pkg/init.cc
index 4c15858a1..4818174ac 100644
--- a/apt-pkg/init.cc
+++ b/apt-pkg/init.cc
@@ -24,7 +24,7 @@
#define Stringfy_(x) # x
#define Stringfy(x) Stringfy_(x)
-const char *pkgVersion = VERSION;
+const char *pkgVersion = PACKAGE_VERSION;
const char *pkgLibVersion = Stringfy(APT_PKG_MAJOR) "."
Stringfy(APT_PKG_MINOR) "."
Stringfy(APT_PKG_RELEASE);
diff --git a/apt-pkg/makefile b/apt-pkg/makefile
index e1f69dd65..27d7ead24 100644
--- a/apt-pkg/makefile
+++ b/apt-pkg/makefile
@@ -14,7 +14,13 @@ include ../buildlib/libversion.mak
LIBRARY=apt-pkg
MAJOR=$(LIBAPTPKG_MAJOR)
MINOR=$(LIBAPTPKG_RELEASE)
-SLIBS=$(PTHREADLIB) $(INTLLIBS) -lutil -ldl -lz
+SLIBS=$(PTHREADLIB) $(INTLLIBS) -lutil -ldl
+ifeq ($(HAVE_ZLIB),yes)
+SLIBS+= -lz
+endif
+ifeq ($(HAVE_BZ2),yes)
+SLIBS+= -lbz2
+endif
APT_DOMAIN:=libapt-pkg$(LIBAPTPKG_MAJOR)
# Source code for the contributed non-core things
diff --git a/apt-pkg/packagemanager.cc b/apt-pkg/packagemanager.cc
index cefb760af..80369dd1a 100644
--- a/apt-pkg/packagemanager.cc
+++ b/apt-pkg/packagemanager.cc
@@ -25,9 +25,10 @@
#include <apt-pkg/configuration.h>
#include <apt-pkg/sptr.h>
-#include <apti18n.h>
#include <iostream>
#include <fcntl.h>
+
+#include <apti18n.h>
/*}}}*/
using namespace std;
@@ -183,8 +184,7 @@ bool pkgPackageManager::CreateOrderList()
continue;
// Mark the package and its dependends for immediate configuration
- if ((((I->Flags & pkgCache::Flag::Essential) == pkgCache::Flag::Essential ||
- (I->Flags & pkgCache::Flag::Important) == pkgCache::Flag::Important) &&
+ if ((((I->Flags & pkgCache::Flag::Essential) == pkgCache::Flag::Essential) &&
NoImmConfigure == false) || ImmConfigureAll)
{
if(Debug && !ImmConfigureAll)
@@ -523,7 +523,8 @@ bool pkgPackageManager::EarlyRemove(PkgIterator Pkg)
// Essential packages get special treatment
bool IsEssential = false;
- if ((Pkg->Flags & pkgCache::Flag::Essential) != 0)
+ if ((Pkg->Flags & pkgCache::Flag::Essential) != 0 ||
+ (Pkg->Flags & pkgCache::Flag::Important) != 0)
IsEssential = true;
/* Check for packages that are the dependents of essential packages and
@@ -533,7 +534,8 @@ bool pkgPackageManager::EarlyRemove(PkgIterator Pkg)
for (DepIterator D = Pkg.RevDependsList(); D.end() == false &&
IsEssential == false; ++D)
if (D->Type == pkgCache::Dep::Depends || D->Type == pkgCache::Dep::PreDepends)
- if ((D.ParentPkg()->Flags & pkgCache::Flag::Essential) != 0)
+ if ((D.ParentPkg()->Flags & pkgCache::Flag::Essential) != 0 ||
+ (D.ParentPkg()->Flags & pkgCache::Flag::Important) != 0)
IsEssential = true;
}
@@ -601,7 +603,7 @@ bool pkgPackageManager::SmartUnPack(PkgIterator Pkg, bool const Immediate, int c
or by the ConfigureAll call at the end of the for loop in OrderInstall. */
bool Changed = false;
const unsigned int max_loops = _config->FindI("APT::pkgPackageManager::MaxLoopCount", 5000);
- unsigned int i=0;
+ unsigned int i = 0;
do
{
Changed = false;
@@ -783,7 +785,7 @@ bool pkgPackageManager::SmartUnPack(PkgIterator Pkg, bool const Immediate, int c
VerIterator V(Cache,*I);
PkgIterator P = V.ParentPkg();
// we are checking for installation as an easy 'protection' against or-groups and (unchosen) providers
- if (P->CurrentVer == 0 || P != Pkg || (P.CurrentVer() != V && Cache[P].InstallVer != V))
+ if (P != Pkg || (P.CurrentVer() != V && Cache[P].InstallVer != V))
continue;
circle = true;
break;
diff --git a/apt-pkg/pkgcachegen.cc b/apt-pkg/pkgcachegen.cc
index ec072fddd..538d10b35 100644
--- a/apt-pkg/pkgcachegen.cc
+++ b/apt-pkg/pkgcachegen.cc
@@ -38,7 +38,7 @@
typedef std::vector<pkgIndexFile *>::iterator FileIterator;
template <typename Iter> std::vector<Iter*> pkgCacheGenerator::Dynamic<Iter>::toReMap;
-bool IsDuplicateDescription(pkgCache::DescIterator Desc,
+static bool IsDuplicateDescription(pkgCache::DescIterator Desc,
MD5SumValue const &CurMd5, std::string const &CurLang);
using std::string;
@@ -286,7 +286,7 @@ bool pkgCacheGenerator::MergeListPackage(ListParser &List, pkgCache::PkgIterator
pkgCache::DescIterator Desc = Ver.DescriptionList();
// a version can only have one md5 describing it
- if (MD5SumValue(Desc.md5()) != CurMd5)
+ if (Desc.end() == true || MD5SumValue(Desc.md5()) != CurMd5)
continue;
// don't add a new description if we have one for the given
@@ -304,6 +304,9 @@ bool pkgCacheGenerator::MergeListPackage(ListParser &List, pkgCache::PkgIterator
void const * const oldMap = Map.Data();
map_ptrloc const descindex = NewDescription(Desc, CurLang, CurMd5, *LastDesc);
+ if (unlikely(descindex == 0 && _error->PendingError()))
+ return _error->Error(_("Error occurred while processing %s (%s%d)"),
+ Pkg.Name(), "NewDescription", 1);
if (oldMap != Map.Data())
LastDesc += (map_ptrloc*) Map.Data() - (map_ptrloc*) oldMap;
*LastDesc = descindex;
@@ -456,6 +459,9 @@ bool pkgCacheGenerator::MergeListVersion(ListParser &List, pkgCache::PkgIterator
oldMap = Map.Data();
map_ptrloc const descindex = NewDescription(Desc, CurLang, CurMd5, *LastDesc);
+ if (unlikely(descindex == 0 && _error->PendingError()))
+ return _error->Error(_("Error occurred while processing %s (%s%d)"),
+ Pkg.Name(), "NewDescription", 2);
if (oldMap != Map.Data())
LastDesc += (map_ptrloc*) Map.Data() - (map_ptrloc*) oldMap;
*LastDesc = descindex;
@@ -1449,11 +1455,11 @@ bool pkgCacheGenerator::MakeOnlyStatusCache(OpProgress *Progress,DynamicMMap **O
}
/*}}}*/
// IsDuplicateDescription /*{{{*/
-bool IsDuplicateDescription(pkgCache::DescIterator Desc,
+static bool IsDuplicateDescription(pkgCache::DescIterator Desc,
MD5SumValue const &CurMd5, std::string const &CurLang)
{
// Descriptions in the same link-list have all the same md5
- if (MD5SumValue(Desc.md5()) != CurMd5)
+ if (Desc.end() == true || MD5SumValue(Desc.md5()) != CurMd5)
return false;
for (; Desc.end() == false; ++Desc)
if (Desc.LanguageCode() == CurLang)
diff --git a/apt-pkg/srcrecords.h b/apt-pkg/srcrecords.h
index 06f0dce6c..ed69d0d72 100644
--- a/apt-pkg/srcrecords.h
+++ b/apt-pkg/srcrecords.h
@@ -71,6 +71,7 @@ class pkgSrcRecords
virtual std::string Section() const = 0;
virtual const char **Binaries() = 0; // Ownership does not transfer
+ //FIXME: Add a parameter to specify which architecture to use for [wildcard] matching
virtual bool BuildDepends(std::vector<BuildDepRec> &BuildDeps, bool const &ArchOnly, bool const &StripMultiArch = true) = 0;
static const char *BuildDepType(unsigned char const &Type);