summaryrefslogtreecommitdiff
path: root/apt-pkg
diff options
context:
space:
mode:
Diffstat (limited to 'apt-pkg')
-rw-r--r--apt-pkg/acquire-item.cc129
-rw-r--r--apt-pkg/acquire-item.h1
-rw-r--r--apt-pkg/acquire-method.cc245
-rw-r--r--apt-pkg/acquire-method.h3
-rw-r--r--apt-pkg/acquire-worker.cc22
-rw-r--r--apt-pkg/acquire-worker.h5
-rw-r--r--apt-pkg/acquire.h27
-rw-r--r--apt-pkg/algorithms.cc133
-rw-r--r--apt-pkg/algorithms.h8
-rw-r--r--apt-pkg/aptconfiguration.cc122
-rw-r--r--apt-pkg/aptconfiguration.h29
-rw-r--r--apt-pkg/cachefile.h3
-rw-r--r--apt-pkg/cachefilter.h2
-rw-r--r--apt-pkg/cacheiterators.h9
-rw-r--r--apt-pkg/cacheset.h28
-rw-r--r--apt-pkg/cdrom.cc126
-rw-r--r--apt-pkg/cdrom.h10
-rw-r--r--apt-pkg/clean.h3
-rw-r--r--apt-pkg/contrib/cdromutl.cc41
-rw-r--r--apt-pkg/contrib/cdromutl.h1
-rw-r--r--apt-pkg/contrib/configuration.h2
-rw-r--r--apt-pkg/contrib/error.cc166
-rw-r--r--apt-pkg/contrib/error.h5
-rw-r--r--apt-pkg/contrib/fileutl.cc23
-rw-r--r--apt-pkg/contrib/mmap.cc12
-rw-r--r--apt-pkg/contrib/mmap.h2
-rw-r--r--apt-pkg/contrib/netrc.cc12
-rw-r--r--apt-pkg/contrib/progress.cc27
-rw-r--r--apt-pkg/contrib/progress.h3
-rw-r--r--apt-pkg/contrib/strutl.cc8
-rw-r--r--apt-pkg/deb/debindexfile.cc20
-rw-r--r--apt-pkg/deb/debindexfile.h20
-rw-r--r--apt-pkg/deb/deblistparser.cc126
-rw-r--r--apt-pkg/deb/deblistparser.h13
-rw-r--r--apt-pkg/deb/debmetaindex.cc5
-rw-r--r--apt-pkg/deb/debmetaindex.h4
-rw-r--r--apt-pkg/deb/debrecords.h4
-rw-r--r--apt-pkg/deb/debsrcrecords.cc8
-rw-r--r--apt-pkg/deb/debsrcrecords.h5
-rw-r--r--apt-pkg/deb/debsystem.cc62
-rw-r--r--apt-pkg/deb/debsystem.h13
-rw-r--r--apt-pkg/deb/dpkgpm.cc225
-rw-r--r--apt-pkg/deb/dpkgpm.h11
-rw-r--r--apt-pkg/depcache.cc707
-rw-r--r--apt-pkg/depcache.h31
-rw-r--r--apt-pkg/edsp.cc564
-rw-r--r--apt-pkg/edsp.h222
-rw-r--r--apt-pkg/edsp/edspindexfile.cc78
-rw-r--r--apt-pkg/edsp/edspindexfile.h28
-rw-r--r--apt-pkg/edsp/edsplistparser.cc90
-rw-r--r--apt-pkg/edsp/edsplistparser.h38
-rw-r--r--apt-pkg/edsp/edspsystem.cc124
-rw-r--r--apt-pkg/edsp/edspsystem.h41
-rw-r--r--apt-pkg/indexcopy.cc10
-rw-r--r--apt-pkg/indexcopy.h8
-rw-r--r--apt-pkg/init.cc5
-rw-r--r--apt-pkg/init.h4
-rw-r--r--apt-pkg/makefile10
-rw-r--r--apt-pkg/orderlist.cc28
-rw-r--r--apt-pkg/packagemanager.cc77
-rw-r--r--apt-pkg/packagemanager.h2
-rw-r--r--apt-pkg/pkgcache.cc75
-rw-r--r--apt-pkg/pkgcache.h23
-rw-r--r--apt-pkg/pkgcachegen.cc42
-rw-r--r--apt-pkg/pkgrecords.h5
-rw-r--r--apt-pkg/policy.cc83
-rw-r--r--apt-pkg/policy.h8
-rw-r--r--apt-pkg/srcrecords.h4
-rw-r--r--apt-pkg/tagfile.cc123
-rw-r--r--apt-pkg/tagfile.h21
-rw-r--r--apt-pkg/vendor.h3
-rw-r--r--apt-pkg/vendorlist.cc11
-rw-r--r--apt-pkg/vendorlist.h3
73 files changed, 2766 insertions, 1425 deletions
diff --git a/apt-pkg/acquire-item.cc b/apt-pkg/acquire-item.cc
index 05e2f28a4..d790bd898 100644
--- a/apt-pkg/acquire-item.cc
+++ b/apt-pkg/acquire-item.cc
@@ -17,7 +17,6 @@
#include <apt-pkg/configuration.h>
#include <apt-pkg/aptconfiguration.h>
#include <apt-pkg/sourcelist.h>
-#include <apt-pkg/vendorlist.h>
#include <apt-pkg/error.h>
#include <apt-pkg/strutl.h>
#include <apt-pkg/fileutl.h>
@@ -220,8 +219,8 @@ string pkgAcqSubIndex::Custom600Headers()
struct stat Buf;
if (stat(Final.c_str(),&Buf) != 0)
- return "\nIndex-File: true";
- return "\nIndex-File: true\nLast-Modified: " + TimeRFC1123(Buf.st_mtime);
+ return "\nIndex-File: true\nFail-Ignore: true\n";
+ return "\nIndex-File: true\nFail-Ignore: true\nLast-Modified: " + TimeRFC1123(Buf.st_mtime);
}
/*}}}*/
void pkgAcqSubIndex::Failed(string Message,pkgAcquire::MethodConfig *Cnf) /*{{{*/
@@ -272,6 +271,14 @@ void pkgAcqSubIndex::Done(string Message,unsigned long Size,string Md5Hash, /*{{
string FinalFile = _config->FindDir("Dir::State::lists")+URItoFileName(Desc.URI);
+ /* Downloaded invalid transindex => Error (LP: #346386) (Closes: #627642) */
+ indexRecords SubIndexParser;
+ if (FileExists(DestFile) == true && !SubIndexParser.Load(DestFile)) {
+ Status = StatError;
+ ErrorText = SubIndexParser.ErrorText;
+ return;
+ }
+
// sucess in downloading the index
// rename the index
if(Debug)
@@ -835,10 +842,16 @@ string pkgAcqIndex::Custom600Headers()
if (_config->FindB("Acquire::GzipIndexes",false))
Final += ".gz";
+ string msg = "\nIndex-File: true";
+ // FIXME: this really should use "IndexTarget::IsOptional()" but that
+ // seems to be difficult without breaking ABI
+ if (ShortDesc().find("Translation") != 0)
+ msg += "\nFail-Ignore: true";
struct stat Buf;
- if (stat(Final.c_str(),&Buf) != 0)
- return "\nIndex-File: true";
- return "\nIndex-File: true\nLast-Modified: " + TimeRFC1123(Buf.st_mtime);
+ if (stat(Final.c_str(),&Buf) == 0)
+ msg += "\nLast-Modified: " + TimeRFC1123(Buf.st_mtime);
+
+ return msg;
}
/*}}}*/
void pkgAcqIndex::Failed(string Message,pkgAcquire::MethodConfig *Cnf) /*{{{*/
@@ -889,6 +902,30 @@ void pkgAcqIndex::Done(string Message,unsigned long Size,string Hash,
ReportMirrorFailure("HashChecksumFailure");
return;
}
+
+ /* Verify the index file for correctness (all indexes must
+ * have a Package field) (LP: #346386) (Closes: #627642) */
+ {
+ FileFd fd(DestFile, FileFd::ReadOnly);
+ pkgTagSection sec;
+ pkgTagFile tag(&fd);
+
+ // Only test for correctness if the file is not empty (empty is ok)
+ if (fd.Size() > 0) {
+ if (_error->PendingError() || !tag.Step(sec)) {
+ Status = StatError;
+ _error->DumpErrors();
+ Rename(DestFile,DestFile + ".FAILED");
+ return;
+ } else if (!sec.Exists("Package")) {
+ Status = StatError;
+ ErrorText = ("Encountered a section with no Package: header");
+ Rename(DestFile,DestFile + ".FAILED");
+ return;
+ }
+ }
+ }
+
// Done, move it into position
string FinalFile = _config->FindDir("Dir::State::lists");
FinalFile += URItoFileName(RealURI);
@@ -1002,8 +1039,8 @@ string pkgAcqIndexTrans::Custom600Headers()
struct stat Buf;
if (stat(Final.c_str(),&Buf) != 0)
- return "\nFail-Ignore: true";
- return "\nFail-Ignore: true\nLast-Modified: " + TimeRFC1123(Buf.st_mtime);
+ return "\nFail-Ignore: true\nIndex-File: true";
+ return "\nFail-Ignore: true\nIndex-File: true\nLast-Modified: " + TimeRFC1123(Buf.st_mtime);
}
/*}}}*/
// AcqIndexTrans::Failed - Silence failure messages for missing files /*{{{*/
@@ -1325,6 +1362,16 @@ void pkgAcqMetaIndex::AuthDone(string Message) /*{{{*/
/*}}}*/
void pkgAcqMetaIndex::QueueIndexes(bool verify) /*{{{*/
{
+#if 0
+ /* Reject invalid, existing Release files (LP: #346386) (Closes: #627642)
+ * FIXME: Disabled; it breaks unsigned repositories without hashes */
+ if (!verify && FileExists(DestFile) && !MetaIndexParser->Load(DestFile))
+ {
+ Status = StatError;
+ ErrorText = MetaIndexParser->ErrorText;
+ return;
+ }
+#endif
for (vector <struct IndexTarget*>::const_iterator Target = IndexTargets->begin();
Target != IndexTargets->end();
Target++)
@@ -1384,29 +1431,6 @@ void pkgAcqMetaIndex::QueueIndexes(bool verify) /*{{{*/
/*}}}*/
bool pkgAcqMetaIndex::VerifyVendor(string Message) /*{{{*/
{
-// // Maybe this should be made available from above so we don't have
-// // to read and parse it every time?
-// pkgVendorList List;
-// List.ReadMainList();
-
-// const Vendor* Vndr = NULL;
-// for (std::vector<string>::const_iterator I = GPGVOutput.begin(); I != GPGVOutput.end(); I++)
-// {
-// string::size_type pos = (*I).find("VALIDSIG ");
-// if (_config->FindB("Debug::Vendor", false))
-// std::cerr << "Looking for VALIDSIG in \"" << (*I) << "\": pos " << pos
-// << std::endl;
-// if (pos != std::string::npos)
-// {
-// string Fingerprint = (*I).substr(pos+sizeof("VALIDSIG"));
-// if (_config->FindB("Debug::Vendor", false))
-// std::cerr << "Looking for \"" << Fingerprint << "\" in vendor..." <<
-// std::endl;
-// Vndr = List.FindVendor(Fingerprint) != "";
-// if (Vndr != NULL);
-// break;
-// }
-// }
string::size_type pos;
// check for missing sigs (that where not fatal because otherwise we had
@@ -1511,6 +1535,12 @@ void pkgAcqMetaIndex::Failed(string Message,pkgAcquire::MethodConfig *Cnf)
LookupTag(Message,"Message").c_str());
RunScripts("APT::Update::Auth-Failure");
return;
+ } else if (LookupTag(Message,"Message").find("NODATA") != string::npos) {
+ /* Invalid signature file, reject (LP: #346386) (Closes: #627642) */
+ _error->Error(_("GPG error: %s: %s"),
+ Desc.Description.c_str(),
+ LookupTag(Message,"Message").c_str());
+ return;
} else {
_error->Warning(_("GPG error: %s: %s"),
Desc.Description.c_str(),
@@ -1520,6 +1550,26 @@ void pkgAcqMetaIndex::Failed(string Message,pkgAcquire::MethodConfig *Cnf)
ReportMirrorFailure("GPGFailure");
}
+ /* Always move the meta index, even if gpgv failed. This ensures
+ * that PackageFile objects are correctly filled in */
+ if (FileExists(DestFile)) {
+ string FinalFile = _config->FindDir("Dir::State::lists");
+ FinalFile += URItoFileName(RealURI);
+ /* InRelease files become Release files, otherwise
+ * they would be considered as trusted later on */
+ if (SigFile == DestFile) {
+ RealURI = RealURI.replace(RealURI.rfind("InRelease"), 9,
+ "Release");
+ FinalFile = FinalFile.replace(FinalFile.rfind("InRelease"), 9,
+ "Release");
+ SigFile = FinalFile;
+ }
+ Rename(DestFile,FinalFile);
+ chmod(FinalFile.c_str(),0644);
+
+ DestFile = FinalFile;
+ }
+
// No Release file was present, or verification failed, so fall
// back to queueing Packages files without verification
QueueIndexes(false);
@@ -1538,6 +1588,21 @@ pkgAcqMetaClearSig::pkgAcqMetaClearSig(pkgAcquire *Owner, /*{{{*/
SigFile = DestFile;
}
/*}}}*/
+// pkgAcqMetaClearSig::Custom600Headers - Insert custom request headers /*{{{*/
+// ---------------------------------------------------------------------
+// FIXME: this can go away once the InRelease file is used widely
+string pkgAcqMetaClearSig::Custom600Headers()
+{
+ string Final = _config->FindDir("Dir::State::lists");
+ Final += URItoFileName(RealURI);
+
+ struct stat Buf;
+ if (stat(Final.c_str(),&Buf) != 0)
+ return "\nIndex-File: true\nFail-Ignore: true\n";
+
+ return "\nIndex-File: true\nFail-Ignore: true\nLast-Modified: " + TimeRFC1123(Buf.st_mtime);
+}
+ /*}}}*/
void pkgAcqMetaClearSig::Failed(string Message,pkgAcquire::MethodConfig *Cnf) /*{{{*/
{
if (AuthPass == false)
@@ -1628,7 +1693,7 @@ pkgAcqArchive::pkgAcqArchive(pkgAcquire *Owner,pkgSourceList *Sources,
// Select a source
if (QueueNext() == false && _error->PendingError() == false)
- _error->Error(_("I wasn't able to locate file for the %s package. "
+ _error->Error(_("I wasn't able to locate a file for the %s package. "
"This might mean you need to manually fix this package."),
Version.ParentPkg().Name());
}
diff --git a/apt-pkg/acquire-item.h b/apt-pkg/acquire-item.h
index 2ae7bf27c..f763577ee 100644
--- a/apt-pkg/acquire-item.h
+++ b/apt-pkg/acquire-item.h
@@ -854,6 +854,7 @@ class pkgAcqMetaClearSig : public pkgAcqMetaIndex
public:
void Failed(string Message,pkgAcquire::MethodConfig *Cnf);
+ virtual string Custom600Headers();
/** \brief Create a new pkgAcqMetaClearSig. */
pkgAcqMetaClearSig(pkgAcquire *Owner,
diff --git a/apt-pkg/acquire-method.cc b/apt-pkg/acquire-method.cc
index bf3beafa2..8c353beb2 100644
--- a/apt-pkg/acquire-method.cc
+++ b/apt-pkg/acquire-method.cc
@@ -23,9 +23,7 @@
#include <apt-pkg/hashes.h>
#include <iostream>
-#include <stdarg.h>
#include <stdio.h>
-#include <unistd.h>
#include <sys/signal.h>
/*}}}*/
@@ -36,32 +34,28 @@ using namespace std;
/* This constructs the initialization text */
pkgAcqMethod::pkgAcqMethod(const char *Ver,unsigned long Flags)
{
- char S[300] = "";
- char *End = S;
- strcat(End,"100 Capabilities\n");
- sprintf(End+strlen(End),"Version: %s\n",Ver);
+ std::cout << "100 Capabilities\n"
+ << "Version: " << Ver << "\n";
if ((Flags & SingleInstance) == SingleInstance)
- strcat(End,"Single-Instance: true\n");
-
+ std::cout << "Single-Instance: true\n";
+
if ((Flags & Pipeline) == Pipeline)
- strcat(End,"Pipeline: true\n");
-
+ std::cout << "Pipeline: true\n";
+
if ((Flags & SendConfig) == SendConfig)
- strcat(End,"Send-Config: true\n");
+ std::cout << "Send-Config: true\n";
if ((Flags & LocalOnly) == LocalOnly)
- strcat(End,"Local-Only: true\n");
+ std::cout <<"Local-Only: true\n";
if ((Flags & NeedsCleanup) == NeedsCleanup)
- strcat(End,"Needs-Cleanup: true\n");
+ std::cout << "Needs-Cleanup: true\n";
if ((Flags & Removable) == Removable)
- strcat(End,"Removable: true\n");
- strcat(End,"\n");
+ std::cout << "Removable: true\n";
- if (write(STDOUT_FILENO,S,strlen(S)) != (signed)strlen(S))
- exit(100);
+ std::cout << "\n" << std::flush;
SetNonBlock(STDIN_FILENO,true);
@@ -94,13 +88,11 @@ void pkgAcqMethod::Fail(string Err,bool Transient)
if (*I == '\n')
*I = ' ';
}
-
- char S[1024];
- char *End = S;
+
if (Queue != 0)
{
- End += snprintf(S,sizeof(S)-50,"400 URI Failure\nURI: %s\n"
- "Message: %s %s\n",Queue->Uri.c_str(), Err.c_str(), IP.c_str());
+ std::cout << "400 URI Failure\nURI: " << Queue->Uri << "\n"
+ << "Message: " << Err << " " << IP << "\n";
// Dequeue
FetchItem *Tmp = Queue;
Queue = Queue->Next;
@@ -109,22 +101,17 @@ void pkgAcqMethod::Fail(string Err,bool Transient)
QueueBack = Queue;
}
else
- {
- End += snprintf(S,sizeof(S)-50,"400 URI Failure\nURI: <UNKNOWN>\n"
- "Message: %s\n",Err.c_str());
- }
+ std::cout << "400 URI Failure\nURI: <UNKNOWN>\nMessage: " << Err << "\n";
+
if(FailReason.empty() == false)
- End += snprintf(End,sizeof(S)-50 - (End - S),"FailReason: %s\n",FailReason.c_str());
+ std::cout << "FailReason: " << FailReason << "\n";
if (UsedMirror.empty() == false)
- End += snprintf(End,sizeof(S)-50 - (End - S),"UsedMirror: %s\n",UsedMirror.c_str());
- // Set the transient flag
+ std::cout << "UsedMirror: " << UsedMirror << "\n";
+ // Set the transient flag
if (Transient == true)
- strcat(S,"Transient-Failure: true\n\n");
- else
- strcat(S,"\n");
-
- if (write(STDOUT_FILENO,S,strlen(S)) != (signed)strlen(S))
- exit(100);
+ std::cout << "Transient-Failure: true\n";
+
+ std::cout << "\n" << std::flush;
}
/*}}}*/
// AcqMethod::URIStart - Indicate a download is starting /*{{{*/
@@ -134,25 +121,22 @@ void pkgAcqMethod::URIStart(FetchResult &Res)
{
if (Queue == 0)
abort();
-
- char S[1024] = "";
- char *End = S;
-
- End += snprintf(S,sizeof(S),"200 URI Start\nURI: %s\n",Queue->Uri.c_str());
+
+ std::cout << "200 URI Start\n"
+ << "URI: " << Queue->Uri << "\n";
if (Res.Size != 0)
- End += snprintf(End,sizeof(S)-4 - (End - S),"Size: %lu\n",Res.Size);
-
+ std::cout << "Size: " << Res.Size << "\n";
+
if (Res.LastModified != 0)
- End += snprintf(End,sizeof(S)-4 - (End - S),"Last-Modified: %s\n",
- TimeRFC1123(Res.LastModified).c_str());
-
+ std::cout << "Last-Modified: " << TimeRFC1123(Res.LastModified) << "\n";
+
if (Res.ResumePoint != 0)
- End += snprintf(End,sizeof(S)-4 - (End - S),"Resume-Point: %lu\n",
- Res.ResumePoint);
-
- strcat(End,"\n");
- if (write(STDOUT_FILENO,S,strlen(S)) != (signed)strlen(S))
- exit(100);
+ std::cout << "Resume-Point: " << Res.ResumePoint << "\n";
+
+ if (UsedMirror.empty() == false)
+ std::cout << "UsedMirror: " << UsedMirror << "\n";
+
+ std::cout << "\n" << std::flush;
}
/*}}}*/
// AcqMethod::URIDone - A URI is finished /*{{{*/
@@ -162,81 +146,69 @@ void pkgAcqMethod::URIDone(FetchResult &Res, FetchResult *Alt)
{
if (Queue == 0)
abort();
-
- char S[1024] = "";
- char *End = S;
-
- End += snprintf(S,sizeof(S),"201 URI Done\nURI: %s\n",Queue->Uri.c_str());
+
+ std::cout << "201 URI Done\n"
+ << "URI: " << Queue->Uri << "\n";
if (Res.Filename.empty() == false)
- End += snprintf(End,sizeof(S)-50 - (End - S),"Filename: %s\n",Res.Filename.c_str());
-
+ std::cout << "Filename: " << Res.Filename << "\n";
+
if (Res.Size != 0)
- End += snprintf(End,sizeof(S)-50 - (End - S),"Size: %lu\n",Res.Size);
-
+ std::cout << "Size: " << Res.Size << "\n";
+
if (Res.LastModified != 0)
- End += snprintf(End,sizeof(S)-50 - (End - S),"Last-Modified: %s\n",
- TimeRFC1123(Res.LastModified).c_str());
+ std::cout << "Last-Modified: " << TimeRFC1123(Res.LastModified) << "\n";
if (Res.MD5Sum.empty() == false)
- {
- End += snprintf(End,sizeof(S)-50 - (End - S),"MD5-Hash: %s\n",Res.MD5Sum.c_str());
- End += snprintf(End,sizeof(S)-50 - (End - S),"MD5Sum-Hash: %s\n",Res.MD5Sum.c_str());
- }
+ std::cout << "MD5-Hash: " << Res.MD5Sum << "\n"
+ << "MD5Sum-Hash: " << Res.MD5Sum << "\n";
if (Res.SHA1Sum.empty() == false)
- End += snprintf(End,sizeof(S)-50 - (End - S),"SHA1-Hash: %s\n",Res.SHA1Sum.c_str());
+ std::cout << "SHA1-Hash: " << Res.SHA1Sum << "\n";
if (Res.SHA256Sum.empty() == false)
- End += snprintf(End,sizeof(S)-50 - (End - S),"SHA256-Hash: %s\n",Res.SHA256Sum.c_str());
+ std::cout << "SHA256-Hash: " << Res.SHA256Sum << "\n";
if (Res.SHA512Sum.empty() == false)
- End += snprintf(End,sizeof(S)-50 - (End - S),"SHA512-Hash: %s\n",Res.SHA512Sum.c_str());
+ std::cout << "SHA512-Hash: " << Res.SHA512Sum << "\n";
if (UsedMirror.empty() == false)
- End += snprintf(End,sizeof(S)-50 - (End - S),"UsedMirror: %s\n",UsedMirror.c_str());
- if (Res.GPGVOutput.size() > 0)
- End += snprintf(End,sizeof(S)-50 - (End - S),"GPGVOutput:\n");
- for (vector<string>::iterator I = Res.GPGVOutput.begin();
- I != Res.GPGVOutput.end(); I++)
- End += snprintf(End,sizeof(S)-50 - (End - S), " %s\n", (*I).c_str());
+ std::cout << "UsedMirror: " << UsedMirror << "\n";
+ if (Res.GPGVOutput.empty() == false)
+ {
+ std::cout << "GPGVOutput:\n";
+ for (vector<string>::const_iterator I = Res.GPGVOutput.begin();
+ I != Res.GPGVOutput.end(); ++I)
+ std::cout << " " << *I << "\n";
+ }
if (Res.ResumePoint != 0)
- End += snprintf(End,sizeof(S)-50 - (End - S),"Resume-Point: %lu\n",
- Res.ResumePoint);
+ std::cout << "Resume-Point: " << Res.ResumePoint << "\n";
if (Res.IMSHit == true)
- strcat(End,"IMS-Hit: true\n");
- End = S + strlen(S);
-
+ std::cout << "IMS-Hit: true\n";
+
if (Alt != 0)
{
if (Alt->Filename.empty() == false)
- End += snprintf(End,sizeof(S)-50 - (End - S),"Alt-Filename: %s\n",Alt->Filename.c_str());
-
+ std::cout << "Alt-Filename: " << Alt->Filename << "\n";
+
if (Alt->Size != 0)
- End += snprintf(End,sizeof(S)-50 - (End - S),"Alt-Size: %lu\n",Alt->Size);
-
+ std::cout << "Alt-Size: " << Alt->Size << "\n";
+
if (Alt->LastModified != 0)
- End += snprintf(End,sizeof(S)-50 - (End - S),"Alt-Last-Modified: %s\n",
- TimeRFC1123(Alt->LastModified).c_str());
-
+ std::cout << "Alt-Last-Modified: " << TimeRFC1123(Alt->LastModified) << "\n";
+
if (Alt->MD5Sum.empty() == false)
- End += snprintf(End,sizeof(S)-50 - (End - S),"Alt-MD5-Hash: %s\n",
- Alt->MD5Sum.c_str());
+ std::cout << "Alt-MD5-Hash: " << Alt->MD5Sum << "\n";
if (Alt->SHA1Sum.empty() == false)
- End += snprintf(End,sizeof(S)-50 - (End - S),"Alt-SHA1-Hash: %s\n",
- Alt->SHA1Sum.c_str());
+ std::cout << "Alt-SHA1-Hash: " << Alt->SHA1Sum << "\n";
if (Alt->SHA256Sum.empty() == false)
- End += snprintf(End,sizeof(S)-50 - (End - S),"Alt-SHA256-Hash: %s\n",
- Alt->SHA256Sum.c_str());
+ std::cout << "Alt-SHA256-Hash: " << Alt->SHA256Sum << "\n";
if (Alt->SHA512Sum.empty() == false)
- End += snprintf(End,sizeof(S)-50 - (End - S),"Alt-SHA512-Hash: %s\n",
- Alt->SHA512Sum.c_str());
+ std::cout << "Alt-SHA512-Hash: " << Alt->SHA512Sum << "\n";
if (Alt->IMSHit == true)
- strcat(End,"Alt-IMS-Hit: true\n");
+ std::cout << "Alt-IMS-Hit: true\n";
}
-
- strcat(End,"\n");
- if (write(STDOUT_FILENO,S,strlen(S)) != (signed)strlen(S))
- exit(100);
+
+ std::cout << "\n" << std::flush;
// Dequeue
FetchItem *Tmp = Queue;
@@ -252,13 +224,10 @@ void pkgAcqMethod::URIDone(FetchResult &Res, FetchResult *Alt)
to be ackd */
bool pkgAcqMethod::MediaFail(string Required,string Drive)
{
- char S[1024];
- snprintf(S,sizeof(S),"403 Media Failure\nMedia: %s\nDrive: %s\n\n",
+ fprintf(stdout, "403 Media Failure\nMedia: %s\nDrive: %s\n",
Required.c_str(),Drive.c_str());
+ std::cout << "\n" << std::flush;
- if (write(STDOUT_FILENO,S,strlen(S)) != (signed)strlen(S))
- exit(100);
-
vector<string> MyMessages;
/* Here we read messages until we find a 603, each non 603 message is
@@ -409,28 +378,34 @@ int pkgAcqMethod::Run(bool Single)
return 0;
}
/*}}}*/
-// AcqMethod::Log - Send a log message /*{{{*/
+// AcqMethod::PrintStatus - privately really send a log/status message /*{{{*/
// ---------------------------------------------------------------------
/* */
-void pkgAcqMethod::Log(const char *Format,...)
+void pkgAcqMethod::PrintStatus(char const * const header, const char* Format,
+ va_list &args) const
{
string CurrentURI = "<UNKNOWN>";
if (Queue != 0)
CurrentURI = Queue->Uri;
-
+ if (UsedMirror.empty() == true)
+ fprintf(stdout, "%s\nURI: %s\nMessage: ",
+ header, CurrentURI.c_str());
+ else
+ fprintf(stdout, "%s\nURI: %s\nUsedMirror: %s\nMessage: ",
+ header, CurrentURI.c_str(), UsedMirror.c_str());
+ vfprintf(stdout,Format,args);
+ std::cout << "\n\n" << std::flush;
+}
+ /*}}}*/
+// AcqMethod::Log - Send a log message /*{{{*/
+// ---------------------------------------------------------------------
+/* */
+void pkgAcqMethod::Log(const char *Format,...)
+{
va_list args;
va_start(args,Format);
-
- // sprintf the description
- char S[1024];
- unsigned int Len = snprintf(S,sizeof(S)-4,"101 Log\nURI: %s\n"
- "Message: ",CurrentURI.c_str());
-
- vsnprintf(S+Len,sizeof(S)-4-Len,Format,args);
- strcat(S,"\n\n");
-
- if (write(STDOUT_FILENO,S,strlen(S)) != (signed)strlen(S))
- exit(100);
+ PrintStatus("101 Log", Format, args);
+ va_end(args);
}
/*}}}*/
// AcqMethod::Status - Send a status message /*{{{*/
@@ -438,23 +413,10 @@ void pkgAcqMethod::Log(const char *Format,...)
/* */
void pkgAcqMethod::Status(const char *Format,...)
{
- string CurrentURI = "<UNKNOWN>";
- if (Queue != 0)
- CurrentURI = Queue->Uri;
-
va_list args;
va_start(args,Format);
-
- // sprintf the description
- char S[1024];
- unsigned int Len = snprintf(S,sizeof(S)-4,"102 Status\nURI: %s\n"
- "Message: ",CurrentURI.c_str());
-
- vsnprintf(S+Len,sizeof(S)-4-Len,Format,args);
- strcat(S,"\n\n");
-
- if (write(STDOUT_FILENO,S,strlen(S)) != (signed)strlen(S))
- exit(100);
+ PrintStatus("102 Status", Format, args);
+ va_end(args);
}
/*}}}*/
// AcqMethod::Redirect - Send a redirect message /*{{{*/
@@ -463,16 +425,13 @@ void pkgAcqMethod::Status(const char *Format,...)
to keep the pipeline synchronized. */
void pkgAcqMethod::Redirect(const string &NewURI)
{
- string CurrentURI = "<UNKNOWN>";
+ std::cout << "103 Redirect\nURI: ";
if (Queue != 0)
- CurrentURI = Queue->Uri;
-
- char S[1024];
- snprintf(S, sizeof(S)-50, "103 Redirect\nURI: %s\nNew-URI: %s\n\n",
- CurrentURI.c_str(), NewURI.c_str());
-
- if (write(STDOUT_FILENO,S,strlen(S)) != (ssize_t)strlen(S))
- exit(100);
+ std::cout << Queue->Uri << "\n";
+ else
+ std::cout << "<UNKNOWN>\n";
+ std::cout << "New-URI: " << NewURI << "\n"
+ << "\n" << std::flush;
// Change the URI for the request.
Queue->Uri = NewURI;
diff --git a/apt-pkg/acquire-method.h b/apt-pkg/acquire-method.h
index f6bf83842..2d0fa4590 100644
--- a/apt-pkg/acquire-method.h
+++ b/apt-pkg/acquire-method.h
@@ -23,6 +23,7 @@
#include <apt-pkg/configuration.h>
#include <apt-pkg/strutl.h>
+#include <stdarg.h>
class Hashes;
class pkgAcqMethod
@@ -79,6 +80,8 @@ class pkgAcqMethod
bool MediaFail(string Required,string Drive);
virtual void Exit() {};
+ void PrintStatus(char const * const header, const char* Format, va_list &args) const;
+
public:
enum CnfFlags {SingleInstance = (1<<0),
Pipeline = (1<<1), SendConfig = (1<<2),
diff --git a/apt-pkg/acquire-worker.cc b/apt-pkg/acquire-worker.cc
index 4f0b52af9..75e03232a 100644
--- a/apt-pkg/acquire-worker.cc
+++ b/apt-pkg/acquire-worker.cc
@@ -199,6 +199,17 @@ bool pkgAcquire::Worker::RunMessages()
pkgAcquire::Queue::QItem *Itm = 0;
if (URI.empty() == false)
Itm = OwnerQ->FindItem(URI,this);
+
+ // update used mirror
+ string UsedMirror = LookupTag(Message,"UsedMirror", "");
+ if (!UsedMirror.empty() &&
+ Itm &&
+ Itm->Description.find(" ") != string::npos)
+ {
+ Itm->Description.replace(0, Itm->Description.find(" "), UsedMirror);
+ // FIXME: will we need this as well?
+ //Itm->ShortDesc = UsedMirror;
+ }
// Determine the message number and dispatch
switch (Number)
@@ -276,10 +287,10 @@ bool pkgAcquire::Worker::RunMessages()
Log->Pulse(Owner->GetOwner());
OwnerQ->ItemDone(Itm);
- if (TotalSize != 0 &&
- (unsigned)atoi(LookupTag(Message,"Size","0").c_str()) != TotalSize)
- _error->Warning("Bizarre Error - File size is not what the server reported %s %lu",
- LookupTag(Message,"Size","0").c_str(),TotalSize);
+ unsigned long const ServerSize = atol(LookupTag(Message,"Size","0").c_str());
+ if (TotalSize != 0 && ServerSize != TotalSize)
+ _error->Warning("Size of file %s is not what the server reported %s %lu",
+ Owner->DestFile.c_str(), LookupTag(Message,"Size","0").c_str(),TotalSize);
// see if there is a hash to verify
string RecivedHash;
@@ -298,8 +309,7 @@ bool pkgAcquire::Worker::RunMessages()
<< endl << endl;
}
}
- Owner->Done(Message,atoi(LookupTag(Message,"Size","0").c_str()),
- RecivedHash.c_str(), Config);
+ Owner->Done(Message, ServerSize, RecivedHash.c_str(), Config);
ItemDone();
// Log that we are done
diff --git a/apt-pkg/acquire-worker.h b/apt-pkg/acquire-worker.h
index 06283922e..62545829a 100644
--- a/apt-pkg/acquire-worker.h
+++ b/apt-pkg/acquire-worker.h
@@ -44,6 +44,9 @@
*/
class pkgAcquire::Worker : public WeakPointable
{
+ /** \brief dpointer placeholder (for later in case we need it) */
+ void *d;
+
friend class pkgAcquire;
protected:
@@ -314,7 +317,7 @@ class pkgAcquire::Worker : public WeakPointable
* Closes the file descriptors; if MethodConfig::NeedsCleanup is
* \b false, also rudely interrupts the worker with a SIGINT.
*/
- ~Worker();
+ virtual ~Worker();
};
/** @} */
diff --git a/apt-pkg/acquire.h b/apt-pkg/acquire.h
index e3a4435b8..7db7a9958 100644
--- a/apt-pkg/acquire.h
+++ b/apt-pkg/acquire.h
@@ -91,6 +91,12 @@ class pkgAcquireStatus;
*/
class pkgAcquire
{
+ private:
+ /** \brief FD of the Lock file we acquire in Setup (if any) */
+ int LockFD;
+ /** \brief dpointer placeholder (for later in case we need it) */
+ void *d;
+
public:
class Item;
@@ -359,9 +365,6 @@ class pkgAcquire
*/
virtual ~pkgAcquire();
- private:
- /** \brief FD of the Lock file we acquire in Setup (if any) */
- int LockFD;
};
/** \brief Represents a single download source from which an item
@@ -391,6 +394,9 @@ class pkgAcquire::Queue
friend class pkgAcquire::UriIterator;
friend class pkgAcquire::Worker;
+ /** \brief dpointer placeholder (for later in case we need it) */
+ void *d;
+
/** \brief The next queue in the pkgAcquire object's list of queues. */
Queue *Next;
@@ -540,12 +546,15 @@ class pkgAcquire::Queue
/** Shut down all the worker processes associated with this queue
* and empty the queue.
*/
- ~Queue();
+ virtual ~Queue();
};
/*}}}*/
/** \brief Iterates over all the URIs being fetched by a pkgAcquire object. {{{*/
class pkgAcquire::UriIterator
{
+ /** \brief dpointer placeholder (for later in case we need it) */
+ void *d;
+
/** The next queue to iterate over. */
pkgAcquire::Queue *CurQ;
/** The item that we currently point at. */
@@ -581,11 +590,15 @@ class pkgAcquire::UriIterator
CurQ = CurQ->Next;
}
}
+ virtual ~UriIterator() {};
};
/*}}}*/
/** \brief Information about the properties of a single acquire method. {{{*/
struct pkgAcquire::MethodConfig
{
+ /** \brief dpointer placeholder (for later in case we need it) */
+ void *d;
+
/** \brief The next link on the acquire method list.
*
* \todo Why not an STL container?
@@ -634,6 +647,9 @@ struct pkgAcquire::MethodConfig
* appropriate.
*/
MethodConfig();
+
+ /* \brief Destructor, empty currently */
+ virtual ~MethodConfig() {};
};
/*}}}*/
/** \brief A monitor object for downloads controlled by the pkgAcquire class. {{{
@@ -644,6 +660,9 @@ struct pkgAcquire::MethodConfig
*/
class pkgAcquireStatus
{
+ /** \brief dpointer placeholder (for later in case we need it) */
+ void *d;
+
protected:
/** \brief The last time at which this monitor object was updated. */
diff --git a/apt-pkg/algorithms.cc b/apt-pkg/algorithms.cc
index fc520d744..47bdd4aba 100644
--- a/apt-pkg/algorithms.cc
+++ b/apt-pkg/algorithms.cc
@@ -20,12 +20,15 @@
#include <apt-pkg/version.h>
#include <apt-pkg/sptr.h>
#include <apt-pkg/acquire-item.h>
-
+#include <apt-pkg/edsp.h>
+
#include <apti18n.h>
#include <sys/types.h>
#include <cstdlib>
#include <algorithm>
#include <iostream>
+
+#include <stdio.h>
/*}}}*/
using namespace std;
@@ -90,21 +93,6 @@ bool pkgSimulate::Install(PkgIterator iPkg,string /*File*/)
Describe(Pkg,cout,true,true);
Sim.MarkInstall(Pkg,false);
- if (strcmp(Pkg.Arch(),"all") == 0)
- {
- pkgCache::GrpIterator G = Pkg.Group();
- pkgCache::GrpIterator iG = iPkg.Group();
- for (pkgCache::PkgIterator P = G.FindPkg("any"); P.end() != true; P = G.NextPkg(P))
- {
- if (strcmp(P.Arch(), "all") == 0)
- continue;
- if (iG.FindPkg(P.Arch())->CurrentVer == 0)
- continue;
- Flags[P->ID] = 1;
- Sim.MarkInstall(P, false);
- }
- }
-
// Look for broken conflicts+predepends.
for (PkgIterator I = Sim.PkgBegin(); I.end() == false; I++)
{
@@ -116,9 +104,7 @@ bool pkgSimulate::Install(PkgIterator iPkg,string /*File*/)
DepIterator Start;
DepIterator End;
D.GlobOr(Start,End);
- if (Start->Type == pkgCache::Dep::Conflicts ||
- Start->Type == pkgCache::Dep::DpkgBreaks ||
- Start->Type == pkgCache::Dep::Obsoletes ||
+ if (Start.IsNegative() == true ||
End->Type == pkgCache::Dep::PreDepends)
{
if ((Sim[End] & pkgDepCache::DepGInstall) == 0)
@@ -150,19 +136,6 @@ bool pkgSimulate::Configure(PkgIterator iPkg)
Flags[Pkg->ID] = 2;
- if (strcmp(Pkg.Arch(),"all") == 0)
- {
- pkgCache::GrpIterator G = Pkg.Group();
- for (pkgCache::PkgIterator P = G.FindPkg("any"); P.end() != true; P = G.NextPkg(P))
- {
- if (strcmp(P.Arch(), "all") == 0)
- continue;
- if (Flags[P->ID] == 1)
- Flags[P->ID] = 2;
- }
- }
-
-// Sim.MarkInstall(Pkg,false);
if (Sim[Pkg].InstBroken() == true)
{
cout << "Conf " << Pkg.FullName(false) << " broken" << endl;
@@ -214,21 +187,6 @@ bool pkgSimulate::Remove(PkgIterator iPkg,bool Purge)
Flags[Pkg->ID] = 3;
Sim.MarkDelete(Pkg);
- if (strcmp(Pkg.Arch(),"all") == 0)
- {
- pkgCache::GrpIterator G = Pkg.Group();
- pkgCache::GrpIterator iG = iPkg.Group();
- for (pkgCache::PkgIterator P = G.FindPkg("any"); P.end() != true; P = G.NextPkg(P))
- {
- if (strcmp(P.Arch(), "all") == 0)
- continue;
- if (iG.FindPkg(P.Arch())->CurrentVer == 0)
- continue;
- Flags[P->ID] = 3;
- Sim.MarkDelete(P);
- }
- }
-
if (Purge == true)
cout << "Purg ";
else
@@ -372,6 +330,12 @@ bool pkgFixBroken(pkgDepCache &Cache)
*/
bool pkgDistUpgrade(pkgDepCache &Cache)
{
+ std::string const solver = _config->Find("APT::Solver", "internal");
+ if (solver != "internal") {
+ OpTextProgress Prog(*_config);
+ return EDSP::ResolveExternal(solver.c_str(), Cache, false, true, false, &Prog);
+ }
+
pkgDepCache::ActionGroup group(Cache);
/* Upgrade all installed packages first without autoinst to help the resolver
@@ -424,6 +388,12 @@ bool pkgDistUpgrade(pkgDepCache &Cache)
to install packages not marked for install */
bool pkgAllUpgrade(pkgDepCache &Cache)
{
+ std::string const solver = _config->Find("APT::Solver", "internal");
+ if (solver != "internal") {
+ OpTextProgress Prog(*_config);
+ return EDSP::ResolveExternal(solver.c_str(), Cache, true, false, false, &Prog);
+ }
+
pkgDepCache::ActionGroup group(Cache);
pkgProblemResolver Fix(&Cache);
@@ -690,12 +660,10 @@ bool pkgProblemResolver::DoUpgrade(pkgCache::PkgIterator Pkg)
// Compute a single dependency element (glob or)
pkgCache::DepIterator Start = D;
pkgCache::DepIterator End = D;
- unsigned char State = 0;
for (bool LastOR = true; D.end() == false && LastOR == true;)
{
- State |= Cache[D];
LastOR = (D->CompareOp & pkgCache::Dep::Or) == pkgCache::Dep::Or;
- D++;
+ ++D;
if (LastOR == true)
End = D;
}
@@ -740,9 +708,7 @@ bool pkgProblemResolver::DoUpgrade(pkgCache::PkgIterator Pkg)
{
/* We let the algorithm deal with conflicts on its next iteration,
it is much smarter than us */
- if (Start->Type == pkgCache::Dep::Conflicts ||
- Start->Type == pkgCache::Dep::DpkgBreaks ||
- Start->Type == pkgCache::Dep::Obsoletes)
+ if (Start.IsNegative() == true)
break;
if (Debug == true)
@@ -774,7 +740,20 @@ bool pkgProblemResolver::DoUpgrade(pkgCache::PkgIterator Pkg)
return true;
}
/*}}}*/
-// ProblemResolver::Resolve - Run the resolution pass /*{{{*/
+// ProblemResolver::Resolve - calls a resolver to fix the situation /*{{{*/
+// ---------------------------------------------------------------------
+/* */
+bool pkgProblemResolver::Resolve(bool BrokenFix)
+{
+ std::string const solver = _config->Find("APT::Solver", "internal");
+ if (solver != "internal") {
+ OpTextProgress Prog(*_config);
+ return EDSP::ResolveExternal(solver.c_str(), Cache, false, false, false, &Prog);
+ }
+ return ResolveInternal(BrokenFix);
+}
+ /*}}}*/
+// ProblemResolver::ResolveInternal - Run the resolution pass /*{{{*/
// ---------------------------------------------------------------------
/* This routines works by calculating a score for each package. The score
is derived by considering the package's priority and all reverse
@@ -788,12 +767,10 @@ bool pkgProblemResolver::DoUpgrade(pkgCache::PkgIterator Pkg)
The BrokenFix flag enables a mode where the algorithm tries to
upgrade packages to advoid problems. */
-bool pkgProblemResolver::Resolve(bool BrokenFix)
+bool pkgProblemResolver::ResolveInternal(bool const BrokenFix)
{
pkgDepCache::ActionGroup group(Cache);
- unsigned long Size = Cache.Head().PackageCount;
-
// Record which packages are marked for install
bool Again = false;
do
@@ -823,7 +800,9 @@ bool pkgProblemResolver::Resolve(bool BrokenFix)
clog << "Starting" << endl;
MakeScores();
-
+
+ unsigned long const Size = Cache.Head().PackageCount;
+
/* We have to order the packages so that the broken fixing pass
operates from highest score to lowest. This prevents problems when
high score packages cause the removal of lower score packages that
@@ -971,9 +950,7 @@ bool pkgProblemResolver::Resolve(bool BrokenFix)
if a package has a dep on another package that cant be found */
SPtrArray<pkgCache::Version *> VList = Start.AllTargets();
if (*VList == 0 && (Flags[I->ID] & Protected) != Protected &&
- Start->Type != pkgCache::Dep::Conflicts &&
- Start->Type != pkgCache::Dep::DpkgBreaks &&
- Start->Type != pkgCache::Dep::Obsoletes &&
+ Start.IsNegative() == false &&
Cache[I].NowBroken() == false)
{
if (InOr == true)
@@ -998,10 +975,7 @@ bool pkgProblemResolver::Resolve(bool BrokenFix)
at is not the currently selected version of the
package, which means it is not necessary to
remove/keep */
- if (Cache[Pkg].InstallVer != Ver &&
- (Start->Type == pkgCache::Dep::Conflicts ||
- Start->Type == pkgCache::Dep::DpkgBreaks ||
- Start->Type == pkgCache::Dep::Obsoletes))
+ if (Cache[Pkg].InstallVer != Ver && Start.IsNegative() == true)
{
if (Debug)
clog << " Conflicts//Breaks against version "
@@ -1019,9 +993,7 @@ bool pkgProblemResolver::Resolve(bool BrokenFix)
fiddle with the VList package */
if (Scores[I->ID] <= Scores[Pkg->ID] ||
((Cache[Start] & pkgDepCache::DepNow) == 0 &&
- End->Type != pkgCache::Dep::Conflicts &&
- End->Type != pkgCache::Dep::DpkgBreaks &&
- End->Type != pkgCache::Dep::Obsoletes))
+ End.IsNegative() == false))
{
// Try a little harder to fix protected packages..
if ((Flags[I->ID] & Protected) == Protected)
@@ -1128,10 +1100,8 @@ bool pkgProblemResolver::Resolve(bool BrokenFix)
}
// Hm, nothing can possibly satisify this dep. Nuke it.
- if (VList[0] == 0 &&
- Start->Type != pkgCache::Dep::Conflicts &&
- Start->Type != pkgCache::Dep::DpkgBreaks &&
- Start->Type != pkgCache::Dep::Obsoletes &&
+ if (VList[0] == 0 &&
+ Start.IsNegative() == false &&
(Flags[I->ID] & Protected) != Protected)
{
bool Installed = Cache[I].Install();
@@ -1177,9 +1147,7 @@ bool pkgProblemResolver::Resolve(bool BrokenFix)
Change = true;
if ((Cache[J->Dep] & pkgDepCache::DepGNow) == 0)
{
- if (J->Dep->Type == pkgCache::Dep::Conflicts ||
- J->Dep->Type == pkgCache::Dep::DpkgBreaks ||
- J->Dep->Type == pkgCache::Dep::Obsoletes)
+ if (J->Dep.IsNegative() == true)
{
if (Debug == true)
clog << " Fixing " << I.FullName(false) << " via remove of " << J->Pkg.FullName(false) << endl;
@@ -1243,6 +1211,21 @@ bool pkgProblemResolver::Resolve(bool BrokenFix)
system was non-broken previously. */
bool pkgProblemResolver::ResolveByKeep()
{
+ std::string const solver = _config->Find("APT::Solver", "internal");
+ if (solver != "internal") {
+ OpTextProgress Prog(*_config);
+ return EDSP::ResolveExternal(solver.c_str(), Cache, true, false, false, &Prog);
+ }
+ return ResolveByKeepInternal();
+}
+ /*}}}*/
+// ProblemResolver::ResolveByKeepInternal - Resolve problems using keep /*{{{*/
+// ---------------------------------------------------------------------
+/* This is the work horse of the soft upgrade routine. It is very gental
+ in that it does not install or remove any packages. It is assumed that the
+ system was non-broken previously. */
+bool pkgProblemResolver::ResolveByKeepInternal()
+{
pkgDepCache::ActionGroup group(Cache);
unsigned long Size = Cache.Head().PackageCount;
diff --git a/apt-pkg/algorithms.h b/apt-pkg/algorithms.h
index cf4a98c4f..050934bad 100644
--- a/apt-pkg/algorithms.h
+++ b/apt-pkg/algorithms.h
@@ -78,6 +78,9 @@ private:
/*}}}*/
class pkgProblemResolver /*{{{*/
{
+ /** \brief dpointer placeholder (for later in case we need it) */
+ void *d;
+
pkgDepCache &Cache;
typedef pkgCache::PkgIterator PkgIterator;
typedef pkgCache::VerIterator VerIterator;
@@ -105,10 +108,13 @@ class pkgProblemResolver /*{{{*/
void MakeScores();
bool DoUpgrade(pkgCache::PkgIterator Pkg);
+
+ bool ResolveInternal(bool const BrokenFix = false);
+ bool ResolveByKeepInternal();
public:
- inline void Protect(pkgCache::PkgIterator Pkg) {Flags[Pkg->ID] |= Protected;};
+ inline void Protect(pkgCache::PkgIterator Pkg) {Flags[Pkg->ID] |= Protected; Cache.MarkProtected(Pkg);};
inline void Remove(pkgCache::PkgIterator Pkg) {Flags[Pkg->ID] |= ToRemove;};
inline void Clear(pkgCache::PkgIterator Pkg) {Flags[Pkg->ID] &= ~(Protected | ToRemove);};
diff --git a/apt-pkg/aptconfiguration.cc b/apt-pkg/aptconfiguration.cc
index 3cf4d2429..e8c8e73d0 100644
--- a/apt-pkg/aptconfiguration.cc
+++ b/apt-pkg/aptconfiguration.cc
@@ -17,6 +17,7 @@
#include <sys/types.h>
#include <dirent.h>
+#include <stdio.h>
#include <algorithm>
#include <string>
@@ -38,12 +39,11 @@ const Configuration::getCompressionTypes(bool const &Cached) {
// setup the defaults for the compressiontypes => method mapping
_config->CndSet("Acquire::CompressionTypes::bz2","bzip2");
+ _config->CndSet("Acquire::CompressionTypes::xz","xz");
_config->CndSet("Acquire::CompressionTypes::lzma","lzma");
_config->CndSet("Acquire::CompressionTypes::gz","gzip");
- // Set default application paths to check for optional compression types
- _config->CndSet("Dir::Bin::lzma", "/usr/bin/lzma");
- _config->CndSet("Dir::Bin::bzip2", "/bin/bzip2");
+ setDefaultConfigurationForCompressors();
// accept non-list order as override setting for config settings on commandline
std::string const overrideOrder = _config->Find("Acquire::CompressionTypes::Order","");
@@ -224,7 +224,7 @@ std::vector<std::string> const Configuration::getLanguages(bool const &All,
environment.push_back("en");
}
- // Support settings like Acquire::Translation=none on the command line to
+ // Support settings like Acquire::Languages=none on the command line to
// override the configuration settings vector of languages.
string const forceLang = _config->Find("Acquire::Languages","");
if (forceLang.empty() == false) {
@@ -315,11 +315,41 @@ std::vector<std::string> const Configuration::getArchitectures(bool const &Cache
if (likely(Cached == true) && archs.empty() == false)
return archs;
- archs = _config->FindVector("APT::Architectures");
string const arch = _config->Find("APT::Architecture");
+ archs = _config->FindVector("APT::Architectures");
+
if (unlikely(arch.empty() == true))
return archs;
+ // FIXME: It is a bit unclean to have debian specific code here…
+ if (archs.empty() == true) {
+ archs.push_back(arch);
+ string dpkgcall = _config->Find("Dir::Bin::dpkg", "dpkg");
+ std::vector<string> const dpkgoptions = _config->FindVector("DPkg::options");
+ for (std::vector<string>::const_iterator o = dpkgoptions.begin();
+ o != dpkgoptions.end(); ++o)
+ dpkgcall.append(" ").append(*o);
+ dpkgcall.append(" --print-foreign-architectures 2> /dev/null");
+ FILE *dpkg = popen(dpkgcall.c_str(), "r");
+ char buf[1024];
+ if(dpkg != NULL) {
+ if (fgets(buf, sizeof(buf), dpkg) != NULL) {
+ char* arch = strtok(buf, " ");
+ while (arch != NULL) {
+ for (; isspace(*arch) != 0; ++arch);
+ if (arch[0] != '\0') {
+ char const* archend = arch;
+ for (; isspace(*archend) == 0 && *archend != '\0'; ++archend);
+ archs.push_back(string(arch, (archend - arch)));
+ }
+ arch = strtok(NULL, " ");
+ }
+ }
+ pclose(dpkg);
+ }
+ return archs;
+ }
+
if (archs.empty() == true ||
std::find(archs.begin(), archs.end(), arch) == archs.end())
archs.push_back(arch);
@@ -344,4 +374,86 @@ bool const Configuration::checkArchitecture(std::string const &Arch) {
return (std::find(archs.begin(), archs.end(), Arch) != archs.end());
}
/*}}}*/
+// 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");
+}
+ /*}}}*/
+// getCompressors - Return Vector of usbale compressors /*{{{*/
+// ---------------------------------------------------------------------
+/* return a vector of compressors used by apt-ftparchive in the
+ multicompress functionality or to detect data.tar files */
+std::vector<APT::Configuration::Compressor>
+const Configuration::getCompressors(bool const Cached) {
+ static std::vector<APT::Configuration::Compressor> compressors;
+ if (compressors.empty() == false) {
+ if (Cached == true)
+ return compressors;
+ else
+ compressors.clear();
+ }
+
+ setDefaultConfigurationForCompressors();
+
+ compressors.push_back(Compressor(".", "", "", "", "", 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));
+ 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));
+ if (_config->Exists("Dir::Bin::xz") == false || FileExists(_config->FindFile("Dir::Bin::xz")) == true)
+ compressors.push_back(Compressor("xz",".xz","xz","-6","-d",5));
+
+ 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")
+ continue;
+ compressors.push_back(Compressor(c->c_str(), std::string(".").append(*c).c_str(), c->c_str(), "-9", "-d", 100));
+ }
+
+ return compressors;
+}
+ /*}}}*/
+// getCompressorExtensions - supported data.tar extensions /*{{{*/
+// ---------------------------------------------------------------------
+/* */
+std::vector<std::string> const Configuration::getCompressorExtensions() {
+ std::vector<APT::Configuration::Compressor> const compressors = getCompressors();
+ std::vector<std::string> ext;
+ for (std::vector<APT::Configuration::Compressor>::const_iterator c = compressors.begin();
+ c != compressors.end(); ++c)
+ if (c->Extension.empty() == false && c->Extension != ".")
+ ext.push_back(c->Extension);
+ return ext;
+}
+ /*}}}*/
+// Compressor constructor /*{{{*/
+// ---------------------------------------------------------------------
+/* */
+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 = 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);
+ Cost = _config->FindI(std::string(config).append("Cost"), cost);
+ std::string const compConf = std::string(config).append("CompressArg");
+ if (_config->Exists(compConf) == true)
+ CompressArgs = _config->FindVector(compConf);
+ else if (compressArg != NULL)
+ CompressArgs.push_back(compressArg);
+ std::string const uncompConf = std::string(config).append("UncompressArg");
+ if (_config->Exists(uncompConf) == true)
+ UncompressArgs = _config->FindVector(uncompConf);
+ else if (uncompressArg != NULL)
+ UncompressArgs.push_back(uncompressArg);
+}
+ /*}}}*/
}
diff --git a/apt-pkg/aptconfiguration.h b/apt-pkg/aptconfiguration.h
index dd339d841..815db6cae 100644
--- a/apt-pkg/aptconfiguration.h
+++ b/apt-pkg/aptconfiguration.h
@@ -82,6 +82,35 @@ public: /*{{{*/
*/
bool static const checkArchitecture(std::string const &Arch);
+ /** \brief Representation of supported compressors */
+ struct Compressor {
+ std::string Name;
+ std::string Extension;
+ std::string Binary;
+ std::vector<std::string> CompressArgs;
+ std::vector<std::string> UncompressArgs;
+ unsigned short Cost;
+
+ Compressor(char const *name, char const *extension, char const *binary,
+ char const *compressArg, char const *uncompressArg,
+ unsigned short const cost);
+ Compressor() {};
+ };
+
+ /** \brief Return a vector of Compressors supported for data.tar's
+ *
+ * \param Cached saves the result so we need to calculated it only once
+ * this parameter should ony be used for testing purposes.
+ *
+ * \return a vector of Compressors
+ */
+ std::vector<Compressor> static const getCompressors(bool const Cached = true);
+
+ /** \brief Return a vector of extensions supported for data.tar's */
+ std::vector<std::string> static const getCompressorExtensions();
+ /*}}}*/
+ private: /*{{{*/
+ void static setDefaultConfigurationForCompressors();
/*}}}*/
};
/*}}}*/
diff --git a/apt-pkg/cachefile.h b/apt-pkg/cachefile.h
index 09d3ec267..d07337d38 100644
--- a/apt-pkg/cachefile.h
+++ b/apt-pkg/cachefile.h
@@ -25,6 +25,9 @@
class pkgCacheFile
{
+ /** \brief dpointer placeholder (for later in case we need it) */
+ void *d;
+
protected:
MMap *Map;
diff --git a/apt-pkg/cachefilter.h b/apt-pkg/cachefilter.h
index e7ab1723f..5d426008b 100644
--- a/apt-pkg/cachefilter.h
+++ b/apt-pkg/cachefilter.h
@@ -16,6 +16,8 @@ namespace APT {
namespace CacheFilter {
// PackageNameMatchesRegEx /*{{{*/
class PackageNameMatchesRegEx {
+ /** \brief dpointer placeholder (for later in case we need it) */
+ void *d;
regex_t* pattern;
public:
PackageNameMatchesRegEx(std::string const &Pattern);
diff --git a/apt-pkg/cacheiterators.h b/apt-pkg/cacheiterators.h
index 449d4b441..b97a1a589 100644
--- a/apt-pkg/cacheiterators.h
+++ b/apt-pkg/cacheiterators.h
@@ -206,15 +206,10 @@ class pkgCache::VerIterator : public Iterator<Version, VerIterator> {
inline const char *VerStr() const {return S->VerStr == 0?0:Owner->StrP + S->VerStr;};
inline const char *Section() const {return S->Section == 0?0:Owner->StrP + S->Section;};
inline const char *Arch() const {
- if(S->MultiArch == pkgCache::Version::All)
+ if (S->MultiArch == pkgCache::Version::All)
return "all";
return S->ParentPkg == 0?0:Owner->StrP + ParentPkg()->Arch;
};
- inline const char *Arch(bool const pseudo) const {
- if(pseudo == false)
- return Arch();
- return S->ParentPkg == 0?0:Owner->StrP + ParentPkg()->Arch;
- };
inline PkgIterator ParentPkg() const {return PkgIterator(*Owner,Owner->PkgP + S->ParentPkg);};
inline DescIterator DescriptionList() const;
@@ -227,7 +222,6 @@ class pkgCache::VerIterator : public Iterator<Version, VerIterator> {
string RelStr() const;
bool Automatic() const;
- bool Pseudo() const;
VerFileIterator NewestFile() const;
inline VerIterator(pkgCache &Owner,Version *Trg = 0) : Iterator<Version, VerIterator>(Owner, Trg) {
@@ -287,6 +281,7 @@ class pkgCache::DepIterator : public Iterator<Dependency, DepIterator> {
inline PkgIterator ParentPkg() const {return PkgIterator(*Owner,Owner->PkgP + Owner->VerP[S->ParentVer].ParentPkg);};
inline bool Reverse() const {return Type == DepRev;};
bool IsCritical() const;
+ bool IsNegative() const;
void GlobOr(DepIterator &Start,DepIterator &End);
Version **AllTargets() const;
bool SmartTargetPkg(PkgIterator &Result) const;
diff --git a/apt-pkg/cacheset.h b/apt-pkg/cacheset.h
index 3f4f0066b..061d0a2f4 100644
--- a/apt-pkg/cacheset.h
+++ b/apt-pkg/cacheset.h
@@ -135,7 +135,7 @@ public: /*{{{*/
static APT::PackageSet FromTask(pkgCacheFile &Cache, std::string pattern, CacheSetHelper &helper);
static APT::PackageSet FromTask(pkgCacheFile &Cache, std::string const &pattern) {
CacheSetHelper helper;
- return APT::PackageSet::FromTask(Cache, pattern, helper);
+ return FromTask(Cache, pattern, helper);
}
/** \brief returns all packages in the cache whose name matchs a given pattern
@@ -149,7 +149,7 @@ public: /*{{{*/
static APT::PackageSet FromRegEx(pkgCacheFile &Cache, std::string pattern, CacheSetHelper &helper);
static APT::PackageSet FromRegEx(pkgCacheFile &Cache, std::string const &pattern) {
CacheSetHelper helper;
- return APT::PackageSet::FromRegEx(Cache, pattern, helper);
+ return FromRegEx(Cache, pattern, helper);
}
/** \brief returns all packages specified by a string
@@ -160,7 +160,7 @@ public: /*{{{*/
static APT::PackageSet FromString(pkgCacheFile &Cache, std::string const &string, CacheSetHelper &helper);
static APT::PackageSet FromString(pkgCacheFile &Cache, std::string const &string) {
CacheSetHelper helper;
- return APT::PackageSet::FromString(Cache, string, helper);
+ return FromString(Cache, string, helper);
}
/** \brief returns a package specified by a string
@@ -171,7 +171,7 @@ public: /*{{{*/
static pkgCache::PkgIterator FromName(pkgCacheFile &Cache, std::string const &string, CacheSetHelper &helper);
static pkgCache::PkgIterator FromName(pkgCacheFile &Cache, std::string const &string) {
CacheSetHelper helper;
- return APT::PackageSet::FromName(Cache, string, helper);
+ return FromName(Cache, string, helper);
}
/** \brief returns all packages specified on the commandline
@@ -184,7 +184,7 @@ public: /*{{{*/
static APT::PackageSet FromCommandLine(pkgCacheFile &Cache, const char **cmdline, CacheSetHelper &helper);
static APT::PackageSet FromCommandLine(pkgCacheFile &Cache, const char **cmdline) {
CacheSetHelper helper;
- return APT::PackageSet::FromCommandLine(Cache, cmdline, helper);
+ return FromCommandLine(Cache, cmdline, helper);
}
struct Modifier {
@@ -215,7 +215,7 @@ public: /*{{{*/
std::list<PackageSet::Modifier> const &mods,
unsigned short const &fallback) {
CacheSetHelper helper;
- return APT::PackageSet::GroupedFromCommandLine(Cache, cmdline,
+ return GroupedFromCommandLine(Cache, cmdline,
mods, fallback, helper);
}
@@ -257,7 +257,6 @@ public: /*{{{*/
inline const char *VerStr() const { return (**this).VerStr(); };
inline const char *Section() const { return (**this).Section(); };
inline const char *Arch() const { return (**this).Arch(); };
- inline const char *Arch(bool const pseudo) const { return (**this).Arch(pseudo); };
inline pkgCache::PkgIterator ParentPkg() const { return (**this).ParentPkg(); };
inline pkgCache::DescIterator DescriptionList() const { return (**this).DescriptionList(); };
inline pkgCache::DescIterator TranslatedDescription() const { return (**this).TranslatedDescription(); };
@@ -268,7 +267,6 @@ public: /*{{{*/
inline const char *PriorityType() const { return (**this).PriorityType(); };
inline string RelStr() const { return (**this).RelStr(); };
inline bool Automatic() const { return (**this).Automatic(); };
- inline bool Pseudo() const { return (**this).Pseudo(); };
inline pkgCache::VerFileIterator NewestFile() const { return (**this).NewestFile(); };
};
/*}}}*/
@@ -309,10 +307,10 @@ public: /*{{{*/
static APT::VersionSet FromCommandLine(pkgCacheFile &Cache, const char **cmdline,
APT::VersionSet::Version const &fallback) {
CacheSetHelper helper;
- return APT::VersionSet::FromCommandLine(Cache, cmdline, fallback, helper);
+ return FromCommandLine(Cache, cmdline, fallback, helper);
}
static APT::VersionSet FromCommandLine(pkgCacheFile &Cache, const char **cmdline) {
- return APT::VersionSet::FromCommandLine(Cache, cmdline, CANDINST);
+ return FromCommandLine(Cache, cmdline, CANDINST);
}
static APT::VersionSet FromString(pkgCacheFile &Cache, std::string pkg,
@@ -321,10 +319,10 @@ public: /*{{{*/
static APT::VersionSet FromString(pkgCacheFile &Cache, std::string pkg,
APT::VersionSet::Version const &fallback) {
CacheSetHelper helper;
- return APT::VersionSet::FromString(Cache, pkg, fallback, helper);
+ return FromString(Cache, pkg, fallback, helper);
}
static APT::VersionSet FromString(pkgCacheFile &Cache, std::string pkg) {
- return APT::VersionSet::FromString(Cache, pkg, CANDINST);
+ return FromString(Cache, pkg, CANDINST);
}
/** \brief returns all versions specified for the package
@@ -338,10 +336,10 @@ public: /*{{{*/
static APT::VersionSet FromPackage(pkgCacheFile &Cache, pkgCache::PkgIterator const &P,
APT::VersionSet::Version const &fallback) {
CacheSetHelper helper;
- return APT::VersionSet::FromPackage(Cache, P, fallback, helper);
+ return FromPackage(Cache, P, fallback, helper);
}
static APT::VersionSet FromPackage(pkgCacheFile &Cache, pkgCache::PkgIterator const &P) {
- return APT::VersionSet::FromPackage(Cache, P, CANDINST);
+ return FromPackage(Cache, P, CANDINST);
}
struct Modifier {
@@ -364,7 +362,7 @@ public: /*{{{*/
std::list<VersionSet::Modifier> const &mods,
unsigned short const &fallback) {
CacheSetHelper helper;
- return APT::VersionSet::GroupedFromCommandLine(Cache, cmdline,
+ return GroupedFromCommandLine(Cache, cmdline,
mods, fallback, helper);
}
/*}}}*/
diff --git a/apt-pkg/cdrom.cc b/apt-pkg/cdrom.cc
index 04ace10a6..2a914c665 100644
--- a/apt-pkg/cdrom.cc
+++ b/apt-pkg/cdrom.cc
@@ -155,7 +155,11 @@ bool pkgCdrom::FindPackages(string CD,
break;
if (chdir(CD.c_str()) != 0)
- return _error->Errno("chdir","Unable to change to %s",CD.c_str());
+ {
+ _error->Errno("chdir","Unable to change to %s", CD.c_str());
+ closedir(D);
+ return false;
+ }
};
closedir(D);
@@ -257,8 +261,10 @@ bool pkgCdrom::DropRepeats(vector<string> &List,const char *Name)
Inodes[I] = Buf.st_ino;
}
- if (_error->PendingError() == true)
+ if (_error->PendingError() == true) {
+ delete[] Inodes;
return false;
+ }
// Look for dups
for (unsigned int I = 0; I != List.size(); I++)
@@ -513,7 +519,8 @@ bool pkgCdrom::Ident(string &ident, pkgCdromStatus *log) /*{{{*/
if (CDROM[0] == '.')
CDROM= SafeGetCWD() + '/' + CDROM;
- if(log) {
+ if (log != NULL)
+ {
msg.str("");
ioprintf(msg, _("Using CD-ROM mount point %s\nMounting CD-ROM\n"),
CDROM.c_str());
@@ -523,7 +530,7 @@ bool pkgCdrom::Ident(string &ident, pkgCdromStatus *log) /*{{{*/
return _error->Error("Failed to mount the cdrom.");
// Hash the CD to get an ID
- if(log)
+ if (log != NULL)
log->Update(_("Identifying.. "));
@@ -533,10 +540,12 @@ bool pkgCdrom::Ident(string &ident, pkgCdromStatus *log) /*{{{*/
return false;
}
- msg.str("");
- ioprintf(msg, "[%s]\n",ident.c_str());
- log->Update(msg.str());
-
+ if (log != NULL)
+ {
+ msg.str("");
+ ioprintf(msg, "[%s]\n",ident.c_str());
+ log->Update(msg.str());
+ }
// Read the database
Configuration Database;
@@ -547,7 +556,8 @@ bool pkgCdrom::Ident(string &ident, pkgCdromStatus *log) /*{{{*/
return _error->Error("Unable to read the cdrom database %s",
DFile.c_str());
}
- if(log) {
+ if (log != NULL)
+ {
msg.str("");
ioprintf(msg, _("Stored label: %s\n"),
Database.Find("CD::"+ident).c_str());
@@ -555,8 +565,10 @@ bool pkgCdrom::Ident(string &ident, pkgCdromStatus *log) /*{{{*/
}
// Unmount and finish
- if (_config->FindB("APT::CDROM::NoMount",false) == false) {
- log->Update(_("Unmounting CD-ROM...\n"), STEP_LAST);
+ if (_config->FindB("APT::CDROM::NoMount",false) == false)
+ {
+ if (log != NULL)
+ log->Update(_("Unmounting CD-ROM...\n"), STEP_LAST);
UnmountCdrom(CDROM);
}
@@ -572,7 +584,8 @@ bool pkgCdrom::Add(pkgCdromStatus *log) /*{{{*/
if (CDROM[0] == '.')
CDROM= SafeGetCWD() + '/' + CDROM;
- if(log) {
+ if(log != NULL)
+ {
log->SetTotal(STEP_LAST);
msg.str("");
ioprintf(msg, _("Using CD-ROM mount point %s\n"), CDROM.c_str());
@@ -592,11 +605,12 @@ bool pkgCdrom::Add(pkgCdromStatus *log) /*{{{*/
// Unmount the CD and get the user to put in the one they want
if (_config->FindB("APT::CDROM::NoMount",false) == false)
{
- if(log)
+ if(log != NULL)
log->Update(_("Unmounting CD-ROM\n"), STEP_UNMOUNT);
UnmountCdrom(CDROM);
- if(log) {
+ if(log != NULL)
+ {
log->Update(_("Waiting for disc...\n"), STEP_WAIT);
if(!log->ChangeCdrom()) {
// user aborted
@@ -605,26 +619,29 @@ bool pkgCdrom::Add(pkgCdromStatus *log) /*{{{*/
}
// Mount the new CDROM
- log->Update(_("Mounting CD-ROM...\n"), STEP_MOUNT);
+ if(log != NULL)
+ log->Update(_("Mounting CD-ROM...\n"), STEP_MOUNT);
+
if (MountCdrom(CDROM) == false)
return _error->Error("Failed to mount the cdrom.");
}
// Hash the CD to get an ID
- if(log)
+ if(log != NULL)
log->Update(_("Identifying.. "), STEP_IDENT);
string ID;
if (IdentCdrom(CDROM,ID) == false)
{
- log->Update("\n");
+ if (log != NULL)
+ log->Update("\n");
return false;
}
- if(log)
+ if(log != NULL)
+ {
log->Update("["+ID+"]\n");
-
- if(log)
log->Update(_("Scanning disc for index files..\n"),STEP_SCAN);
-
+ }
+
// Get the CD structure
vector<string> List;
vector<string> SourceList;
@@ -634,7 +651,8 @@ bool pkgCdrom::Add(pkgCdromStatus *log) /*{{{*/
string InfoDir;
if (FindPackages(CDROM,List,SourceList, SigList,TransList,InfoDir,log) == false)
{
- log->Update("\n");
+ if (log != NULL)
+ log->Update("\n");
return false;
}
@@ -661,7 +679,7 @@ bool pkgCdrom::Add(pkgCdromStatus *log) /*{{{*/
DropRepeats(SourceList,"Sources");
DropRepeats(SigList,"Release.gpg");
DropRepeats(TransList,"");
- if(log) {
+ if(log != NULL) {
msg.str("");
ioprintf(msg, _("Found %zu package indexes, %zu source indexes, "
"%zu translation indexes and %zu signatures\n"),
@@ -698,7 +716,8 @@ bool pkgCdrom::Add(pkgCdromStatus *log) /*{{{*/
if (*J == '"' || *J == ']' || *J == '[')
*J = '_';
- if(log) {
+ if(log != NULL)
+ {
msg.str("");
ioprintf(msg, _("Found label '%s'\n"), Name.c_str());
log->Update(msg.str());
@@ -710,7 +729,7 @@ bool pkgCdrom::Add(pkgCdromStatus *log) /*{{{*/
if (_config->FindB("APT::CDROM::Rename",false) == true ||
Name.empty() == true)
{
- if(!log)
+ if(log == NULL)
{
if (_config->FindB("APT::CDROM::NoMount",false) == false)
UnmountCdrom(CDROM);
@@ -743,13 +762,13 @@ bool pkgCdrom::Add(pkgCdromStatus *log) /*{{{*/
*J = '_';
Database.Set("CD::" + ID,Name);
- if(log) {
+ if(log != NULL)
+ {
msg.str("");
ioprintf(msg, _("This disc is called: \n'%s'\n"), Name.c_str());
log->Update(msg.str());
+ log->Update(_("Copying package lists..."), STEP_COPY);
}
-
- log->Update(_("Copying package lists..."), STEP_COPY);
// take care of the signatures and copy them if they are ok
// (we do this before PackageCopy as it modifies "List" and "SourceList")
SigVerify SignVerify;
@@ -774,16 +793,15 @@ bool pkgCdrom::Add(pkgCdromStatus *log) /*{{{*/
if (WriteDatabase(Database) == false)
return false;
- if(log) {
+ if(log != NULL)
log->Update(_("Writing new source list\n"), STEP_WRITE);
- }
if (WriteSourceList(Name,List,false) == false ||
WriteSourceList(Name,SourceList,true) == false)
return false;
}
// Print the sourcelist entries
- if(log)
+ if(log != NULL)
log->Update(_("Source list entries for this disc are:\n"));
for (vector<string>::iterator I = List.begin(); I != List.end(); I++)
@@ -796,7 +814,8 @@ bool pkgCdrom::Add(pkgCdromStatus *log) /*{{{*/
return _error->Error("Internal error");
}
- if(log) {
+ if(log != NULL)
+ {
msg.str("");
msg << "deb cdrom:[" << Name << "]/" << string(*I,0,Space) <<
" " << string(*I,Space+1) << endl;
@@ -814,7 +833,7 @@ bool pkgCdrom::Add(pkgCdromStatus *log) /*{{{*/
return _error->Error("Internal error");
}
- if(log) {
+ if(log != NULL) {
msg.str("");
msg << "deb-src cdrom:[" << Name << "]/" << string(*I,0,Space) <<
" " << string(*I,Space+1) << endl;
@@ -824,7 +843,8 @@ bool pkgCdrom::Add(pkgCdromStatus *log) /*{{{*/
// Unmount and finish
if (_config->FindB("APT::CDROM::NoMount",false) == false) {
- log->Update(_("Unmounting CD-ROM...\n"), STEP_LAST);
+ if (log != NULL)
+ log->Update(_("Unmounting CD-ROM...\n"), STEP_LAST);
UnmountCdrom(CDROM);
}
@@ -854,6 +874,9 @@ pkgUdevCdromDevices::Dlopen() /*{{{*/
libudev_handle = h;
udev_new = (udev* (*)(void)) dlsym(h, "udev_new");
udev_enumerate_add_match_property = (int (*)(udev_enumerate*, const char*, const char*))dlsym(h, "udev_enumerate_add_match_property");
+#if 0 // FIXME: uncomment on next ABI break
+ udev_enumerate_add_match_sysattr = (int (*)(udev_enumerate*, const char*, const char*))dlsym(h, "udev_enumerate_add_match_sysattr");
+#endif
udev_enumerate_scan_devices = (int (*)(udev_enumerate*))dlsym(h, "udev_enumerate_scan_devices");
udev_enumerate_get_list_entry = (udev_list_entry* (*)(udev_enumerate*))dlsym(h, "udev_enumerate_get_list_entry");
udev_device_new_from_syspath = (udev_device* (*)(udev*, const char*))dlsym(h, "udev_device_new_from_syspath");
@@ -867,8 +890,20 @@ pkgUdevCdromDevices::Dlopen() /*{{{*/
return true;
}
/*}}}*/
+
+ /*{{{*/
+// compatiblity only with the old API/ABI, can be removed on the next
+// ABI break
+vector<CdromDevice>
+pkgUdevCdromDevices::Scan()
+{
+ bool CdromOnly = _config->FindB("APT::cdrom::CdromOnly", true);
+ return ScanForRemovable(CdromOnly);
+};
+ /*}}}*/
+ /*{{{*/
vector<CdromDevice>
-pkgUdevCdromDevices::Scan() /*{{{*/
+pkgUdevCdromDevices::ScanForRemovable(bool CdromOnly)
{
vector<CdromDevice> cdrom_devices;
struct udev_enumerate *enumerate;
@@ -880,7 +915,15 @@ pkgUdevCdromDevices::Scan() /*{{{*/
udev_ctx = udev_new();
enumerate = udev_enumerate_new (udev_ctx);
- udev_enumerate_add_match_property(enumerate, "ID_CDROM", "1");
+ if (CdromOnly)
+ udev_enumerate_add_match_property(enumerate, "ID_CDROM", "1");
+ else {
+#if 1 // FIXME: remove the next two lines on the next ABI break
+ int (*udev_enumerate_add_match_sysattr)(struct udev_enumerate *udev_enumerate, const char *property, const char *value);
+ udev_enumerate_add_match_sysattr = (int (*)(udev_enumerate*, const char*, const char*))dlsym(libudev_handle, "udev_enumerate_add_match_sysattr");
+#endif
+ udev_enumerate_add_match_sysattr(enumerate, "removable", "1");
+ }
udev_enumerate_scan_devices (enumerate);
devices = udev_enumerate_get_list_entry (enumerate);
@@ -892,11 +935,18 @@ pkgUdevCdromDevices::Scan() /*{{{*/
if (udevice == NULL)
continue;
const char* devnode = udev_device_get_devnode(udevice);
- const char* mountpath = udev_device_get_property_value(udevice, "FSTAB_DIR");
+
+ // try fstab_dir first
+ string mountpath;
+ const char* mp = udev_device_get_property_value(udevice, "FSTAB_DIR");
+ if (mp)
+ mountpath = string(mp);
+ else
+ mountpath = FindMountPointForDevice(devnode);
// fill in the struct
cdrom.DeviceName = string(devnode);
- if (mountpath) {
+ if (mountpath != "") {
cdrom.MountPath = mountpath;
string s = string(mountpath);
cdrom.Mounted = IsMounted(s);
diff --git a/apt-pkg/cdrom.h b/apt-pkg/cdrom.h
index 14ca1d810..e83c38582 100644
--- a/apt-pkg/cdrom.h
+++ b/apt-pkg/cdrom.h
@@ -68,7 +68,7 @@ class pkgCdrom /*{{{*/
/*}}}*/
-// class that uses libudev to find cdrom devices dynamically
+// class that uses libudev to find cdrom/removable devices dynamically
struct CdromDevice /*{{{*/
{
string DeviceName;
@@ -92,6 +92,9 @@ class pkgUdevCdromDevices /*{{{*/
struct udev_enumerate *(*udev_enumerate_new) (struct udev *udev);
struct udev_list_entry *(*udev_list_entry_get_next)(struct udev_list_entry *list_entry);
const char* (*udev_device_get_property_value)(struct udev_device *udev_device, const char *key);
+#if 0 // FIXME: uncomment on next ABI break
+ int (*udev_enumerate_add_match_sysattr)(struct udev_enumerate *udev_enumerate, const char *property, const char *value);
+#endif
// end libudev dlopen
public:
@@ -100,7 +103,12 @@ class pkgUdevCdromDevices /*{{{*/
// try to open
bool Dlopen();
+
+ // this is the new interface
+ vector<CdromDevice> ScanForRemovable(bool CdromOnly);
+ // FIXME: compat with the old interface/API/ABI only
vector<CdromDevice> Scan();
+
};
/*}}}*/
diff --git a/apt-pkg/clean.h b/apt-pkg/clean.h
index 2aee2bf54..1ebf68dc9 100644
--- a/apt-pkg/clean.h
+++ b/apt-pkg/clean.h
@@ -15,6 +15,9 @@
class pkgArchiveCleaner
{
+ /** \brief dpointer placeholder (for later in case we need it) */
+ void *d;
+
protected:
virtual void Erase(const char * /*File*/,string /*Pkg*/,string /*Ver*/,struct stat & /*St*/) {};
diff --git a/apt-pkg/contrib/cdromutl.cc b/apt-pkg/contrib/cdromutl.cc
index 68b980407..821e6d688 100644
--- a/apt-pkg/contrib/cdromutl.cc
+++ b/apt-pkg/contrib/cdromutl.cc
@@ -15,11 +15,11 @@
#include <apt-pkg/md5.h>
#include <apt-pkg/fileutl.h>
#include <apt-pkg/configuration.h>
+#include <apt-pkg/strutl.h>
#include <apti18n.h>
#include <sys/wait.h>
-#include <sys/errno.h>
#include <sys/statvfs.h>
#include <dirent.h>
#include <fcntl.h>
@@ -205,8 +205,11 @@ bool IdentCdrom(string CD,string &Res,unsigned int Version)
Hash.Add(Dir->d_name);
};
- if (chdir(StartDir.c_str()) != 0)
- return _error->Errno("chdir",_("Unable to change to %s"),StartDir.c_str());
+ if (chdir(StartDir.c_str()) != 0) {
+ _error->Errno("chdir",_("Unable to change to %s"),StartDir.c_str());
+ closedir(D);
+ return false;
+ }
closedir(D);
// Some stats from the fsys
@@ -234,3 +237,35 @@ bool IdentCdrom(string CD,string &Res,unsigned int Version)
return true;
}
/*}}}*/
+
+// FindMountPointForDevice - Find mountpoint for the given device /*{{{*/
+string FindMountPointForDevice(const char *devnode)
+{
+ char buf[255];
+ char *out[10];
+ int i=0;
+
+ // this is the order that mount uses as well
+ const char *mount[] = { "/etc/mtab",
+ "/proc/mount",
+ NULL };
+
+ for (i=0; mount[i] != NULL; i++) {
+ if (FileExists(mount[i])) {
+ FILE *f=fopen(mount[i], "r");
+ while ( fgets(buf, sizeof(buf), f) != NULL) {
+ if (strncmp(buf, devnode, strlen(devnode)) == 0) {
+ if(TokSplitString(' ', buf, out, 10))
+ {
+ fclose(f);
+ return string(out[1]);
+ }
+ }
+ }
+ fclose(f);
+ }
+ }
+
+ return string();
+}
+ /*}}}*/
diff --git a/apt-pkg/contrib/cdromutl.h b/apt-pkg/contrib/cdromutl.h
index 9d14249c5..38ed2996e 100644
--- a/apt-pkg/contrib/cdromutl.h
+++ b/apt-pkg/contrib/cdromutl.h
@@ -19,5 +19,6 @@ bool MountCdrom(string Path, string DeviceName="");
bool UnmountCdrom(string Path);
bool IdentCdrom(string CD,string &Res,unsigned int Version = 2);
bool IsMounted(string &Path);
+string FindMountPointForDevice(const char *device);
#endif
diff --git a/apt-pkg/contrib/configuration.h b/apt-pkg/contrib/configuration.h
index 175c1bef3..71e5a0e47 100644
--- a/apt-pkg/contrib/configuration.h
+++ b/apt-pkg/contrib/configuration.h
@@ -72,8 +72,8 @@ class Configuration
string Find(string const &Name, string const &Default) const {return Find(Name.c_str(),Default.c_str());};
string FindFile(const char *Name,const char *Default = 0) const;
string FindDir(const char *Name,const char *Default = 0) const;
- std::vector<string> FindVector(string const &Name) const;
std::vector<string> FindVector(const char *Name) const;
+ std::vector<string> FindVector(string const &Name) const { return FindVector(Name.c_str()); };
int FindI(const char *Name,int const &Default = 0) const;
int FindI(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/error.cc b/apt-pkg/contrib/error.cc
index e2e8d6e57..18810d2a4 100644
--- a/apt-pkg/contrib/error.cc
+++ b/apt-pkg/contrib/error.cc
@@ -18,6 +18,7 @@
#include <iostream>
#include <errno.h>
#include <stdio.h>
+#include <stdlib.h>
#include <unistd.h>
#include <string>
@@ -57,108 +58,112 @@
// GlobalError::GlobalError - Constructor /*{{{*/
GlobalError::GlobalError() : PendingFlag(false) {}
/*}}}*/
-// GlobalError::FatalE - Get part of the error string from errno /*{{{*/
-bool GlobalError::FatalE(const char *Function,const char *Description,...) {
- va_list args;
- va_start(args,Description);
- return InsertErrno(FATAL, Function, Description, args);
-}
- /*}}}*/
-// GlobalError::Errno - Get part of the error string from errno /*{{{*/
-bool GlobalError::Errno(const char *Function,const char *Description,...) {
- va_list args;
- va_start(args,Description);
- return InsertErrno(ERROR, Function, Description, args);
-}
- /*}}}*/
-// GlobalError::WarningE - Get part of the warning string from errno /*{{{*/
-bool GlobalError::WarningE(const char *Function,const char *Description,...) {
- va_list args;
- va_start(args,Description);
- return InsertErrno(WARNING, Function, Description, args);
-}
- /*}}}*/
-// GlobalError::NoticeE - Get part of the notice string from errno /*{{{*/
-bool GlobalError::NoticeE(const char *Function,const char *Description,...) {
- va_list args;
- va_start(args,Description);
- return InsertErrno(NOTICE, Function, Description, args);
-}
- /*}}}*/
-// GlobalError::DebugE - Get part of the debug string from errno /*{{{*/
-bool GlobalError::DebugE(const char *Function,const char *Description,...) {
- va_list args;
- va_start(args,Description);
- return InsertErrno(DEBUG, Function, Description, args);
+// GlobalError::FatalE, Errno, WarningE, NoticeE and DebugE - Add to the list/*{{{*/
+#define GEMessage(NAME, TYPE) \
+bool GlobalError::NAME (const char *Function, const char *Description,...) { \
+ va_list args; \
+ size_t msgSize = 400; \
+ int const errsv = errno; \
+ while (true) { \
+ va_start(args,Description); \
+ if (InsertErrno(TYPE, Function, Description, args, errsv, msgSize) == false) \
+ break; \
+ va_end(args); \
+ } \
+ return false; \
}
+GEMessage(FatalE, FATAL)
+GEMessage(Errno, ERROR)
+GEMessage(WarningE, WARNING)
+GEMessage(NoticeE, NOTICE)
+GEMessage(DebugE, DEBUG)
+#undef GEMessage
/*}}}*/
// GlobalError::InsertErrno - Get part of the errortype string from errno/*{{{*/
bool GlobalError::InsertErrno(MsgType const &type, const char *Function,
const char *Description,...) {
va_list args;
- va_start(args,Description);
- return InsertErrno(type, Function, Description, args);
+ size_t msgSize = 400;
+ int const errsv = errno;
+ while (true) {
+ va_start(args,Description);
+ if (InsertErrno(type, Function, Description, args, errsv, msgSize) == false)
+ break;
+ va_end(args);
+ }
+ return false;
}
/*}}}*/
// GlobalError::InsertErrno - formats an error message with the errno /*{{{*/
bool GlobalError::InsertErrno(MsgType type, const char* Function,
- const char* Description, va_list &args) {
- char S[400];
- snprintf(S, sizeof(S), "%s - %s (%i: %s)", Description,
- Function, errno, strerror(errno));
- return Insert(type, S, args);
-}
- /*}}}*/
-// GlobalError::Fatal - Add a fatal error to the list /*{{{*/
-bool GlobalError::Fatal(const char *Description,...) {
- va_list args;
- va_start(args,Description);
- return Insert(FATAL, Description, args);
-}
- /*}}}*/
-// GlobalError::Error - Add an error to the list /*{{{*/
-bool GlobalError::Error(const char *Description,...) {
- va_list args;
- va_start(args,Description);
- return Insert(ERROR, Description, args);
-}
- /*}}}*/
-// GlobalError::Warning - Add a warning to the list /*{{{*/
-bool GlobalError::Warning(const char *Description,...) {
- va_list args;
- va_start(args,Description);
- return Insert(WARNING, Description, args);
-}
- /*}}}*/
-// GlobalError::Notice - Add a notice to the list /*{{{*/
-bool GlobalError::Notice(const char *Description,...)
-{
- va_list args;
- va_start(args,Description);
- return Insert(NOTICE, Description, args);
+ const char* Description, va_list &args,
+ int const errsv, size_t &msgSize) {
+ char* S = (char*) malloc(msgSize);
+ int const n = snprintf(S, msgSize, "%s - %s (%i: %s)", Description,
+ Function, errsv, strerror(errsv));
+ if (n > -1 && ((unsigned int) n) < msgSize);
+ else {
+ if (n > -1)
+ msgSize = n + 1;
+ else
+ msgSize *= 2;
+ free(S);
+ return true;
+ }
+
+ bool const geins = Insert(type, S, args, msgSize);
+ free(S);
+ return geins;
}
/*}}}*/
-// GlobalError::Debug - Add a debug to the list /*{{{*/
-bool GlobalError::Debug(const char *Description,...)
-{
- va_list args;
- va_start(args,Description);
- return Insert(DEBUG, Description, args);
+// GlobalError::Fatal, Error, Warning, Notice and Debug - Add to the list/*{{{*/
+#define GEMessage(NAME, TYPE) \
+bool GlobalError::NAME (const char *Description,...) { \
+ va_list args; \
+ size_t msgSize = 400; \
+ while (true) { \
+ va_start(args,Description); \
+ if (Insert(TYPE, Description, args, msgSize) == false) \
+ break; \
+ va_end(args); \
+ } \
+ return false; \
}
+GEMessage(Fatal, FATAL)
+GEMessage(Error, ERROR)
+GEMessage(Warning, WARNING)
+GEMessage(Notice, NOTICE)
+GEMessage(Debug, DEBUG)
+#undef GEMessage
/*}}}*/
// GlobalError::Insert - Add a errotype message to the list /*{{{*/
bool GlobalError::Insert(MsgType const &type, const char *Description,...)
{
va_list args;
- va_start(args,Description);
- return Insert(type, Description, args);
+ size_t msgSize = 400;
+ while (true) {
+ va_start(args,Description);
+ if (Insert(type, Description, args, msgSize) == false)
+ break;
+ va_end(args);
+ }
+ return false;
}
/*}}}*/
// GlobalError::Insert - Insert a new item at the end /*{{{*/
bool GlobalError::Insert(MsgType type, const char* Description,
- va_list &args) {
- char S[400];
- vsnprintf(S,sizeof(S),Description,args);
+ va_list &args, size_t &msgSize) {
+ char* S = (char*) malloc(msgSize);
+ int const n = vsnprintf(S, msgSize, Description, args);
+ if (n > -1 && ((unsigned int) n) < msgSize);
+ else {
+ if (n > -1)
+ msgSize = n + 1;
+ else
+ msgSize *= 2;
+ free(S);
+ return true;
+ }
Item const m(S, type);
Messages.push_back(m);
@@ -169,6 +174,7 @@ bool GlobalError::Insert(MsgType type, const char* Description,
if (type == FATAL || type == DEBUG)
std::clog << m << std::endl;
+ free(S);
return false;
}
/*}}}*/
diff --git a/apt-pkg/contrib/error.h b/apt-pkg/contrib/error.h
index ae756dbc4..21c51c1be 100644
--- a/apt-pkg/contrib/error.h
+++ b/apt-pkg/contrib/error.h
@@ -307,9 +307,10 @@ private: /*{{{*/
std::list<MsgStack> Stacks;
bool InsertErrno(MsgType type, const char* Function,
- const char* Description, va_list &args);
+ const char* Description, va_list &args,
+ int const errsv, size_t &msgSize);
bool Insert(MsgType type, const char* Description,
- va_list &args);
+ va_list &args, size_t &msgSize);
/*}}}*/
};
/*}}}*/
diff --git a/apt-pkg/contrib/fileutl.cc b/apt-pkg/contrib/fileutl.cc
index 52f517ee0..50019872e 100644
--- a/apt-pkg/contrib/fileutl.cc
+++ b/apt-pkg/contrib/fileutl.cc
@@ -42,6 +42,11 @@
#include <errno.h>
#include <set>
#include <algorithm>
+
+#include <config.h>
+#ifdef WORDS_BIGENDIAN
+#include <inttypes.h>
+#endif
/*}}}*/
using namespace std;
@@ -62,6 +67,15 @@ bool RunScripts(const char *Cnf)
// This is the child
if (Child == 0)
{
+ if (_config->FindDir("DPkg::Chroot-Directory","/") != "/")
+ {
+ std::cerr << "Chrooting into "
+ << _config->FindDir("DPkg::Chroot-Directory")
+ << std::endl;
+ if (chroot(_config->FindDir("DPkg::Chroot-Directory","/").c_str()) != 0)
+ _exit(100);
+ }
+
if (chdir("/tmp/") != 0)
_exit(100);
@@ -962,9 +976,16 @@ unsigned long FileFd::Size()
off_t orig_pos = lseek(iFd, 0, SEEK_CUR);
if (lseek(iFd, -4, SEEK_END) < 0)
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");
- size &= 0xFFFFFFFF;
+
+#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
if (lseek(iFd, orig_pos, SEEK_SET) < 0)
return _error->Errno("lseek","Unable to seek in gzipped file");
diff --git a/apt-pkg/contrib/mmap.cc b/apt-pkg/contrib/mmap.cc
index 69fb61fca..19381ae47 100644
--- a/apt-pkg/contrib/mmap.cc
+++ b/apt-pkg/contrib/mmap.cc
@@ -106,7 +106,7 @@ bool MMap::Map(FileFd &Fd)
/* */
bool MMap::Close(bool DoSync)
{
- if ((Flags & UnMapped) == UnMapped || Base == 0 || iSize == 0)
+ if ((Flags & UnMapped) == UnMapped || validData() == false || iSize == 0)
return true;
if (DoSync == true)
@@ -237,11 +237,19 @@ DynamicMMap::DynamicMMap(unsigned long Flags,unsigned long const &WorkSpace,
if ((this->Flags & Fallback) != Fallback) {
// Set the permissions.
int Prot = PROT_READ;
+#ifdef MAP_ANONYMOUS
int Map = MAP_PRIVATE | MAP_ANONYMOUS;
+#else
+ int Map = MAP_PRIVATE | MAP_ANON;
+#endif
if ((this->Flags & ReadOnly) != ReadOnly)
Prot |= PROT_WRITE;
if ((this->Flags & Public) == Public)
+#ifdef MAP_ANONYMOUS
Map = MAP_SHARED | MAP_ANONYMOUS;
+#else
+ Map = MAP_SHARED | MAP_ANON;
+#endif
// use anonymous mmap() to get the memory
Base = (unsigned char*) mmap(0, WorkSpace, Prot, Map, -1, 0);
@@ -266,6 +274,8 @@ DynamicMMap::~DynamicMMap()
{
if (Fd == 0)
{
+ if (validData() == false)
+ return;
#ifdef _POSIX_MAPPED_FILES
munmap(Base, WorkSpace);
#else
diff --git a/apt-pkg/contrib/mmap.h b/apt-pkg/contrib/mmap.h
index 5ca951204..2bf2c1540 100644
--- a/apt-pkg/contrib/mmap.h
+++ b/apt-pkg/contrib/mmap.h
@@ -61,6 +61,8 @@ class MMap
inline operator void *() {return Base;};
inline void *Data() {return Base;};
inline unsigned long Size() {return iSize;};
+ inline void AddSize(unsigned long const size) {iSize += size;};
+ inline bool validData() const { return Base != (void *)-1 && Base != 0; };
// File manipulators
bool Sync();
diff --git a/apt-pkg/contrib/netrc.cc b/apt-pkg/contrib/netrc.cc
index d8027fc24..34f472ee1 100644
--- a/apt-pkg/contrib/netrc.cc
+++ b/apt-pkg/contrib/netrc.cc
@@ -160,10 +160,10 @@ void maybe_add_auth (URI &Uri, string NetRCFile)
{
char login[64] = "";
char password[64] = "";
- char *netrcfile = strdupa (NetRCFile.c_str ());
+ char *netrcfile = strdup(NetRCFile.c_str());
// first check for a generic host based netrc entry
- char *host = strdupa (Uri.Host.c_str ());
+ char *host = strdup(Uri.Host.c_str());
if (host && parsenetrc (host, login, password, netrcfile) == 0)
{
if (_config->FindB("Debug::Acquire::netrc", false) == true)
@@ -173,13 +173,16 @@ void maybe_add_auth (URI &Uri, string NetRCFile)
<< std::endl;
Uri.User = string (login);
Uri.Password = string (password);
+ free(netrcfile);
+ free(host);
return;
}
+ free(host);
// if host did not work, try Host+Path next, this will trigger
// a lookup uri.startswith(host) in the netrc file parser (because
// of the "/"
- char *hostpath = strdupa (string(Uri.Host+Uri.Path).c_str ());
+ char *hostpath = strdup(string(Uri.Host+Uri.Path).c_str());
if (hostpath && parsenetrc (hostpath, login, password, netrcfile) == 0)
{
if (_config->FindB("Debug::Acquire::netrc", false) == true)
@@ -189,8 +192,9 @@ void maybe_add_auth (URI &Uri, string NetRCFile)
<< std::endl;
Uri.User = string (login);
Uri.Password = string (password);
- return;
}
+ free(netrcfile);
+ free(hostpath);
}
}
}
diff --git a/apt-pkg/contrib/progress.cc b/apt-pkg/contrib/progress.cc
index 45e81edcb..84ee4c124 100644
--- a/apt-pkg/contrib/progress.cc
+++ b/apt-pkg/contrib/progress.cc
@@ -65,27 +65,18 @@ void OpProgress::OverallProgress(unsigned long Current, unsigned long Total,
// OpProgress::SubProgress - Set the sub progress state /*{{{*/
// ---------------------------------------------------------------------
/* */
-void OpProgress::SubProgress(unsigned long SubTotal,const string &Op)
+void OpProgress::SubProgress(unsigned long SubTotal,const string &Op,
+ float const Percent)
{
this->SubTotal = SubTotal;
- SubOp = Op;
- if (Total == 0)
- Percent = 0;
+ if (Op.empty() == false)
+ SubOp = Op;
+ if (Total == 0 || Percent == 0)
+ this->Percent = 0;
+ else if (Percent != -1)
+ this->Percent = this->Current += (Size*Percent)/SubTotal;
else
- Percent = Current*100.0/Total;
- Update();
-}
- /*}}}*/
-// OpProgress::SubProgress - Set the sub progress state /*{{{*/
-// ---------------------------------------------------------------------
-/* */
-void OpProgress::SubProgress(unsigned long SubTotal)
-{
- this->SubTotal = SubTotal;
- if (Total == 0)
- Percent = 0;
- else
- Percent = Current*100.0/Total;
+ this->Percent = Current*100.0/Total;
Update();
}
/*}}}*/
diff --git a/apt-pkg/contrib/progress.h b/apt-pkg/contrib/progress.h
index 7dd004f7e..3a914d17f 100644
--- a/apt-pkg/contrib/progress.h
+++ b/apt-pkg/contrib/progress.h
@@ -55,8 +55,7 @@ class OpProgress
public:
void Progress(unsigned long Current);
- void SubProgress(unsigned long SubTotal);
- void SubProgress(unsigned long SubTotal,const string &Op);
+ void SubProgress(unsigned long SubTotal, const string &Op = "", float const Percent = -1);
void OverallProgress(unsigned long Current,unsigned long Total,
unsigned long Size,const string &Op);
virtual void Done() {};
diff --git a/apt-pkg/contrib/strutl.cc b/apt-pkg/contrib/strutl.cc
index 2e2bb5ebc..072dda3ac 100644
--- a/apt-pkg/contrib/strutl.cc
+++ b/apt-pkg/contrib/strutl.cc
@@ -692,14 +692,16 @@ int StringToBool(const string &Text,int Default)
year 2000 complient and timezone neutral */
string TimeRFC1123(time_t Date)
{
- struct tm Conv = *gmtime(&Date);
- char Buf[300];
+ struct tm Conv;
+ if (gmtime_r(&Date, &Conv) == NULL)
+ return "";
+ char Buf[300];
const char *Day[] = {"Sun","Mon","Tue","Wed","Thu","Fri","Sat"};
const char *Month[] = {"Jan","Feb","Mar","Apr","May","Jun","Jul",
"Aug","Sep","Oct","Nov","Dec"};
- sprintf(Buf,"%s, %02i %s %i %02i:%02i:%02i GMT",Day[Conv.tm_wday],
+ snprintf(Buf, sizeof(Buf), "%s, %02i %s %i %02i:%02i:%02i GMT",Day[Conv.tm_wday],
Conv.tm_mday,Month[Conv.tm_mon],Conv.tm_year+1900,Conv.tm_hour,
Conv.tm_min,Conv.tm_sec);
return Buf;
diff --git a/apt-pkg/deb/debindexfile.cc b/apt-pkg/deb/debindexfile.cc
index 9961b5ae4..c9e7f1176 100644
--- a/apt-pkg/deb/debindexfile.cc
+++ b/apt-pkg/deb/debindexfile.cc
@@ -66,7 +66,10 @@ pkgSrcRecords::Parser *debSourcesIndex::CreateSrcParser() const
string SourcesURI = _config->FindDir("Dir::State::lists") +
URItoFileName(IndexURI("Sources"));
string SourcesURIgzip = SourcesURI + ".gz";
- if (!FileExists(SourcesURI) && FileExists(SourcesURIgzip))
+
+ if (!FileExists(SourcesURI) && !FileExists(SourcesURIgzip))
+ return NULL;
+ else if (!FileExists(SourcesURI) && FileExists(SourcesURIgzip))
SourcesURI = SourcesURIgzip;
return new debSrcRecordParser(SourcesURI,this);
@@ -420,12 +423,10 @@ string debTranslationsIndex::IndexURI(const char *Type) const
/* */
bool debTranslationsIndex::GetIndexes(pkgAcquire *Owner) const
{
- if (TranslationsAvailable()) {
- string const TranslationFile = string("Translation-").append(Language);
- new pkgAcqIndexTrans(Owner, IndexURI(Language),
- Info(TranslationFile.c_str()),
- TranslationFile);
- }
+ string const TranslationFile = string("Translation-").append(Language);
+ new pkgAcqIndexTrans(Owner, IndexURI(Language),
+ Info(TranslationFile.c_str()),
+ TranslationFile);
return true;
}
@@ -465,9 +466,6 @@ string debTranslationsIndex::Info(const char *Type) const
/*}}}*/
bool debTranslationsIndex::HasPackages() const /*{{{*/
{
- if(!TranslationsAvailable())
- return false;
-
return FileExists(IndexFile(Language));
}
/*}}}*/
@@ -507,7 +505,7 @@ bool debTranslationsIndex::Merge(pkgCacheGenerator &Gen,OpProgress *Prog) const
{
// Check the translation file, if in use
string TranslationFile = IndexFile(Language);
- if (TranslationsAvailable() && FileExists(TranslationFile))
+ if (FileExists(TranslationFile))
{
FileFd Trans(TranslationFile,FileFd::ReadOnlyGzip);
debListParser TransParser(&Trans);
diff --git a/apt-pkg/deb/debindexfile.h b/apt-pkg/deb/debindexfile.h
index b5085992d..678c22473 100644
--- a/apt-pkg/deb/debindexfile.h
+++ b/apt-pkg/deb/debindexfile.h
@@ -22,8 +22,12 @@
class debStatusIndex : public pkgIndexFile
{
+ /** \brief dpointer placeholder (for later in case we need it) */
+ void *d;
+
+ protected:
string File;
-
+
public:
virtual const Type *GetType() const;
@@ -36,13 +40,18 @@ class debStatusIndex : public pkgIndexFile
virtual bool HasPackages() const {return true;};
virtual unsigned long Size() const;
virtual bool Merge(pkgCacheGenerator &Gen,OpProgress *Prog) const;
+ bool Merge(pkgCacheGenerator &Gen,OpProgress *Prog, unsigned long const Flag) const;
virtual pkgCache::PkgFileIterator FindInCache(pkgCache &Cache) const;
debStatusIndex(string File);
+ virtual ~debStatusIndex() {};
};
class debPackagesIndex : public pkgIndexFile
{
+ /** \brief dpointer placeholder (for later in case we need it) */
+ void *d;
+
string URI;
string Dist;
string Section;
@@ -72,10 +81,14 @@ class debPackagesIndex : public pkgIndexFile
debPackagesIndex(string const &URI, string const &Dist, string const &Section,
bool const &Trusted, string const &Arch = "native");
+ virtual ~debPackagesIndex() {};
};
class debTranslationsIndex : public pkgIndexFile
{
+ /** \brief dpointer placeholder (for later in case we need it) */
+ void *d;
+
string URI;
string Dist;
string Section;
@@ -103,10 +116,14 @@ class debTranslationsIndex : public pkgIndexFile
virtual pkgCache::PkgFileIterator FindInCache(pkgCache &Cache) const;
debTranslationsIndex(string URI,string Dist,string Section, char const * const Language);
+ virtual ~debTranslationsIndex() {};
};
class debSourcesIndex : public pkgIndexFile
{
+ /** \brief dpointer placeholder (for later in case we need it) */
+ void *d;
+
string URI;
string Dist;
string Section;
@@ -136,6 +153,7 @@ class debSourcesIndex : public pkgIndexFile
virtual unsigned long Size() const;
debSourcesIndex(string URI,string Dist,string Section,bool Trusted);
+ virtual ~debSourcesIndex() {};
};
#endif
diff --git a/apt-pkg/deb/deblistparser.cc b/apt-pkg/deb/deblistparser.cc
index 9201e6a54..b708296d3 100644
--- a/apt-pkg/deb/deblistparser.cc
+++ b/apt-pkg/deb/deblistparser.cc
@@ -67,23 +67,12 @@ string debListParser::Package() {
/*}}}*/
// ListParser::Architecture - Return the package arch /*{{{*/
// ---------------------------------------------------------------------
-/* This will return the Architecture of the package this section describes
- Note that architecture "all" packages will get the architecture of the
- Packages file parsed here. */
+/* This will return the Architecture of the package this section describes */
string debListParser::Architecture() {
- string const Result = Section.FindS("Architecture");
- if (Result.empty() == true || Result == "all")
- {
- if (Arch.empty() == true)
- /* FIXME: this is a problem for installed arch all
- packages as we don't know from which arch this
- package was installed - and therefore which
- dependency this package resolves. */
- return _config->Find("APT::Architecture");
- else
- return Arch;
- }
- return Result;
+ std::string const Arch = Section.FindS("Architecture");
+ if (Arch.empty() == true)
+ return _config->Find("APT::Architecture");
+ return Arch;
}
/*}}}*/
// ListParser::ArchitectureAll /*{{{*/
@@ -112,29 +101,35 @@ bool debListParser::NewVersion(pkgCache::VerIterator &Ver)
Ver->Section = UniqFindTagWrite("Section");
// Parse multi-arch
- if (Section.FindS("Architecture") == "all")
- /* Arch all packages can't have a Multi-Arch field,
- but we need a special treatment for them nonetheless */
- Ver->MultiArch = pkgCache::Version::All;
- else
- {
- string const MultiArch = Section.FindS("Multi-Arch");
- if (MultiArch.empty() == true)
- Ver->MultiArch = pkgCache::Version::None;
- else if (MultiArch == "same")
- Ver->MultiArch = pkgCache::Version::Same;
- else if (MultiArch == "foreign")
- Ver->MultiArch = pkgCache::Version::Foreign;
- else if (MultiArch == "allowed")
- Ver->MultiArch = pkgCache::Version::Allowed;
- else
+ string const MultiArch = Section.FindS("Multi-Arch");
+ if (MultiArch.empty() == true)
+ Ver->MultiArch = pkgCache::Version::None;
+ else if (MultiArch == "same") {
+ // Parse multi-arch
+ if (ArchitectureAll() == true)
{
- _error->Warning("Unknown Multi-Arch type »%s« for package »%s«",
- MultiArch.c_str(), Section.FindS("Package").c_str());
+ /* Arch all packages can't be Multi-Arch: same */
+ _error->Warning("Architecture: all package '%s' can't be Multi-Arch: same",
+ Section.FindS("Package").c_str());
Ver->MultiArch = pkgCache::Version::None;
}
+ else
+ Ver->MultiArch = pkgCache::Version::Same;
+ }
+ else if (MultiArch == "foreign")
+ Ver->MultiArch = pkgCache::Version::Foreign;
+ else if (MultiArch == "allowed")
+ Ver->MultiArch = pkgCache::Version::Allowed;
+ else
+ {
+ _error->Warning("Unknown Multi-Arch type '%s' for package '%s'",
+ MultiArch.c_str(), Section.FindS("Package").c_str());
+ Ver->MultiArch = pkgCache::Version::None;
}
+ if (ArchitectureAll() == true)
+ Ver->MultiArch |= pkgCache::Version::All;
+
// Archive Size
Ver->Size = Section.FindULL("Size");
// Unpacked Size (in K)
@@ -150,24 +145,6 @@ bool debListParser::NewVersion(pkgCache::VerIterator &Ver)
Ver->Priority = pkgCache::State::Extra;
}
- if (Ver->MultiArch == pkgCache::Version::All)
- {
- /* We maintain a "pseudo" arch=all package for architecture all versions
- on which these versions can depend on. This pseudo package is many used
- for downloading/installing: The other pseudo-packages will degenerate
- to a NOP in the download/install step - this package will ensure that
- it is downloaded only one time and installed only one time -- even if
- the architecture bound versions coming in and out on regular basis. */
- if (strcmp(Ver.Arch(true),"all") == 0)
- return true;
- else if (MultiArchEnabled == true)
- {
- // our pseudo packages have no size to not confuse the fetcher
- Ver->Size = 0;
- Ver->InstalledSize = 0;
- }
- }
-
if (ParseDepends(Ver,"Depends",pkgCache::Dep::Depends) == false)
return false;
if (ParseDepends(Ver,"Pre-Depends",pkgCache::Dep::PreDepends) == false)
@@ -219,7 +196,7 @@ string debListParser::DescriptionLanguage()
if (Section.FindS("Description").empty() == false)
return "";
- std::vector<string> const lang = APT::Configuration::getLanguages();
+ std::vector<string> const lang = APT::Configuration::getLanguages(true);
for (std::vector<string>::const_iterator l = lang.begin();
l != lang.end(); l++)
if (Section.FindS(string("Description-").append(*l).c_str()).empty() == false)
@@ -302,18 +279,18 @@ unsigned short debListParser::VersionHash()
/* Strip out any spaces from the text, this undoes dpkgs reformatting
of certain fields. dpkg also has the rather interesting notion of
reformatting depends operators < -> <= */
- char *I = S;
+ char *J = S;
for (; Start != End; Start++)
{
if (isspace(*Start) == 0)
- *I++ = tolower_ascii(*Start);
+ *J++ = tolower_ascii(*Start);
if (*Start == '<' && Start[1] != '<' && Start[1] != '=')
- *I++ = '=';
+ *J++ = '=';
if (*Start == '>' && Start[1] != '>' && Start[1] != '=')
- *I++ = '=';
+ *J++ = '=';
}
- Result = AddCRC16(Result,S,I - S);
+ Result = AddCRC16(Result,S,J - S);
}
return Result;
@@ -505,7 +482,7 @@ const char *debListParser::ParseDepends(const char *Start,const char *Stop,
// Parse off the package name
const char *I = Start;
for (;I != Stop && isspace(*I) == 0 && *I != '(' && *I != ')' &&
- *I != ',' && *I != '|'; I++);
+ *I != ',' && *I != '|' && *I != '[' && *I != ']'; I++);
// Malformed, no '('
if (I != Stop && *I == ')')
@@ -644,13 +621,13 @@ bool debListParser::ParseDepends(pkgCache::VerIterator &Ver,
return true;
string Package;
- string const pkgArch = Ver.Arch(true);
+ string const pkgArch = Ver.Arch();
string Version;
unsigned int Op;
while (1)
{
- Start = ParseDepends(Start,Stop,Package,Version,Op);
+ Start = ParseDepends(Start,Stop,Package,Version,Op,false,!MultiArchEnabled);
if (Start == 0)
return _error->Error("Problem parsing dependency %s",Tag);
@@ -683,7 +660,7 @@ bool debListParser::ParseProvides(pkgCache::VerIterator &Ver)
{
string Package;
string Version;
- string const Arch = Ver.Arch(true);
+ string const Arch = Ver.Arch();
unsigned int Op;
while (1)
@@ -703,27 +680,28 @@ bool debListParser::ParseProvides(pkgCache::VerIterator &Ver)
}
}
- if (Ver->MultiArch == pkgCache::Version::Allowed)
+ if (MultiArchEnabled == false)
+ return true;
+ else if ((Ver->MultiArch & pkgCache::Version::Allowed) == pkgCache::Version::Allowed)
{
string const Package = string(Ver.ParentPkg().Name()).append(":").append("any");
- NewProvides(Ver, Package, "any", Ver.VerStr());
+ return NewProvidesAllArch(Ver, Package, Ver.VerStr());
}
+ else if ((Ver->MultiArch & pkgCache::Version::Foreign) == pkgCache::Version::Foreign)
+ return NewProvidesAllArch(Ver, Ver.ParentPkg().Name(), Ver.VerStr());
- if (Ver->MultiArch != pkgCache::Version::Foreign)
- return true;
-
- if (MultiArchEnabled == false)
- return true;
-
- string const Package = Ver.ParentPkg().Name();
- string const Version = Ver.VerStr();
+ return true;
+}
+ /*}}}*/
+// ListParser::NewProvides - add provides for all architectures /*{{{*/
+bool debListParser::NewProvidesAllArch(pkgCache::VerIterator &Ver, string const &Package,
+ string const &Version) {
for (std::vector<string>::const_iterator a = Architectures.begin();
a != Architectures.end(); ++a)
{
if (NewProvides(Ver, Package, *a, Version) == false)
return false;
}
-
return true;
}
/*}}}*/
@@ -768,7 +746,7 @@ bool debListParser::Step()
if (Architecture == Arch)
return true;
- if (Architecture == "all")
+ if (Architecture == "all" && Arch == _config->Find("APT::Architecture"))
return true;
}
diff --git a/apt-pkg/deb/deblistparser.h b/apt-pkg/deb/deblistparser.h
index 4bc1bd93c..41d712fbf 100644
--- a/apt-pkg/deb/deblistparser.h
+++ b/apt-pkg/deb/deblistparser.h
@@ -25,9 +25,12 @@ class debListParser : public pkgCacheGenerator::ListParser
const char *Str;
unsigned char Val;
};
-
+
private:
-
+ /** \brief dpointer placeholder (for later in case we need it) */
+ void *d;
+
+ protected:
pkgTagFile Tags;
pkgTagSection Section;
unsigned long iOffset;
@@ -36,10 +39,11 @@ class debListParser : public pkgCacheGenerator::ListParser
bool MultiArchEnabled;
unsigned long UniqFindTagWrite(const char *Tag);
- bool ParseStatus(pkgCache::PkgIterator &Pkg,pkgCache::VerIterator &Ver);
+ virtual bool ParseStatus(pkgCache::PkgIterator &Pkg,pkgCache::VerIterator &Ver);
bool ParseDepends(pkgCache::VerIterator &Ver,const char *Tag,
unsigned int Type);
bool ParseProvides(pkgCache::VerIterator &Ver);
+ bool NewProvidesAllArch(pkgCache::VerIterator &Ver, string const &Package, string const &Version);
static bool GrabWord(string Word,WordList *List,unsigned char &Out);
public:
@@ -69,10 +73,11 @@ class debListParser : public pkgCacheGenerator::ListParser
static const char *ParseDepends(const char *Start,const char *Stop,
string &Package,string &Ver,unsigned int &Op,
bool const &ParseArchFlags = false,
- bool const &StripMultiArch = false);
+ bool const &StripMultiArch = true);
static const char *ConvertRelation(const char *I,unsigned int &Op);
debListParser(FileFd *File, string const &Arch = "");
+ virtual ~debListParser() {};
};
#endif
diff --git a/apt-pkg/deb/debmetaindex.cc b/apt-pkg/deb/debmetaindex.cc
index a6edab6b9..a91cc34e9 100644
--- a/apt-pkg/deb/debmetaindex.cc
+++ b/apt-pkg/deb/debmetaindex.cc
@@ -195,11 +195,14 @@ vector <struct IndexTarget *>* debReleaseIndex::ComputeIndexTargets() const {
}
}
+ std::vector<std::string> const lang = APT::Configuration::getLanguages(true);
+ 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] == '/') {
- std::vector<std::string> const lang = APT::Configuration::getLanguages(true);
for (std::set<std::string>::const_iterator s = sections.begin();
s != sections.end(); ++s) {
for (std::vector<std::string>::const_iterator l = lang.begin();
diff --git a/apt-pkg/deb/debmetaindex.h b/apt-pkg/deb/debmetaindex.h
index 1561c6e00..0aaf7f14a 100644
--- a/apt-pkg/deb/debmetaindex.h
+++ b/apt-pkg/deb/debmetaindex.h
@@ -19,12 +19,14 @@ class debReleaseIndex : public metaIndex {
};
private:
+ /** \brief dpointer placeholder (for later in case we need it) */
+ void *d;
std::map<string, vector<debSectionEntry const*> > ArchEntries;
public:
debReleaseIndex(string const &URI, string const &Dist);
- ~debReleaseIndex();
+ virtual ~debReleaseIndex();
virtual string ArchiveURI(string const &File) const {return URI + File;};
virtual bool GetIndexes(pkgAcquire *Owner, bool const &GetAll=false) const;
diff --git a/apt-pkg/deb/debrecords.h b/apt-pkg/deb/debrecords.h
index 05159ea1e..9692ac94c 100644
--- a/apt-pkg/deb/debrecords.h
+++ b/apt-pkg/deb/debrecords.h
@@ -20,6 +20,9 @@
class debRecordParser : public pkgRecords::Parser
{
+ /** \brief dpointer placeholder (for later in case we need it) */
+ void *d;
+
FileFd File;
pkgTagFile Tags;
pkgTagSection Section;
@@ -50,6 +53,7 @@ class debRecordParser : public pkgRecords::Parser
virtual void GetRec(const char *&Start,const char *&Stop);
debRecordParser(string FileName,pkgCache &Cache);
+ virtual ~debRecordParser() {};
};
#endif
diff --git a/apt-pkg/deb/debsrcrecords.cc b/apt-pkg/deb/debsrcrecords.cc
index 21336e1af..749305005 100644
--- a/apt-pkg/deb/debsrcrecords.cc
+++ b/apt-pkg/deb/debsrcrecords.cc
@@ -14,6 +14,7 @@
#include <apt-pkg/error.h>
#include <apt-pkg/strutl.h>
#include <apt-pkg/configuration.h>
+#include <apt-pkg/aptconfiguration.h>
using std::max;
/*}}}*/
@@ -111,7 +112,9 @@ bool debSrcRecordParser::Files(vector<pkgSrcRecords::File> &List)
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)
@@ -144,7 +147,8 @@ bool debSrcRecordParser::Files(vector<pkgSrcRecords::File> &List)
}
F.Type = string(F.Path,Tmp+1,Pos-Tmp);
- if (F.Type == "gz" || F.Type == "bz2" || F.Type == "lzma" || F.Type == "tar")
+ if (std::find(compExts.begin(), compExts.end(), std::string(".").append(F.Type)) != compExts.end() ||
+ F.Type == "tar")
{
Pos = Tmp-1;
continue;
diff --git a/apt-pkg/deb/debsrcrecords.h b/apt-pkg/deb/debsrcrecords.h
index 905264daa..aa859b0e6 100644
--- a/apt-pkg/deb/debsrcrecords.h
+++ b/apt-pkg/deb/debsrcrecords.h
@@ -18,6 +18,9 @@
class debSrcRecordParser : public pkgSrcRecords::Parser
{
+ /** \brief dpointer placeholder (for later in case we need it) */
+ void *d;
+
FileFd Fd;
pkgTagFile Tags;
pkgTagSection Sect;
@@ -50,7 +53,7 @@ class debSrcRecordParser : public pkgSrcRecords::Parser
debSrcRecordParser(string const &File,pkgIndexFile const *Index)
: Parser(Index), Fd(File,FileFd::ReadOnlyGzip), Tags(&Fd,102400),
Buffer(0), BufSize(0) {}
- ~debSrcRecordParser();
+ virtual ~debSrcRecordParser();
};
#endif
diff --git a/apt-pkg/deb/debsystem.cc b/apt-pkg/deb/debsystem.cc
index 8619822df..7644bc66b 100644
--- a/apt-pkg/deb/debsystem.cc
+++ b/apt-pkg/deb/debsystem.cc
@@ -26,15 +26,24 @@
debSystem debSys;
+class debSystemPrivate {
+public:
+ debSystemPrivate() : LockFD(-1), LockCount(0), StatusFile(0)
+ {
+ }
+ // For locking support
+ int LockFD;
+ unsigned LockCount;
+
+ debStatusIndex *StatusFile;
+};
+
// System::debSystem - Constructor /*{{{*/
// ---------------------------------------------------------------------
/* */
debSystem::debSystem()
{
- LockFD = -1;
- LockCount = 0;
- StatusFile = 0;
-
+ d = new debSystemPrivate();
Label = "Debian dpkg interface";
VS = &debVS;
}
@@ -44,7 +53,8 @@ debSystem::debSystem()
/* */
debSystem::~debSystem()
{
- delete StatusFile;
+ delete d->StatusFile;
+ delete d;
}
/*}}}*/
// System::Lock - Get the lock /*{{{*/
@@ -54,16 +64,16 @@ debSystem::~debSystem()
bool debSystem::Lock()
{
// Disable file locking
- if (_config->FindB("Debug::NoLocking",false) == true || LockCount > 1)
+ if (_config->FindB("Debug::NoLocking",false) == true || d->LockCount > 1)
{
- LockCount++;
+ d->LockCount++;
return true;
}
// Create the lockfile
string AdminDir = flNotFile(_config->Find("Dir::State::status"));
- LockFD = GetLock(AdminDir + "lock");
- if (LockFD == -1)
+ d->LockFD = GetLock(AdminDir + "lock");
+ if (d->LockFD == -1)
{
if (errno == EACCES || errno == EAGAIN)
return _error->Error(_("Unable to lock the administration directory (%s), "
@@ -76,8 +86,8 @@ bool debSystem::Lock()
// See if we need to abort with a dirty journal
if (CheckUpdates() == true)
{
- close(LockFD);
- LockFD = -1;
+ close(d->LockFD);
+ d->LockFD = -1;
const char *cmd;
if (getenv("SUDO_USER") != NULL)
cmd = "sudo dpkg --configure -a";
@@ -89,7 +99,7 @@ bool debSystem::Lock()
"run '%s' to correct the problem. "), cmd);
}
- LockCount++;
+ d->LockCount++;
return true;
}
@@ -99,15 +109,15 @@ bool debSystem::Lock()
/* */
bool debSystem::UnLock(bool NoErrors)
{
- if (LockCount == 0 && NoErrors == true)
+ if (d->LockCount == 0 && NoErrors == true)
return false;
- if (LockCount < 1)
+ if (d->LockCount < 1)
return _error->Error(_("Not locked"));
- if (--LockCount == 0)
+ if (--d->LockCount == 0)
{
- close(LockFD);
- LockCount = 0;
+ close(d->LockFD);
+ d->LockCount = 0;
}
return true;
@@ -168,9 +178,9 @@ bool debSystem::Initialize(Configuration &Cnf)
Cnf.CndSet("Dir::State::status","/var/lib/dpkg/status");
Cnf.CndSet("Dir::Bin::dpkg","/usr/bin/dpkg");
- if (StatusFile) {
- delete StatusFile;
- StatusFile = 0;
+ if (d->StatusFile) {
+ delete d->StatusFile;
+ d->StatusFile = 0;
}
return true;
@@ -208,9 +218,9 @@ signed debSystem::Score(Configuration const &Cnf)
/* */
bool debSystem::AddStatusFiles(vector<pkgIndexFile *> &List)
{
- if (StatusFile == 0)
- StatusFile = new debStatusIndex(_config->FindFile("Dir::State::status"));
- List.push_back(StatusFile);
+ if (d->StatusFile == 0)
+ d->StatusFile = new debStatusIndex(_config->FindFile("Dir::State::status"));
+ List.push_back(d->StatusFile);
return true;
}
/*}}}*/
@@ -220,11 +230,11 @@ bool debSystem::AddStatusFiles(vector<pkgIndexFile *> &List)
bool debSystem::FindIndex(pkgCache::PkgFileIterator File,
pkgIndexFile *&Found) const
{
- if (StatusFile == 0)
+ if (d->StatusFile == 0)
return false;
- if (StatusFile->FindInCache(*File.Cache()) == File)
+ if (d->StatusFile->FindInCache(*File.Cache()) == File)
{
- Found = StatusFile;
+ Found = d->StatusFile;
return true;
}
diff --git a/apt-pkg/deb/debsystem.h b/apt-pkg/deb/debsystem.h
index 5f9995e5d..232155256 100644
--- a/apt-pkg/deb/debsystem.h
+++ b/apt-pkg/deb/debsystem.h
@@ -12,16 +12,15 @@
#include <apt-pkg/pkgsystem.h>
+class debSystemPrivate;
+
class debStatusIndex;
class debSystem : public pkgSystem
{
- // For locking support
- int LockFD;
- unsigned LockCount;
+ // private d-pointer
+ debSystemPrivate *d;
bool CheckUpdates();
-
- debStatusIndex *StatusFile;
-
+
public:
virtual bool Lock();
@@ -35,7 +34,7 @@ class debSystem : public pkgSystem
pkgIndexFile *&Found) const;
debSystem();
- ~debSystem();
+ virtual ~debSystem();
};
extern debSystem debSys;
diff --git a/apt-pkg/deb/dpkgpm.cc b/apt-pkg/deb/dpkgpm.cc
index 7d0d34a46..019b72bb8 100644
--- a/apt-pkg/deb/dpkgpm.cc
+++ b/apt-pkg/deb/dpkgpm.cc
@@ -14,8 +14,8 @@
#include <apt-pkg/depcache.h>
#include <apt-pkg/pkgrecords.h>
#include <apt-pkg/strutl.h>
-#include <apti18n.h>
#include <apt-pkg/fileutl.h>
+#include <apt-pkg/cachefile.h>
#include <unistd.h>
#include <stdlib.h>
@@ -32,6 +32,8 @@
#include <algorithm>
#include <sstream>
#include <map>
+#include <pwd.h>
+#include <grp.h>
#include <termios.h>
#include <unistd.h>
@@ -44,6 +46,21 @@
using namespace std;
+class pkgDPkgPMPrivate
+{
+public:
+ pkgDPkgPMPrivate() : dpkgbuf_pos(0), term_out(NULL), history_out(NULL)
+ {
+ }
+ bool stdin_is_dev_null;
+ // the buffer we use for the dpkg status-fd reading
+ char dpkgbuf[1024];
+ int dpkgbuf_pos;
+ FILE *term_out;
+ FILE *history_out;
+ string dpkg_error;
+};
+
namespace
{
// Maps the dpkg "processing" info to human readable names. Entry 0
@@ -108,9 +125,9 @@ ionice(int PID)
// ---------------------------------------------------------------------
/* */
pkgDPkgPM::pkgDPkgPM(pkgDepCache *Cache)
- : pkgPackageManager(Cache), dpkgbuf_pos(0),
- term_out(NULL), history_out(NULL), PackagesDone(0), PackagesTotal(0)
+ : pkgPackageManager(Cache), PackagesDone(0), PackagesTotal(0)
{
+ d = new pkgDPkgPMPrivate();
}
/*}}}*/
// DPkgPM::pkgDPkgPM - Destructor /*{{{*/
@@ -118,6 +135,7 @@ pkgDPkgPM::pkgDPkgPM(pkgDepCache *Cache)
/* */
pkgDPkgPM::~pkgDPkgPM()
{
+ delete d;
}
/*}}}*/
// DPkgPM::Install - Install a package /*{{{*/
@@ -308,6 +326,15 @@ bool pkgDPkgPM::RunScriptsWithPkgs(const char *Cnf)
SetCloseExec(STDIN_FILENO,false);
SetCloseExec(STDERR_FILENO,false);
+ if (_config->FindDir("DPkg::Chroot-Directory","/") != "/")
+ {
+ std::cerr << "Chrooting into "
+ << _config->FindDir("DPkg::Chroot-Directory")
+ << std::endl;
+ if (chroot(_config->FindDir("DPkg::Chroot-Directory","/").c_str()) != 0)
+ _exit(100);
+ }
+
const char *Args[4];
Args[0] = "/bin/sh";
Args[1] = "-c";
@@ -365,7 +392,7 @@ void pkgDPkgPM::DoStdin(int master)
if (len)
write(master, input_buf, len);
else
- stdin_is_dev_null = true;
+ d->stdin_is_dev_null = true;
}
/*}}}*/
// DPkgPM::DoTerminalPty - Read the terminal pty and write log /*{{{*/
@@ -382,15 +409,16 @@ void pkgDPkgPM::DoTerminalPty(int master)
{
// this happens when the child is about to exit, we
// give it time to actually exit, otherwise we run
- // into a race
- usleep(500000);
+ // into a race so we sleep for half a second.
+ struct timespec sleepfor = { 0, 500000000 };
+ nanosleep(&sleepfor, NULL);
return;
}
if(len <= 0)
return;
write(1, term_buf, len);
- if(term_out)
- fwrite(term_buf, len, sizeof(char), term_out);
+ if(d->term_out)
+ fwrite(term_buf, len, sizeof(char), d->term_out);
}
/*}}}*/
// DPkgPM::ProcessDpkgStatusBuf /*{{{*/
@@ -594,14 +622,14 @@ void pkgDPkgPM::DoDpkgStatusFd(int statusfd, int OutStatusFd)
char *p, *q;
int len;
- len=read(statusfd, &dpkgbuf[dpkgbuf_pos], sizeof(dpkgbuf)-dpkgbuf_pos);
- dpkgbuf_pos += len;
+ len=read(statusfd, &d->dpkgbuf[d->dpkgbuf_pos], sizeof(d->dpkgbuf)-d->dpkgbuf_pos);
+ d->dpkgbuf_pos += len;
if(len <= 0)
return;
// process line by line if we have a buffer
- p = q = dpkgbuf;
- while((q=(char*)memchr(p, '\n', dpkgbuf+dpkgbuf_pos-p)) != NULL)
+ p = q = d->dpkgbuf;
+ while((q=(char*)memchr(p, '\n', d->dpkgbuf+d->dpkgbuf_pos-p)) != NULL)
{
*q = 0;
ProcessDpkgStatusLine(OutStatusFd, p);
@@ -609,8 +637,8 @@ void pkgDPkgPM::DoDpkgStatusFd(int statusfd, int OutStatusFd)
}
// now move the unprocessed bits (after the final \n that is now a 0x0)
- // to the start and update dpkgbuf_pos
- p = (char*)memrchr(dpkgbuf, 0, dpkgbuf_pos);
+ // to the start and update d->dpkgbuf_pos
+ p = (char*)memrchr(d->dpkgbuf, 0, d->dpkgbuf_pos);
if(p == NULL)
return;
@@ -618,8 +646,8 @@ void pkgDPkgPM::DoDpkgStatusFd(int statusfd, int OutStatusFd)
p++;
// move the unprocessed tail to the start and update pos
- memmove(dpkgbuf, p, p-dpkgbuf);
- dpkgbuf_pos = dpkgbuf+dpkgbuf_pos-p;
+ memmove(d->dpkgbuf, p, p-d->dpkgbuf);
+ d->dpkgbuf_pos = d->dpkgbuf+d->dpkgbuf_pos-p;
}
/*}}}*/
// DPkgPM::WriteHistoryTag /*{{{*/
@@ -631,7 +659,7 @@ void pkgDPkgPM::WriteHistoryTag(string const &tag, string value)
// poor mans rstrip(", ")
if (value[length-2] == ',' && value[length-1] == ' ')
value.erase(length - 2, 2);
- fprintf(history_out, "%s: %s\n", tag.c_str(), value.c_str());
+ fprintf(d->history_out, "%s: %s\n", tag.c_str(), value.c_str());
} /*}}}*/
// DPkgPM::OpenLog /*{{{*/
bool pkgDPkgPM::OpenLog()
@@ -652,13 +680,19 @@ bool pkgDPkgPM::OpenLog()
_config->Find("Dir::Log::Terminal"));
if (!logfile_name.empty())
{
- term_out = fopen(logfile_name.c_str(),"a");
- if (term_out == NULL)
+ d->term_out = fopen(logfile_name.c_str(),"a");
+ if (d->term_out == NULL)
return _error->WarningE("OpenLog", _("Could not open file '%s'"), logfile_name.c_str());
- setvbuf(term_out, NULL, _IONBF, 0);
- SetCloseExec(fileno(term_out), true);
- chmod(logfile_name.c_str(), 0600);
- fprintf(term_out, "\nLog started: %s\n", timestr);
+ setvbuf(d->term_out, NULL, _IONBF, 0);
+ SetCloseExec(fileno(d->term_out), true);
+ struct passwd *pw;
+ struct group *gr;
+ pw = getpwnam("root");
+ gr = getgrnam("adm");
+ if (pw != NULL && gr != NULL)
+ chown(logfile_name.c_str(), pw->pw_uid, gr->gr_gid);
+ chmod(logfile_name.c_str(), 0644);
+ fprintf(d->term_out, "\nLog started: %s\n", timestr);
}
// write your history
@@ -666,41 +700,52 @@ bool pkgDPkgPM::OpenLog()
_config->Find("Dir::Log::History"));
if (!history_name.empty())
{
- history_out = fopen(history_name.c_str(),"a");
- if (history_out == NULL)
+ d->history_out = fopen(history_name.c_str(),"a");
+ if (d->history_out == NULL)
return _error->WarningE("OpenLog", _("Could not open file '%s'"), history_name.c_str());
chmod(history_name.c_str(), 0644);
- fprintf(history_out, "\nStart-Date: %s\n", timestr);
- string remove, purge, install, upgrade, downgrade;
+ fprintf(d->history_out, "\nStart-Date: %s\n", timestr);
+ string remove, purge, install, reinstall, upgrade, downgrade;
for (pkgCache::PkgIterator I = Cache.PkgBegin(); I.end() == false; I++)
{
- if (Cache[I].NewInstall())
- {
- install += I.FullName(false) + string(" (") + Cache[I].CandVersion;
- if (Cache[I].Flags & pkgCache::Flag::Auto)
- install+= ", automatic";
- install += string("), ");
- }
- else if (Cache[I].Upgrade())
- upgrade += I.FullName(false) + string(" (") + Cache[I].CurVersion + string(", ") + Cache[I].CandVersion + string("), ");
- else if (Cache[I].Downgrade())
- downgrade += I.FullName(false) + string(" (") + Cache[I].CurVersion + string(", ") + Cache[I].CandVersion + string("), ");
- else if (Cache[I].Delete())
- {
- if ((Cache[I].iFlags & pkgDepCache::Purge) == pkgDepCache::Purge)
- purge += I.FullName(false) + string(" (") + Cache[I].CurVersion + string("), ");
- else
- remove += I.FullName(false) + string(" (") + Cache[I].CurVersion + string("), ");
+ enum { CANDIDATE, CANDIDATE_AUTO, CURRENT_CANDIDATE, CURRENT } infostring;
+ string *line = NULL;
+ #define HISTORYINFO(X, Y) { line = &X; infostring = Y; }
+ if (Cache[I].NewInstall() == true)
+ HISTORYINFO(install, CANDIDATE_AUTO)
+ else if (Cache[I].ReInstall() == true)
+ HISTORYINFO(reinstall, CANDIDATE)
+ else if (Cache[I].Upgrade() == true)
+ HISTORYINFO(upgrade, CURRENT_CANDIDATE)
+ else if (Cache[I].Downgrade() == true)
+ HISTORYINFO(downgrade, CURRENT_CANDIDATE)
+ else if (Cache[I].Delete() == true)
+ HISTORYINFO((Cache[I].Purge() ? purge : remove), CURRENT)
+ else
+ continue;
+ #undef HISTORYINFO
+ line->append(I.FullName(false)).append(" (");
+ switch (infostring) {
+ case CANDIDATE: line->append(Cache[I].CandVersion); break;
+ case CANDIDATE_AUTO:
+ line->append(Cache[I].CandVersion);
+ if ((Cache[I].Flags & pkgCache::Flag::Auto) == pkgCache::Flag::Auto)
+ line->append(", automatic");
+ break;
+ case CURRENT_CANDIDATE: line->append(Cache[I].CurVersion).append(", ").append(Cache[I].CandVersion); break;
+ case CURRENT: line->append(Cache[I].CurVersion); break;
}
+ line->append("), ");
}
if (_config->Exists("Commandline::AsString") == true)
WriteHistoryTag("Commandline", _config->Find("Commandline::AsString"));
WriteHistoryTag("Install", install);
+ WriteHistoryTag("Reinstall", reinstall);
WriteHistoryTag("Upgrade", upgrade);
WriteHistoryTag("Downgrade",downgrade);
WriteHistoryTag("Remove",remove);
WriteHistoryTag("Purge",purge);
- fflush(history_out);
+ fflush(d->history_out);
}
return true;
@@ -714,16 +759,16 @@ bool pkgDPkgPM::CloseLog()
struct tm *tmp = localtime(&t);
strftime(timestr, sizeof(timestr), "%F %T", tmp);
- if(term_out)
+ if(d->term_out)
{
- fprintf(term_out, "Log ended: ");
- fprintf(term_out, "%s", timestr);
- fprintf(term_out, "\n");
- fclose(term_out);
+ fprintf(d->term_out, "Log ended: ");
+ fprintf(d->term_out, "%s", timestr);
+ fprintf(d->term_out, "\n");
+ fclose(d->term_out);
}
- term_out = NULL;
+ d->term_out = NULL;
- if(history_out)
+ if(d->history_out)
{
if (disappearedPkgs.empty() == false)
{
@@ -740,12 +785,12 @@ bool pkgDPkgPM::CloseLog()
}
WriteHistoryTag("Disappeared", disappear);
}
- if (dpkg_error.empty() == false)
- fprintf(history_out, "Error: %s\n", dpkg_error.c_str());
- fprintf(history_out, "End-Date: %s\n", timestr);
- fclose(history_out);
+ if (d->dpkg_error.empty() == false)
+ fprintf(d->history_out, "Error: %s\n", d->dpkg_error.c_str());
+ fprintf(d->history_out, "End-Date: %s\n", timestr);
+ fclose(d->history_out);
}
- history_out = NULL;
+ d->history_out = NULL;
return true;
}
@@ -853,7 +898,7 @@ bool pkgDPkgPM::Go(int OutStatusFd)
}
}
- stdin_is_dev_null = false;
+ d->stdin_is_dev_null = false;
// create log
OpenLog();
@@ -881,7 +926,10 @@ bool pkgDPkgPM::Go(int OutStatusFd)
// Generate the argument list
const char *Args[MaxArgs + 50];
-
+ // keep track of allocated strings for multiarch package names
+ char *Packages[MaxArgs + 50];
+ unsigned int pkgcount = 0;
+
// Now check if we are within the MaxArgs limit
//
// this code below is problematic, because it may happen that
@@ -989,16 +1037,27 @@ bool pkgDPkgPM::Go(int OutStatusFd)
}
else
{
+ string const nativeArch = _config->Find("APT::Architecture");
+ unsigned long const oldSize = I->Op == Item::Configure ? Size : 0;
for (;I != J && Size < MaxArgBytes; I++)
{
if((*I).Pkg.end() == true)
continue;
if (I->Op == Item::Configure && disappearedPkgs.find(I->Pkg.Name()) != disappearedPkgs.end())
continue;
- Args[n++] = I->Pkg.Name();
+ if (I->Pkg.Arch() == nativeArch || !strcmp(I->Pkg.Arch(), "all"))
+ Args[n++] = I->Pkg.Name();
+ else
+ {
+ Packages[pkgcount] = strdup(I->Pkg.FullName(false).c_str());
+ Args[n++] = Packages[pkgcount++];
+ }
Size += strlen(Args[n-1]);
- }
- }
+ }
+ // skip configure action if all sheduled packages disappeared
+ if (oldSize == Size)
+ continue;
+ }
Args[n] = 0;
J = I;
@@ -1039,8 +1098,8 @@ bool pkgDPkgPM::Go(int OutStatusFd)
const char *s = _("Can not write log, openpty() "
"failed (/dev/pts not mounted?)\n");
fprintf(stderr, "%s",s);
- if(term_out)
- fprintf(term_out, "%s",s);
+ if(d->term_out)
+ fprintf(d->term_out, "%s",s);
master = slave = -1;
} else {
struct termios rtt;
@@ -1145,6 +1204,11 @@ bool pkgDPkgPM::Go(int OutStatusFd)
sigemptyset(&sigmask);
sigprocmask(SIG_BLOCK,&sigmask,&original_sigmask);
+ /* clean up the temporary allocation for multiarch package names in
+ the parent, so we don't leak memory when we return. */
+ for (unsigned int i = 0; i < pkgcount; i++)
+ free(Packages[i]);
+
// the result of the waitpid call
int res;
int select_ret;
@@ -1165,7 +1229,7 @@ bool pkgDPkgPM::Go(int OutStatusFd)
// wait for input or output here
FD_ZERO(&rfds);
- if (master >= 0 && !stdin_is_dev_null)
+ if (master >= 0 && !d->stdin_is_dev_null)
FD_SET(0, &rfds);
FD_SET(_dpkgin, &rfds);
if(master >= 0)
@@ -1219,14 +1283,14 @@ bool pkgDPkgPM::Go(int OutStatusFd)
RunScripts("DPkg::Post-Invoke");
if (WIFSIGNALED(Status) != 0 && WTERMSIG(Status) == SIGSEGV)
- strprintf(dpkg_error, "Sub-process %s received a segmentation fault.",Args[0]);
+ strprintf(d->dpkg_error, "Sub-process %s received a segmentation fault.",Args[0]);
else if (WIFEXITED(Status) != 0)
- strprintf(dpkg_error, "Sub-process %s returned an error code (%u)",Args[0],WEXITSTATUS(Status));
+ strprintf(d->dpkg_error, "Sub-process %s returned an error code (%u)",Args[0],WEXITSTATUS(Status));
else
- strprintf(dpkg_error, "Sub-process %s exited unexpectedly",Args[0]);
+ strprintf(d->dpkg_error, "Sub-process %s exited unexpectedly",Args[0]);
- if(dpkg_error.size() > 0)
- _error->Error("%s", dpkg_error.c_str());
+ if(d->dpkg_error.size() > 0)
+ _error->Error("%s", d->dpkg_error.c_str());
if(stopOnError)
{
@@ -1240,6 +1304,23 @@ bool pkgDPkgPM::Go(int OutStatusFd)
if (RunScripts("DPkg::Post-Invoke") == false)
return false;
+ if (_config->FindB("Debug::pkgDPkgPM",false) == false)
+ {
+ std::string const oldpkgcache = _config->FindFile("Dir::cache::pkgcache");
+ if (oldpkgcache.empty() == false && RealFileExists(oldpkgcache) == true &&
+ unlink(oldpkgcache.c_str()) == 0)
+ {
+ std::string const srcpkgcache = _config->FindFile("Dir::cache::srcpkgcache");
+ if (srcpkgcache.empty() == false && RealFileExists(srcpkgcache) == true)
+ {
+ _error->PushToStack();
+ pkgCacheFile CacheFile;
+ CacheFile.BuildCaches(NULL, true);
+ _error->RevertToStack();
+ }
+ }
+ }
+
Cache.writeStateFile(NULL);
return true;
}
@@ -1373,8 +1454,8 @@ void pkgDPkgPM::WriteApportReport(const char *pkgpath, const char *errormsg)
fprintf(report, "ErrorMessage:\n %s\n", errormsg);
// ensure that the log is flushed
- if(term_out)
- fflush(term_out);
+ if(d->term_out)
+ fflush(d->term_out);
// attach terminal log it if we have it
string logfile_name = _config->FindFile("Dir::Log::Terminal");
diff --git a/apt-pkg/deb/dpkgpm.h b/apt-pkg/deb/dpkgpm.h
index b7b5a6def..ddf9485c7 100644
--- a/apt-pkg/deb/dpkgpm.h
+++ b/apt-pkg/deb/dpkgpm.h
@@ -18,19 +18,12 @@
using std::vector;
using std::map;
+class pkgDPkgPMPrivate;
class pkgDPkgPM : public pkgPackageManager
{
private:
-
- bool stdin_is_dev_null;
-
- // the buffer we use for the dpkg status-fd reading
- char dpkgbuf[1024];
- int dpkgbuf_pos;
- FILE *term_out;
- FILE *history_out;
- string dpkg_error;
+ pkgDPkgPMPrivate *d;
/** \brief record the disappear action and handle accordingly
diff --git a/apt-pkg/depcache.cc b/apt-pkg/depcache.cc
index 5f59b6d49..1d905df2e 100644
--- a/apt-pkg/depcache.cc
+++ b/apt-pkg/depcache.cc
@@ -70,7 +70,7 @@ void pkgDepCache::ActionGroup::release()
cache.MarkAndSweep();
}
- released = false;
+ released = true;
}
}
@@ -339,8 +339,7 @@ bool pkgDepCache::CheckDep(DepIterator Dep,int Type,PkgIterator &Res)
/* Check simple depends. A depends -should- never self match but
we allow it anyhow because dpkg does. Technically it is a packaging
bug. Conflicts may never self match */
- if (Dep.TargetPkg()->Group != Dep.ParentPkg()->Group ||
- (Dep->Type != Dep::Conflicts && Dep->Type != Dep::DpkgBreaks && Dep->Type != Dep::Obsoletes))
+ if (Dep.TargetPkg() != Dep.ParentPkg() || Dep.IsNegative() == false)
{
PkgIterator Pkg = Dep.TargetPkg();
// Check the base package
@@ -370,8 +369,7 @@ bool pkgDepCache::CheckDep(DepIterator Dep,int Type,PkgIterator &Res)
{
/* Provides may never be applied against the same package (or group)
if it is a conflicts. See the comment above. */
- if (P.OwnerPkg()->Group == Pkg->Group &&
- (Dep->Type == Dep::Conflicts || Dep->Type == Dep::DpkgBreaks))
+ if (P.OwnerPkg()->Group == Pkg->Group && Dep.IsNegative() == true)
continue;
// Check if the provides is a hit
@@ -408,60 +406,8 @@ bool pkgDepCache::CheckDep(DepIterator Dep,int Type,PkgIterator &Res)
/*}}}*/
// DepCache::AddSizes - Add the packages sizes to the counters /*{{{*/
// ---------------------------------------------------------------------
-/* Call with Mult = -1 to preform the inverse opration
- The Mult increases the complexity of the calulations here and is unused -
- or do we really have a usecase for removing the size of a package two
- times? So let us replace it with a simple bool and be done with it… */
-__deprecated void pkgDepCache::AddSizes(const PkgIterator &Pkg,signed long Mult)
-{
- StateCache &P = PkgState[Pkg->ID];
-
- if (Pkg->VersionList == 0)
- return;
-
- if (Pkg.State() == pkgCache::PkgIterator::NeedsConfigure &&
- P.Keep() == true)
- return;
-
- // Compute the size data
- if (P.NewInstall() == true)
- {
- iUsrSize += (signed long long)(Mult*P.InstVerIter(*this)->InstalledSize);
- iDownloadSize += (signed long long)(Mult*P.InstVerIter(*this)->Size);
- return;
- }
-
- // Upgrading
- if (Pkg->CurrentVer != 0 &&
- (P.InstallVer != (Version *)Pkg.CurrentVer() ||
- (P.iFlags & ReInstall) == ReInstall) && P.InstallVer != 0)
- {
- iUsrSize += (signed long long)(Mult*((signed long long)P.InstVerIter(*this)->InstalledSize -
- (signed long long)Pkg.CurrentVer()->InstalledSize));
- iDownloadSize += (signed long long)(Mult*P.InstVerIter(*this)->Size);
- return;
- }
-
- // Reinstall
- if (Pkg.State() == pkgCache::PkgIterator::NeedsUnpack &&
- P.Delete() == false)
- {
- iDownloadSize += (signed long long)(Mult*P.InstVerIter(*this)->Size);
- return;
- }
-
- // Removing
- if (Pkg->CurrentVer != 0 && P.InstallVer == 0)
- {
- iUsrSize -= (signed long long)(Mult*Pkg.CurrentVer()->InstalledSize);
- return;
- }
-}
- /*}}}*/
-// DepCache::AddSizes - Add the packages sizes to the counters /*{{{*/
-// ---------------------------------------------------------------------
/* Call with Inverse = true to preform the inverse opration */
-void pkgDepCache::AddSizes(const PkgIterator &Pkg, bool const &Inverse)
+void pkgDepCache::AddSizes(const PkgIterator &Pkg, bool const Inverse)
{
StateCache &P = PkgState[Pkg->ID];
@@ -532,8 +478,9 @@ void pkgDepCache::AddSizes(const PkgIterator &Pkg, bool const &Inverse)
calld Remove/Add itself. Remember, dependencies can be circular so
while processing a dep for Pkg it is possible that Add/Remove
will be called on Pkg */
-void pkgDepCache::AddStates(const PkgIterator &Pkg,int Add)
+void pkgDepCache::AddStates(const PkgIterator &Pkg, bool const Invert)
{
+ signed char const Add = (Invert == false) ? 1 : -1;
StateCache &State = PkgState[Pkg->ID];
// The Package is broken (either minimal dep or policy dep)
@@ -549,8 +496,8 @@ void pkgDepCache::AddStates(const PkgIterator &Pkg,int Add)
// Not installed
if (Pkg->CurrentVer == 0)
{
- if (State.Mode == ModeDelete &&
- (State.iFlags | Purge) == Purge && Pkg.Purge() == false)
+ if (State.Mode == ModeDelete &&
+ (State.iFlags & Purge) == Purge && Pkg.Purge() == false)
iDelCount += Add;
if (State.Mode == ModeInstall)
@@ -594,9 +541,7 @@ void pkgDepCache::BuildGroupOrs(VerIterator const &V)
/* Invert for Conflicts. We have to do this twice to get the
right sense for a conflicts group */
- if (D->Type == Dep::Conflicts ||
- D->Type == Dep::DpkgBreaks ||
- D->Type == Dep::Obsoletes)
+ if (D.IsNegative() == true)
State = ~State;
// Add to the group if we are within an or..
@@ -607,9 +552,7 @@ void pkgDepCache::BuildGroupOrs(VerIterator const &V)
Group = 0;
// Invert for Conflicts
- if (D->Type == Dep::Conflicts ||
- D->Type == Dep::DpkgBreaks ||
- D->Type == Dep::Obsoletes)
+ if (D.IsNegative() == true)
State = ~State;
}
}
@@ -705,107 +648,6 @@ void pkgDepCache::UpdateVerState(PkgIterator Pkg)
}
}
/*}}}*/
-// DepCache::RemovePseudoInstalledPkg - MultiArch helper for Update() /*{{{*/
-// ---------------------------------------------------------------------
-/* We "install" arch all packages for all archs if it is installed. Many
- of these will be broken. This method will look at these broken Pkg and
- "remove" it. */
-bool pkgDepCache::RemovePseudoInstalledPkg(PkgIterator &Pkg, std::set<unsigned long> &recheck) {
- if (unlikely(Pkg->CurrentVer == 0))
- return false;
-
- VerIterator V = Pkg.CurrentVer();
- if (V->MultiArch != Version::All)
- return false;
-
- // Never ever kill an "all" package - they have no dependency so they can't be broken
- if (strcmp(Pkg.Arch(),"all") == 0)
- return false;
-
- unsigned char const CurDepState = VersionState(V.DependsList(),DepInstall,DepInstMin,DepInstPolicy);
- if ((CurDepState & DepInstMin) == DepInstMin) {
- // okay, the package isn't broken, but is the package also required?
- // If it has no real dependencies, no installed rdepends and doesn't
- // provide something of value, we will kill it as not required.
- // These pseudopackages have otherwise interesting effects if they get
- // a new dependency in a newer version…
- for (pkgCache::DepIterator D = V.DependsList();
- D.end() != true; ++D)
- if (D.IsCritical() == true && D.ParentPkg()->Group != Pkg->Group)
- return false;
- for (DepIterator D = Pkg.RevDependsList(); D.end() != true; ++D)
- {
- if (D.IsCritical() == false)
- continue;
- PkgIterator const P = D.ParentPkg();
- if (P->Group == Pkg->Group)
- continue;
- if (P->CurrentVer != 0)
- return false;
- }
- for (PrvIterator Prv = V.ProvidesList(); Prv.end() != true; Prv++)
- for (DepIterator d = Prv.ParentPkg().RevDependsList();
- d.end() != true; ++d)
- {
- PkgIterator const P = d.ParentPkg();
- if (P->CurrentVer != 0 &&
- P->Group != Pkg->Group)
- return false;
- }
- }
-
- // Dependencies for this arch all package are not statisfied
- // so we installed it only for our convenience: get right of it now.
- RemoveSizes(Pkg);
- RemoveStates(Pkg);
-
- Pkg->CurrentVer = 0;
- PkgState[Pkg->ID].InstallVer = 0;
-
- AddStates(Pkg);
- Update(Pkg);
- AddSizes(Pkg);
-
- // After the remove previously satisfied pseudo pkg could be now
- // no longer satisfied, so we need to recheck the reverse dependencies
- for (DepIterator d = Pkg.RevDependsList(); d.end() != true; ++d)
- {
- PkgIterator const P = d.ParentPkg();
- if (P->CurrentVer != 0)
- recheck.insert(P.Index());
- }
-
- for (DepIterator d = V.DependsList(); d.end() != true; ++d)
- {
- PkgIterator const P = d.TargetPkg();
- for (PrvIterator Prv = P.ProvidesList(); Prv.end() != true; ++Prv)
- {
- PkgIterator const O = Prv.OwnerPkg();
- if (O->CurrentVer != 0)
- recheck.insert(O.Index());
- }
-
- if (P->CurrentVer != 0)
- recheck.insert(P.Index());
- }
-
- for (PrvIterator Prv = V.ProvidesList(); Prv.end() != true; Prv++)
- {
- for (DepIterator d = Prv.ParentPkg().RevDependsList();
- d.end() != true; ++d)
- {
- PkgIterator const P = d.ParentPkg();
- if (P->CurrentVer == 0)
- continue;
-
- recheck.insert(P.Index());
- }
- }
-
-
- return true;
-}
- /*}}}*/
// DepCache::Update - Figure out all the state information /*{{{*/
// ---------------------------------------------------------------------
/* This will figure out the state of all the packages and all the
@@ -820,12 +662,8 @@ void pkgDepCache::Update(OpProgress *Prog)
iBrokenCount = 0;
iBadCount = 0;
- std::set<unsigned long> recheck;
-
// Perform the depends pass
int Done = 0;
- bool const checkMultiArch = APT::Configuration::getArchitectures().size() > 1;
- unsigned long killed = 0;
for (PkgIterator I = PkgBegin(); I.end() != true; I++,Done++)
{
if (Prog != 0 && Done%20 == 0)
@@ -847,9 +685,7 @@ void pkgDepCache::Update(OpProgress *Prog)
Group = 0;
// Invert for Conflicts
- if (D->Type == Dep::Conflicts ||
- D->Type == Dep::DpkgBreaks ||
- D->Type == Dep::Obsoletes)
+ if (D.IsNegative() == true)
State = ~State;
}
}
@@ -858,69 +694,6 @@ void pkgDepCache::Update(OpProgress *Prog)
AddSizes(I);
UpdateVerState(I);
AddStates(I);
-
- if (checkMultiArch != true || I->CurrentVer == 0)
- continue;
-
- VerIterator const V = I.CurrentVer();
- if (V->MultiArch != Version::All)
- continue;
-
- recheck.insert(I.Index());
- --Done; // no progress if we need to recheck the package
- }
-
- if (checkMultiArch == true) {
- /* FIXME: recheck breaks proper progress reporting as we don't know
- how many packages we need to recheck. To lower the effect
- a bit we increase with a kill, but we should do something more clever… */
- while(recheck.empty() == false)
- for (std::set<unsigned long>::const_iterator p = recheck.begin();
- p != recheck.end();) {
- if (Prog != 0 && Done%20 == 0)
- Prog->Progress(Done);
- PkgIterator P = PkgIterator(*Cache, Cache->PkgP + *p);
- if (RemovePseudoInstalledPkg(P, recheck) == true) {
- ++killed;
- ++Done;
- }
- recheck.erase(p++);
- }
-
- /* Okay, we have killed a great amount of pseudopackages -
- we have killed so many that we have now arch "all" packages
- without an installed pseudo package, but we NEED an installed
- pseudo package, so we will search now for a pseudo package
- we can install without breaking everything. */
- for (GrpIterator G = Cache->GrpBegin(); G.end() != true; ++G)
- {
- PkgIterator P = G.FindPkg("all");
- if (P.end() == true)
- continue;
- if (P->CurrentVer == 0)
- continue;
- bool installed = false;
- for (P = G.FindPkg("any"); P.end() != true; P = G.NextPkg(P))
- {
- if (strcmp(P.Arch(), "all") == 0)
- continue;
- if (P->CurrentVer == 0)
- continue;
- installed = true;
- break;
- }
- if (installed == false)
- recheck.insert(G.Index());
- }
-
- while (recheck.empty() != true)
- {
- std::set<unsigned long>::const_iterator g = recheck.begin();
- unsigned long const G = *g;
- recheck.erase(g);
- if (unlikely(ReInstallPseudoForGroup(G, recheck) == false))
- _error->Warning(_("Internal error, group '%s' has no installable pseudo package"), GrpIterator(*Cache, Cache->GrpP + G).Name());
- }
}
if (Prog != 0)
@@ -929,80 +702,6 @@ void pkgDepCache::Update(OpProgress *Prog)
readStateFile(Prog);
}
/*}}}*/
-// DepCache::ReInstallPseudoForGroup - MultiArch helper for Update() /*{{{*/
-// ---------------------------------------------------------------------
-/* RemovePseudoInstalledPkg() is very successful. It even kills packages
- to an amount that no pseudo package is left, but we need a pseudo package
- for upgrading senarios so we need to reinstall one pseudopackage which
- doesn't break everything. Thankfully we can't have architecture depending
- negative dependencies so this problem is already eliminated */
-bool pkgDepCache::ReInstallPseudoForGroup(pkgCache::PkgIterator const &P, std::set<unsigned long> &recheck)
-{
- if (P->CurrentVer != 0)
- return true;
- // recursive call for packages which provide this package
- for (pkgCache::PrvIterator Prv = P.ProvidesList(); Prv.end() != true; ++Prv)
- ReInstallPseudoForGroup(Prv.OwnerPkg(), recheck);
- // check if we actually need to look at this group
- unsigned long const G = P->Group;
- std::set<unsigned long>::const_iterator Pi = recheck.find(G);
- if (Pi == recheck.end())
- return true;
- recheck.erase(Pi); // remove here, so we can't fall into an endless loop
- if (unlikely(ReInstallPseudoForGroup(G, recheck) == false))
- {
- recheck.insert(G);
- return false;
- }
- return true;
-}
-bool pkgDepCache::ReInstallPseudoForGroup(unsigned long const &G, std::set<unsigned long> &recheck)
-{
- std::vector<std::string> static const Archs = APT::Configuration::getArchitectures();
- pkgCache::GrpIterator Grp(*Cache, Cache->GrpP + G);
- if (unlikely(Grp.end() == true))
- return false;
- for (std::vector<std::string>::const_iterator a = Archs.begin();
- a != Archs.end(); ++a)
- {
- pkgCache::PkgIterator P = Grp.FindPkg(*a);
- if (P.end() == true)
- continue;
- pkgCache::VerIterator allV = Grp.FindPkg("all").CurrentVer();
- for (VerIterator V = P.VersionList(); V.end() != true; ++V)
- {
- // search for the same version as the all package
- if (allV->Hash != V->Hash || strcmp(allV.VerStr(),V.VerStr()) != 0)
- continue;
- unsigned char const CurDepState = VersionState(V.DependsList(),DepInstall,DepInstMin,DepInstPolicy);
- // If it is broken, try to install dependencies first before retry
- if ((CurDepState & DepInstMin) != DepInstMin)
- {
- for (pkgCache::DepIterator D = V.DependsList(); D.end() != true; ++D)
- {
- if (D->Type != pkgCache::Dep::PreDepends && D->Type != pkgCache::Dep::Depends)
- continue;
- ReInstallPseudoForGroup(D.TargetPkg(), recheck);
- }
- unsigned char const CurDepState = VersionState(V.DependsList(),DepInstall,DepInstMin,DepInstPolicy);
- // if package ist still broken… try another arch
- if ((CurDepState & DepInstMin) != DepInstMin)
- break;
- }
- // dependencies satisfied: reinstall the package
- RemoveSizes(P);
- RemoveStates(P);
- P->CurrentVer = V.Index();
- PkgState[P->ID].InstallVer = V;
- AddStates(P);
- Update(P);
- AddSizes(P);
- return true;
- }
- }
- return false;
-}
- /*}}}*/
// DepCache::Update - Update the deps list of a package /*{{{*/
// ---------------------------------------------------------------------
/* This is a helper for update that only does the dep portion of the scan.
@@ -1016,9 +715,7 @@ void pkgDepCache::Update(DepIterator D)
State = DependencyState(D);
// Invert for Conflicts
- if (D->Type == Dep::Conflicts ||
- D->Type == Dep::DpkgBreaks ||
- D->Type == Dep::Obsoletes)
+ if (D.IsNegative() == true)
State = ~State;
RemoveStates(D.ParentPkg());
@@ -1058,37 +755,33 @@ void pkgDepCache::Update(PkgIterator const &Pkg)
// DepCache::MarkKeep - Put the package in the keep state /*{{{*/
// ---------------------------------------------------------------------
/* */
-void pkgDepCache::MarkKeep(PkgIterator const &Pkg, bool Soft, bool FromUser,
+bool pkgDepCache::MarkKeep(PkgIterator const &Pkg, bool Soft, bool FromUser,
unsigned long Depth)
{
- // Simplifies other routines.
- if (Pkg.end() == true)
- return;
+ if (IsModeChangeOk(ModeKeep, Pkg, Depth, FromUser) == false)
+ return false;
/* Reject an attempt to keep a non-source broken installed package, those
must be upgraded */
if (Pkg.State() == PkgIterator::NeedsUnpack &&
Pkg.CurrentVer().Downloadable() == false)
- return;
-
- /** \todo Can this be moved later in the method? */
- ActionGroup group(*this);
+ return false;
/* We changed the soft state all the time so the UI is a bit nicer
to use */
StateCache &P = PkgState[Pkg->ID];
+
+ // Check that it is not already kept
+ if (P.Mode == ModeKeep)
+ return true;
+
if (Soft == true)
P.iFlags |= AutoKept;
else
P.iFlags &= ~AutoKept;
-
- // Check that it is not already kept
- if (P.Mode == ModeKeep)
- return;
- // We dont even try to keep virtual packages..
- if (Pkg->VersionList == 0)
- return;
+ ActionGroup group(*this);
+
#if 0 // reseting the autoflag here means we lose the
// auto-mark information if a user selects a package for removal
// but changes his mind then and sets it for keep again
@@ -1113,41 +806,37 @@ void pkgDepCache::MarkKeep(PkgIterator const &Pkg, bool Soft, bool FromUser,
P.InstallVer = Pkg.CurrentVer();
AddStates(Pkg);
-
Update(Pkg);
-
AddSizes(Pkg);
+
+ return true;
}
/*}}}*/
// DepCache::MarkDelete - Put the package in the delete state /*{{{*/
// ---------------------------------------------------------------------
/* */
-void pkgDepCache::MarkDelete(PkgIterator const &Pkg, bool rPurge,
+bool pkgDepCache::MarkDelete(PkgIterator const &Pkg, bool rPurge,
unsigned long Depth, bool FromUser)
{
- // Simplifies other routines.
- if (Pkg.end() == true)
- return;
+ if (IsModeChangeOk(ModeDelete, Pkg, Depth, FromUser) == false)
+ return false;
- ActionGroup group(*this);
+ StateCache &P = PkgState[Pkg->ID];
// Check that it is not already marked for delete
- StateCache &P = PkgState[Pkg->ID];
- P.iFlags &= ~(AutoKept | Purge);
- if (rPurge == true)
- P.iFlags |= Purge;
-
if ((P.Mode == ModeDelete || P.InstallVer == 0) &&
(Pkg.Purge() == true || rPurge == false))
- return;
-
- // We dont even try to delete virtual packages..
- if (Pkg->VersionList == 0)
- return;
+ return true;
- // check if we are allowed to install the package
+ // check if we are allowed to remove the package
if (IsDeleteOk(Pkg,rPurge,Depth,FromUser) == false)
- return;
+ return false;
+
+ P.iFlags &= ~(AutoKept | Purge);
+ if (rPurge == true)
+ P.iFlags |= Purge;
+
+ ActionGroup group(*this);
if (DebugMarker == true)
std::clog << OutputInDepth(Depth) << (rPurge ? "MarkPurge " : "MarkDelete ") << Pkg << " FU=" << FromUser << std::endl;
@@ -1165,35 +854,17 @@ void pkgDepCache::MarkDelete(PkgIterator const &Pkg, bool rPurge,
Update(Pkg);
AddSizes(Pkg);
- // if we remove the pseudo package, we also need to remove the "real"
- if (Pkg->CurrentVer != 0 && Pkg.CurrentVer().Pseudo() == true)
- MarkDelete(Pkg.Group().FindPkg("all"), rPurge, Depth+1, FromUser);
- else if (rPurge == true && Pkg->CurrentVer == 0 &&
- Pkg->CurrentState != pkgCache::State::NotInstalled &&
- strcmp(Pkg.Arch(), "all") != 0)
- {
- PkgIterator const allPkg = Pkg.Group().FindPkg("all");
- if (allPkg.end() == false && allPkg->CurrentVer == 0 &&
- allPkg->CurrentState != pkgCache::State::NotInstalled)
- MarkDelete(allPkg, rPurge, Depth+1, FromUser);
- }
+ return true;
}
/*}}}*/
// DepCache::IsDeleteOk - check if it is ok to remove this package /*{{{*/
// ---------------------------------------------------------------------
-/* The default implementation just honors dpkg hold
- But an application using this library can override this method
- to control the MarkDelete behaviour */
+/* The default implementation tries to prevent deletion of install requests.
+ dpkg holds are enforced by the private IsModeChangeOk */
bool pkgDepCache::IsDeleteOk(PkgIterator const &Pkg,bool rPurge,
unsigned long Depth, bool FromUser)
{
- if (FromUser == false && Pkg->SelectedState == pkgCache::State::Hold && _config->FindB("APT::Ignore-Hold",false) == false)
- {
- if (DebugMarker == true)
- std::clog << OutputInDepth(Depth) << "Hold prevents MarkDelete of " << Pkg << " FU=" << FromUser << std::endl;
- return false;
- }
- else if (FromUser == false && Pkg->CurrentVer == 0)
+ if (FromUser == false && Pkg->CurrentVer == 0)
{
StateCache &P = PkgState[Pkg->ID];
if (P.InstallVer != 0 && P.Status == 2 && (P.Flags & Flag::Auto) != Flag::Auto)
@@ -1206,45 +877,94 @@ bool pkgDepCache::IsDeleteOk(PkgIterator const &Pkg,bool rPurge,
return true;
}
/*}}}*/
+// DepCache::IsModeChangeOk - check if it is ok to change the mode /*{{{*/
+// ---------------------------------------------------------------------
+/* this is used by all Mark methods on the very first line to check sanity
+ and prevents mode changes for packages on hold for example.
+ If you want to check Mode specific stuff you can use the virtual public
+ Is<Mode>Ok methods instead */
+char const* PrintMode(char const mode)
+{
+ switch (mode)
+ {
+ case pkgDepCache::ModeInstall: return "Install";
+ case pkgDepCache::ModeKeep: return "Keep";
+ case pkgDepCache::ModeDelete: return "Delete";
+ default: return "UNKNOWN";
+ }
+}
+bool pkgDepCache::IsModeChangeOk(ModeList const mode, PkgIterator const &Pkg,
+ unsigned long const Depth, bool const FromUser)
+{
+ // we are not trying to hard…
+ if (unlikely(Depth > 100))
+ return false;
+
+ // general sanity
+ if (unlikely(Pkg.end() == true || Pkg->VersionList == 0))
+ return false;
+
+ // the user is always right
+ if (FromUser == true)
+ return true;
+
+ StateCache &P = PkgState[Pkg->ID];
+
+ // if previous state was set by user only user can reset it
+ if ((P.iFlags & Protected) == Protected)
+ {
+ if (unlikely(DebugMarker == true) && P.Mode != mode)
+ std::clog << OutputInDepth(Depth) << "Ignore Mark" << PrintMode(mode)
+ << " of " << Pkg << " as its mode (" << PrintMode(P.Mode)
+ << ") is protected" << std::endl;
+ return false;
+ }
+ // enforce dpkg holds
+ else if (mode != ModeKeep && Pkg->SelectedState == pkgCache::State::Hold &&
+ _config->FindB("APT::Ignore-Hold",false) == false)
+ {
+ if (unlikely(DebugMarker == true) && P.Mode != mode)
+ std::clog << OutputInDepth(Depth) << "Hold prevents Mark" << PrintMode(mode)
+ << " of " << Pkg << std::endl;
+ return false;
+ }
+
+ return true;
+}
+ /*}}}*/
// DepCache::MarkInstall - Put the package in the install state /*{{{*/
// ---------------------------------------------------------------------
/* */
-void pkgDepCache::MarkInstall(PkgIterator const &Pkg,bool AutoInst,
+bool pkgDepCache::MarkInstall(PkgIterator const &Pkg,bool AutoInst,
unsigned long Depth, bool FromUser,
bool ForceImportantDeps)
{
- if (Depth > 100)
- return;
-
- // Simplifies other routines.
- if (Pkg.end() == true)
- return;
-
- ActionGroup group(*this);
+ if (IsModeChangeOk(ModeInstall, Pkg, Depth, FromUser) == false)
+ return false;
+
+ StateCache &P = PkgState[Pkg->ID];
+
+ // See if there is even any possible instalation candidate
+ if (P.CandidateVer == 0)
+ return false;
/* Check that it is not already marked for install and that it can be
installed */
- StateCache &P = PkgState[Pkg->ID];
- P.iFlags &= ~AutoKept;
if ((P.InstPolicyBroken() == false && P.InstBroken() == false) &&
(P.Mode == ModeInstall ||
P.CandidateVer == (Version *)Pkg.CurrentVer()))
{
if (P.CandidateVer == (Version *)Pkg.CurrentVer() && P.InstallVer == 0)
- MarkKeep(Pkg, false, FromUser, Depth+1);
- return;
+ return MarkKeep(Pkg, false, FromUser, Depth+1);
+ return true;
}
- // See if there is even any possible instalation candidate
- if (P.CandidateVer == 0)
- return;
- // We dont even try to install virtual packages..
- if (Pkg->VersionList == 0)
- return;
-
// check if we are allowed to install the package
if (IsInstallOk(Pkg,AutoInst,Depth,FromUser) == false)
- return;
+ return false;
+
+ ActionGroup group(*this);
+ P.iFlags &= ~AutoKept;
/* Target the candidate version and remove the autoflag. We reset the
autoflag below if this was called recursively. Otherwise the user
@@ -1257,9 +977,10 @@ void pkgDepCache::MarkInstall(PkgIterator const &Pkg,bool AutoInst,
if(FromUser)
{
- // Set it to manual if it's a new install or cancelling the
- // removal of a garbage package.
- if(P.Status == 2 || (!Pkg.CurrentVer().end() && !P.Marked))
+ // Set it to manual if it's a new install or already installed,
+ // but only if its not marked by the autoremover (aptitude depend on this behavior)
+ // or if we do automatic installation (aptitude never does it)
+ if(P.Status == 2 || (Pkg->CurrentVer != 0 && (AutoInst == true || P.Marked == false)))
P.Flags &= ~Flag::Auto;
}
else
@@ -1275,12 +996,8 @@ void pkgDepCache::MarkInstall(PkgIterator const &Pkg,bool AutoInst,
Update(Pkg);
AddSizes(Pkg);
- // always trigger the install of the all package for a pseudo package
- if (P.CandidateVerIter(*Cache).Pseudo() == true)
- MarkInstall(Pkg.Group().FindPkg("all"), AutoInst, Depth, FromUser, ForceImportantDeps);
-
- if (AutoInst == false)
- return;
+ if (AutoInst == false || _config->Find("APT::Solver", "internal") != "internal")
+ return true;
if (DebugMarker == true)
std::clog << OutputInDepth(Depth) << "MarkInstall " << Pkg << " FU=" << FromUser << std::endl;
@@ -1311,7 +1028,22 @@ void pkgDepCache::MarkInstall(PkgIterator const &Pkg,bool AutoInst,
*/
if (IsImportantDep(Start) == false)
continue;
-
+
+ /* If we are in an or group locate the first or that can
+ succeed. We have already cached this.. */
+ for (; Ors > 1 && (DepState[Start->ID] & DepCVer) != DepCVer; --Ors)
+ ++Start;
+ if (Ors == 1 && (DepState[Start->ID] &DepCVer) != DepCVer && Start.IsNegative() == false)
+ {
+ if(DebugAutoInstall == true)
+ std::clog << OutputInDepth(Depth) << Start << " can't be satisfied!" << std::endl;
+ if (Start.IsCritical() == false)
+ continue;
+ // if the dependency was critical, we can't install it, so remove it again
+ MarkDelete(Pkg,false,Depth + 1, false);
+ return false;
+ }
+
/* Check if any ImportantDep() (but not Critical) were added
* since we installed the package. Also check for deps that
* were satisfied in the past: for instance, if a version
@@ -1319,57 +1051,49 @@ void pkgDepCache::MarkInstall(PkgIterator const &Pkg,bool AutoInst,
* package should follow that Recommends rather than causing the
* dependency to be removed. (bug #470115)
*/
- bool isNewImportantDep = false;
- bool isPreviouslySatisfiedImportantDep = false;
- if(!ForceImportantDeps && !Start.IsCritical())
+ if (Pkg->CurrentVer != 0 && ForceImportantDeps == false && Start.IsCritical() == false)
{
- bool found=false;
- VerIterator instVer = Pkg.CurrentVer();
- if(!instVer.end())
+ bool isNewImportantDep = true;
+ bool isPreviouslySatisfiedImportantDep = false;
+ for (DepIterator D = Pkg.CurrentVer().DependsList(); D.end() != true; ++D)
{
- for (DepIterator D = instVer.DependsList(); D.end() != true; D++)
- {
- //FIXME: deal better with or-groups(?)
- if(IsImportantDep(D) && !D.IsCritical() &&
- Start.TargetPkg() == D.TargetPkg())
- {
- if(!isPreviouslySatisfiedImportantDep)
- {
- DepIterator D2 = D;
- while((D2->CompareOp & Dep::Or) != 0)
- ++D2;
-
- isPreviouslySatisfiedImportantDep =
- (((*this)[D2] & DepGNow) != 0);
- }
-
- found=true;
- }
- }
- // this is a new dep if it was not found to be already
- // a important dep of the installed pacakge
- isNewImportantDep = !found;
+ //FIXME: Should we handle or-group better here?
+ // We do not check if the package we look for is part of the same or-group
+ // we might find while searching, but could that really be a problem?
+ if (D.IsCritical() == true || IsImportantDep(D) == false ||
+ Start.TargetPkg() != D.TargetPkg())
+ continue;
+
+ isNewImportantDep = false;
+
+ while ((D->CompareOp & Dep::Or) != 0)
+ ++D;
+
+ isPreviouslySatisfiedImportantDep = (((*this)[D] & DepGNow) != 0);
+ if (isPreviouslySatisfiedImportantDep == true)
+ break;
+ }
+
+ if(isNewImportantDep == true)
+ {
+ if (DebugAutoInstall == true)
+ std::clog << OutputInDepth(Depth) << "new important dependency: "
+ << Start.TargetPkg().FullName() << std::endl;
+ }
+ else if(isPreviouslySatisfiedImportantDep == true)
+ {
+ if (DebugAutoInstall == true)
+ std::clog << OutputInDepth(Depth) << "previously satisfied important dependency on "
+ << Start.TargetPkg().FullName() << std::endl;
+ }
+ else
+ {
+ if (DebugAutoInstall == true)
+ std::clog << OutputInDepth(Depth) << "ignore old unsatisfied important dependency on "
+ << Start.TargetPkg().FullName() << std::endl;
+ continue;
}
}
- if(isNewImportantDep)
- if(DebugAutoInstall == true)
- std::clog << OutputInDepth(Depth) << "new important dependency: "
- << Start.TargetPkg().Name() << std::endl;
- if(isPreviouslySatisfiedImportantDep)
- if(DebugAutoInstall == true)
- std::clog << OutputInDepth(Depth) << "previously satisfied important dependency on "
- << Start.TargetPkg().Name() << std::endl;
-
- // skip important deps if the package is already installed
- if (Pkg->CurrentVer != 0 && Start.IsCritical() == false
- && !isNewImportantDep && !isPreviouslySatisfiedImportantDep
- && !ForceImportantDeps)
- continue;
-
- /* If we are in an or group locate the first or that can
- succeed. We have already cached this.. */
- for (; Ors > 1 && (DepState[Start->ID] & DepCVer) != DepCVer; Ors--)
- Start++;
/* This bit is for processing the possibilty of an install/upgrade
fixing the problem */
@@ -1435,8 +1159,7 @@ void pkgDepCache::MarkInstall(PkgIterator const &Pkg,bool AutoInst,
/* 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->Type == Dep::Conflicts || Start->Type == Dep::Obsoletes ||
- Start->Type == Dep::DpkgBreaks)
+ if (Start.IsNegative() == true)
{
for (Version **I = List; *I != 0; I++)
{
@@ -1449,30 +1172,26 @@ void pkgDepCache::MarkInstall(PkgIterator const &Pkg,bool AutoInst,
continue;
if (PkgState[Pkg->ID].CandidateVer != *I &&
- Start->Type == Dep::DpkgBreaks)
- MarkInstall(Pkg,true,Depth + 1, false, ForceImportantDeps);
- else
- MarkDelete(Pkg,false,Depth + 1, false);
+ Start->Type == Dep::DpkgBreaks &&
+ MarkInstall(Pkg,true,Depth + 1, false, ForceImportantDeps) == true)
+ continue;
+ else if (MarkDelete(Pkg,false,Depth + 1, false) == false)
+ break;
}
continue;
}
}
+
+ return Dep.end() == true;
}
/*}}}*/
// DepCache::IsInstallOk - check if it is ok to install this package /*{{{*/
// ---------------------------------------------------------------------
-/* The default implementation just honors dpkg hold
- But an application using this library can override this method
- to control the MarkInstall behaviour */
+/* The default implementation does nothing.
+ dpkg holds are enforced by the private IsModeChangeOk */
bool pkgDepCache::IsInstallOk(PkgIterator const &Pkg,bool AutoInst,
unsigned long Depth, bool FromUser)
{
- if (FromUser == false && Pkg->SelectedState == pkgCache::State::Hold && _config->FindB("APT::Ignore-Hold",false) == false)
- {
- if (DebugMarker == true)
- std::clog << OutputInDepth(Depth) << "Hold prevents MarkInstall of " << Pkg << " FU=" << FromUser << std::endl;
- return false;
- }
return true;
}
/*}}}*/
@@ -1497,19 +1216,13 @@ void pkgDepCache::SetReInstall(PkgIterator const &Pkg,bool To)
AddStates(Pkg);
AddSizes(Pkg);
-
- if (unlikely(Pkg.CurrentVer().end() == true) || Pkg.CurrentVer().Pseudo() == false)
- return;
-
- SetReInstall(Pkg.Group().FindPkg("all"), To);
}
/*}}}*/
// DepCache::SetCandidateVersion - Change the candidate version /*{{{*/
// ---------------------------------------------------------------------
/* */
-void pkgDepCache::SetCandidateVersion(VerIterator TargetVer, bool const &Pseudo)
+void pkgDepCache::SetCandidateVersion(VerIterator TargetVer)
{
-
pkgCache::PkgIterator Pkg = TargetVer.ParentPkg();
StateCache &P = PkgState[Pkg->ID];
@@ -1530,27 +1243,6 @@ void pkgDepCache::SetCandidateVersion(VerIterator TargetVer, bool const &Pseudo)
Update(Pkg);
AddSizes(Pkg);
- if (TargetVer.Pseudo() == false || Pseudo == false)
- return;
-
- // the version was pseudo: set all other pseudos also
- pkgCache::GrpIterator Grp = Pkg.Group();
- for (Pkg = Grp.FindPkg("any"); Pkg.end() == false; ++Pkg)
- {
- StateCache &P = PkgState[Pkg->ID];
- if (TargetVer.SimilarVer(P.CandidateVerIter(*this)) == true ||
- (P.CandidateVerIter(*this).Pseudo() == false &&
- strcmp(Pkg.Arch(), "all") != 0))
- continue;
-
- for (pkgCache::VerIterator Ver = Pkg.VersionList(); Ver.end() == false; ++Ver)
- {
- if (TargetVer.SimilarVer(Ver) == false)
- continue;
- SetCandidateVersion(Ver, false);
- break;
- }
- }
}
/*}}}*/
// DepCache::SetCandidateRelease - Change the candidate version /*{{{*/
@@ -1835,6 +1527,12 @@ bool pkgDepCache::Policy::IsImportantDep(DepIterator const &Dep)
return false;
}
/*}}}*/
+// Policy::GetPriority - Get the priority of the package pin /*{{{*/
+signed short pkgDepCache::Policy::GetPriority(pkgCache::PkgIterator const &Pkg)
+{ return 0; };
+signed short pkgDepCache::Policy::GetPriority(pkgCache::PkgFileIterator const &File)
+{ return 0; };
+ /*}}}*/
pkgDepCache::InRootSetFunc *pkgDepCache::GetRootSetFunc() /*{{{*/
{
DefaultRootSetFunc *f = new DefaultRootSetFunc;
@@ -1860,6 +1558,9 @@ bool pkgDepCache::MarkFollowsSuggests()
// pkgDepCache::MarkRequired - the main mark algorithm /*{{{*/
bool pkgDepCache::MarkRequired(InRootSetFunc &userFunc)
{
+ if (_config->Find("APT::Solver", "internal") != "internal")
+ return true;
+
bool follow_recommends;
bool follow_suggests;
bool debug_autoremove = _config->FindB("Debug::pkgAutoRemove",false);
@@ -1966,28 +1667,6 @@ void pkgDepCache::MarkPackage(const pkgCache::PkgIterator &pkg,
if(ver.end() == true)
return;
- // If the version belongs to a Multi-Arch all package
- // we will mark all others in this Group with this version also
- if (ver->MultiArch == pkgCache::Version::All &&
- strcmp(ver.Arch(true), "all") == 0)
- {
- GrpIterator G = pkg.Group();
- const char* const VerStr = ver.VerStr();
- for (PkgIterator P = G.FindPkg("any");
- P.end() != true; P = G.NextPkg(P))
- {
- for (VerIterator V = P.VersionList();
- V.end() != true; ++V)
- {
- if (ver->Hash != V->Hash ||
- strcmp(VerStr, V.VerStr()) != 0)
- continue;
- MarkPackage(P, V, follow_recommends, follow_suggests);
- break;
- }
- }
- }
-
for(DepIterator d = ver.DependsList(); !d.end(); ++d)
{
if(d->Type == Dep::Depends ||
diff --git a/apt-pkg/depcache.h b/apt-pkg/depcache.h
index dba3e22dc..adc010c28 100644
--- a/apt-pkg/depcache.h
+++ b/apt-pkg/depcache.h
@@ -119,7 +119,7 @@ class pkgDepCache : protected pkgCache::Namespace
DepCandPolicy = (1 << 4), DepCandMin = (1 << 5)};
// These flags are used in StateCache::iFlags
- enum InternalFlags {AutoKept = (1 << 0), Purge = (1 << 1), ReInstall = (1 << 2)};
+ enum InternalFlags {AutoKept = (1 << 0), Purge = (1 << 1), ReInstall = (1 << 2), Protected = (1 << 3)};
enum VersionTypes {NowVersion, InstallVersion, CandidateVersion};
enum ModeList {ModeDelete = 0, ModeKeep = 1, ModeInstall = 2};
@@ -231,7 +231,9 @@ class pkgDepCache : protected pkgCache::Namespace
// Various test members for the current status of the package
inline bool NewInstall() const {return Status == 2 && Mode == ModeInstall;};
inline bool Delete() const {return Mode == ModeDelete;};
+ inline bool Purge() const {return Delete() == true && (iFlags & pkgDepCache::Purge) == pkgDepCache::Purge; };
inline bool Keep() const {return Mode == ModeKeep;};
+ inline bool Protect() const {return (iFlags & Protected) == Protected;};
inline bool Upgrade() const {return Status > 0 && Mode == ModeInstall;};
inline bool Upgradable() const {return Status >= 1;};
inline bool Downgrade() const {return Status < 0 && Mode == ModeInstall;};
@@ -241,6 +243,7 @@ class pkgDepCache : protected pkgCache::Namespace
inline bool InstBroken() const {return (DepState & DepInstMin) != DepInstMin;};
inline bool InstPolicyBroken() const {return (DepState & DepInstPolicy) != DepInstPolicy;};
inline bool Install() const {return Mode == ModeInstall;};
+ inline bool ReInstall() const {return Delete() == false && (iFlags & pkgDepCache::ReInstall) == pkgDepCache::ReInstall;};
inline VerIterator InstVerIter(pkgCache &Cache)
{return VerIterator(Cache,InstallVer);};
inline VerIterator CandidateVerIter(pkgCache &Cache)
@@ -258,7 +261,9 @@ class pkgDepCache : protected pkgCache::Namespace
virtual VerIterator GetCandidateVer(PkgIterator const &Pkg);
virtual bool IsImportantDep(DepIterator const &Dep);
-
+ virtual signed short GetPriority(PkgIterator const &Pkg);
+ virtual signed short GetPriority(PkgFileIterator const &File);
+
virtual ~Policy() {};
};
@@ -313,11 +318,10 @@ class pkgDepCache : protected pkgCache::Namespace
void Update(PkgIterator const &P);
// Count manipulators
- void AddSizes(const PkgIterator &Pkg, bool const &Invert = false);
+ void AddSizes(const PkgIterator &Pkg, bool const Invert = false);
inline void RemoveSizes(const PkgIterator &Pkg) {AddSizes(Pkg, true);};
- void AddSizes(const PkgIterator &Pkg,signed long Mult) __deprecated;
- void AddStates(const PkgIterator &Pkg,int Add = 1);
- inline void RemoveStates(const PkgIterator &Pkg) {AddStates(Pkg,-1);};
+ void AddStates(const PkgIterator &Pkg, bool const Invert = false);
+ inline void RemoveStates(const PkgIterator &Pkg) {AddStates(Pkg,true);};
public:
@@ -386,16 +390,17 @@ class pkgDepCache : protected pkgCache::Namespace
/** \name State Manipulators
*/
// @{
- void MarkKeep(PkgIterator const &Pkg, bool Soft = false,
+ bool MarkKeep(PkgIterator const &Pkg, bool Soft = false,
bool FromUser = true, unsigned long Depth = 0);
- void MarkDelete(PkgIterator const &Pkg, bool Purge = false,
+ bool MarkDelete(PkgIterator const &Pkg, bool Purge = false,
unsigned long Depth = 0, bool FromUser = true);
- void MarkInstall(PkgIterator const &Pkg,bool AutoInst = true,
+ bool MarkInstall(PkgIterator const &Pkg,bool AutoInst = true,
unsigned long Depth = 0, bool FromUser = true,
bool ForceImportantDeps = false);
+ void MarkProtected(PkgIterator const &Pkg) { PkgState[Pkg->ID].iFlags |= Protected; };
void SetReInstall(PkgIterator const &Pkg,bool To);
- void SetCandidateVersion(VerIterator TargetVer, bool const &Pseudo = true);
+ void SetCandidateVersion(VerIterator TargetVer);
bool SetCandidateRelease(pkgCache::VerIterator TargetVer,
std::string const &TargetRel);
/** Set the candidate version for dependencies too if needed.
@@ -480,10 +485,8 @@ class pkgDepCache : protected pkgCache::Namespace
virtual ~pkgDepCache();
private:
- // Helper for Update(OpProgress) to remove pseudoinstalled arch all packages
- bool RemovePseudoInstalledPkg(PkgIterator &Pkg, std::set<unsigned long> &recheck);
- bool ReInstallPseudoForGroup(unsigned long const &Grp, std::set<unsigned long> &recheck);
- bool ReInstallPseudoForGroup(pkgCache::PkgIterator const &P, std::set<unsigned long> &recheck);
+ bool IsModeChangeOk(ModeList const mode, PkgIterator const &Pkg,
+ unsigned long const Depth, bool const FromUser);
};
#endif
diff --git a/apt-pkg/edsp.cc b/apt-pkg/edsp.cc
new file mode 100644
index 000000000..4d2230613
--- /dev/null
+++ b/apt-pkg/edsp.cc
@@ -0,0 +1,564 @@
+// -*- mode: cpp; mode: fold -*-
+// Description /*{{{*/
+/* ######################################################################
+ Set of methods to help writing and reading everything needed for EDSP
+ ##################################################################### */
+ /*}}}*/
+// Include Files /*{{{*/
+#include <apt-pkg/edsp.h>
+#include <apt-pkg/error.h>
+#include <apt-pkg/configuration.h>
+#include <apt-pkg/version.h>
+#include <apt-pkg/policy.h>
+#include <apt-pkg/tagfile.h>
+
+#include <apti18n.h>
+#include <limits>
+
+#include <stdio.h>
+ /*}}}*/
+
+// we could use pkgCache::DepType and ::Priority, but these would be localized strings…
+const char * const EDSP::PrioMap[] = {0, "important", "required", "standard",
+ "optional", "extra"};
+const char * const EDSP::DepMap[] = {"", "Depends", "Pre-Depends", "Suggests",
+ "Recommends" , "Conflicts", "Replaces",
+ "Obsoletes", "Breaks", "Enhances"};
+
+// EDSP::WriteScenario - to the given file descriptor /*{{{*/
+bool EDSP::WriteScenario(pkgDepCache &Cache, FILE* output, OpProgress *Progress)
+{
+ if (Progress != NULL)
+ Progress->SubProgress(Cache.Head().VersionCount, _("Send scenario to solver"));
+ unsigned long p = 0;
+ for (pkgCache::PkgIterator Pkg = Cache.PkgBegin(); Pkg.end() == false; ++Pkg)
+ for (pkgCache::VerIterator Ver = Pkg.VersionList(); Ver.end() == false; ++Ver, ++p)
+ {
+ WriteScenarioVersion(Cache, output, Pkg, Ver);
+ WriteScenarioDependency(Cache, output, Pkg, Ver);
+ fprintf(output, "\n");
+ if (Progress != NULL && p % 100 == 0)
+ Progress->Progress(p);
+ }
+ return true;
+}
+ /*}}}*/
+// EDSP::WriteLimitedScenario - to the given file descriptor /*{{{*/
+bool EDSP::WriteLimitedScenario(pkgDepCache &Cache, FILE* output,
+ APT::PackageSet const &pkgset,
+ OpProgress *Progress)
+{
+ if (Progress != NULL)
+ Progress->SubProgress(Cache.Head().VersionCount, _("Send scenario to solver"));
+ unsigned long p = 0;
+ for (APT::PackageSet::const_iterator Pkg = pkgset.begin(); Pkg != pkgset.end(); ++Pkg, ++p)
+ for (pkgCache::VerIterator Ver = Pkg.VersionList(); Ver.end() == false; ++Ver)
+ {
+ WriteScenarioVersion(Cache, output, Pkg, Ver);
+ WriteScenarioLimitedDependency(Cache, output, Pkg, Ver, pkgset);
+ fprintf(output, "\n");
+ if (Progress != NULL && p % 100 == 0)
+ Progress->Progress(p);
+ }
+ if (Progress != NULL)
+ Progress->Done();
+ return true;
+}
+ /*}}}*/
+// EDSP::WriteScenarioVersion /*{{{*/
+void EDSP::WriteScenarioVersion(pkgDepCache &Cache, FILE* output, pkgCache::PkgIterator const &Pkg,
+ pkgCache::VerIterator const &Ver)
+{
+ fprintf(output, "Package: %s\n", Pkg.Name());
+ fprintf(output, "Architecture: %s\n", Ver.Arch());
+ fprintf(output, "Version: %s\n", Ver.VerStr());
+ if (Pkg.CurrentVer() == Ver)
+ fprintf(output, "Installed: yes\n");
+ if (Pkg->SelectedState == pkgCache::State::Hold ||
+ (Cache[Pkg].Keep() == true && Cache[Pkg].Protect() == true))
+ fprintf(output, "Hold: yes\n");
+ fprintf(output, "APT-ID: %d\n", Ver->ID);
+ fprintf(output, "Priority: %s\n", PrioMap[Ver->Priority]);
+ if ((Pkg->Flags & pkgCache::Flag::Essential) == pkgCache::Flag::Essential)
+ fprintf(output, "Essential: yes\n");
+ fprintf(output, "Section: %s\n", Ver.Section());
+ if ((Ver->MultiArch & pkgCache::Version::Allowed) == pkgCache::Version::Allowed)
+ fprintf(output, "Multi-Arch: allowed\n");
+ else if ((Ver->MultiArch & pkgCache::Version::Foreign) == pkgCache::Version::Foreign)
+ fprintf(output, "Multi-Arch: foreign\n");
+ else if ((Ver->MultiArch & pkgCache::Version::Same) == pkgCache::Version::Same)
+ fprintf(output, "Multi-Arch: same\n");
+ signed short Pin = std::numeric_limits<signed short>::min();
+ for (pkgCache::VerFileIterator File = Ver.FileList(); File.end() == false; ++File) {
+ signed short const p = Cache.GetPolicy().GetPriority(File.File());
+ if (Pin < p)
+ Pin = p;
+ }
+ fprintf(output, "APT-Pin: %d\n", Pin);
+ if (Cache.GetCandidateVer(Pkg) == Ver)
+ fprintf(output, "APT-Candidate: yes\n");
+ if ((Cache[Pkg].Flags & pkgCache::Flag::Auto) == pkgCache::Flag::Auto)
+ fprintf(output, "APT-Automatic: yes\n");
+}
+ /*}}}*/
+// EDSP::WriteScenarioDependency /*{{{*/
+void EDSP::WriteScenarioDependency(pkgDepCache &Cache, FILE* output, pkgCache::PkgIterator const &Pkg,
+ pkgCache::VerIterator const &Ver)
+{
+ std::string dependencies[pkgCache::Dep::Enhances + 1];
+ bool orGroup = false;
+ for (pkgCache::DepIterator Dep = Ver.DependsList(); Dep.end() == false; ++Dep)
+ {
+ // Ignore implicit dependencies for multiarch here
+ if (strcmp(Pkg.Arch(), Dep.TargetPkg().Arch()) != 0)
+ continue;
+ if (orGroup == false)
+ dependencies[Dep->Type].append(", ");
+ dependencies[Dep->Type].append(Dep.TargetPkg().Name());
+ if (Dep->Version != 0)
+ dependencies[Dep->Type].append(" (").append(pkgCache::CompTypeDeb(Dep->CompareOp)).append(" ").append(Dep.TargetVer()).append(")");
+ if ((Dep->CompareOp & pkgCache::Dep::Or) == pkgCache::Dep::Or)
+ {
+ dependencies[Dep->Type].append(" | ");
+ orGroup = true;
+ }
+ else
+ orGroup = false;
+ }
+ for (int i = 1; i < pkgCache::Dep::Enhances + 1; ++i)
+ if (dependencies[i].empty() == false)
+ fprintf(output, "%s: %s\n", DepMap[i], dependencies[i].c_str()+2);
+ string provides;
+ for (pkgCache::PrvIterator Prv = Ver.ProvidesList(); Prv.end() == false; ++Prv)
+ {
+ // Ignore implicit provides for multiarch here
+ if (strcmp(Pkg.Arch(), Prv.ParentPkg().Arch()) != 0 || strcmp(Pkg.Name(),Prv.Name()) == 0)
+ continue;
+ provides.append(", ").append(Prv.Name());
+ }
+ if (provides.empty() == false)
+ fprintf(output, "Provides: %s\n", provides.c_str()+2);
+}
+ /*}}}*/
+// EDSP::WriteScenarioLimitedDependency /*{{{*/
+void EDSP::WriteScenarioLimitedDependency(pkgDepCache &Cache, FILE* output,
+ pkgCache::PkgIterator const &Pkg,
+ pkgCache::VerIterator const &Ver,
+ APT::PackageSet const &pkgset)
+{
+ std::string dependencies[pkgCache::Dep::Enhances + 1];
+ bool orGroup = false;
+ for (pkgCache::DepIterator Dep = Ver.DependsList(); Dep.end() == false; ++Dep)
+ {
+ // Ignore implicit dependencies for multiarch here
+ if (strcmp(Pkg.Arch(), Dep.TargetPkg().Arch()) != 0)
+ continue;
+ if (orGroup == false)
+ {
+ if (pkgset.find(Dep.TargetPkg()) == pkgset.end())
+ continue;
+ dependencies[Dep->Type].append(", ");
+ }
+ else if (pkgset.find(Dep.TargetPkg()) == pkgset.end())
+ {
+ if ((Dep->CompareOp & pkgCache::Dep::Or) == pkgCache::Dep::Or)
+ continue;
+ dependencies[Dep->Type].erase(dependencies[Dep->Type].end()-3, dependencies[Dep->Type].end());
+ orGroup = false;
+ continue;
+ }
+ dependencies[Dep->Type].append(Dep.TargetPkg().Name());
+ if (Dep->Version != 0)
+ dependencies[Dep->Type].append(" (").append(pkgCache::CompTypeDeb(Dep->CompareOp)).append(" ").append(Dep.TargetVer()).append(")");
+ if ((Dep->CompareOp & pkgCache::Dep::Or) == pkgCache::Dep::Or)
+ {
+ dependencies[Dep->Type].append(" | ");
+ orGroup = true;
+ }
+ else
+ orGroup = false;
+ }
+ for (int i = 1; i < pkgCache::Dep::Enhances + 1; ++i)
+ if (dependencies[i].empty() == false)
+ fprintf(output, "%s: %s\n", DepMap[i], dependencies[i].c_str()+2);
+ string provides;
+ for (pkgCache::PrvIterator Prv = Ver.ProvidesList(); Prv.end() == false; ++Prv)
+ {
+ // Ignore implicit provides for multiarch here
+ if (strcmp(Pkg.Arch(), Prv.ParentPkg().Arch()) != 0 || strcmp(Pkg.Name(),Prv.Name()) == 0)
+ continue;
+ if (pkgset.find(Prv.ParentPkg()) == pkgset.end())
+ continue;
+ provides.append(", ").append(Prv.Name());
+ }
+ if (provides.empty() == false)
+ fprintf(output, "Provides: %s\n", provides.c_str()+2);
+}
+ /*}}}*/
+// EDSP::WriteRequest - to the given file descriptor /*{{{*/
+bool EDSP::WriteRequest(pkgDepCache &Cache, FILE* output, bool const Upgrade,
+ bool const DistUpgrade, bool const AutoRemove,
+ OpProgress *Progress)
+{
+ if (Progress != NULL)
+ Progress->SubProgress(Cache.Head().PackageCount, _("Send request to solver"));
+ unsigned long p = 0;
+ string del, inst;
+ for (pkgCache::PkgIterator Pkg = Cache.PkgBegin(); Pkg.end() == false; ++Pkg, ++p)
+ {
+ if (Progress != NULL && p % 100 == 0)
+ Progress->Progress(p);
+ string* req;
+ if (Cache[Pkg].Delete() == true)
+ req = &del;
+ else if (Cache[Pkg].NewInstall() == true || Cache[Pkg].Upgrade() == true)
+ req = &inst;
+ else
+ continue;
+ req->append(" ").append(Pkg.FullName());
+ }
+ fprintf(output, "Request: EDSP 0.4\n");
+ if (del.empty() == false)
+ fprintf(output, "Remove: %s\n", del.c_str()+1);
+ if (inst.empty() == false)
+ fprintf(output, "Install: %s\n", inst.c_str()+1);
+ if (Upgrade == true)
+ fprintf(output, "Upgrade: yes\n");
+ if (DistUpgrade == true)
+ fprintf(output, "Dist-Upgrade: yes\n");
+ if (AutoRemove == true)
+ fprintf(output, "Autoremove: yes\n");
+ if (_config->FindB("APT::Solver::Strict-Pinning", true) == false)
+ fprintf(output, "Strict-Pinning: no\n");
+ string solverpref("APT::Solver::");
+ solverpref.append(_config->Find("APT::Solver", "internal")).append("::Preferences");
+ if (_config->Exists(solverpref) == true)
+ fprintf(output, "Preferences: %s\n", _config->Find(solverpref,"").c_str());
+ fprintf(output, "\n");
+
+ return true;
+}
+ /*}}}*/
+// EDSP::ReadResponse - from the given file descriptor /*{{{*/
+bool EDSP::ReadResponse(int const input, pkgDepCache &Cache, OpProgress *Progress) {
+ /* We build an map id to mmap offset here
+ In theory we could use the offset as ID, but then VersionCount
+ couldn't be used to create other versionmappings anymore and it
+ would be too easy for a (buggy) solver to segfault APT… */
+ unsigned long long const VersionCount = Cache.Head().VersionCount;
+ unsigned long VerIdx[VersionCount];
+ for (pkgCache::PkgIterator P = Cache.PkgBegin(); P.end() == false; ++P) {
+ for (pkgCache::VerIterator V = P.VersionList(); V.end() == false; ++V)
+ VerIdx[V->ID] = V.Index();
+ Cache[P].Marked = true;
+ Cache[P].Garbage = false;
+ }
+
+ FileFd in;
+ in.OpenDescriptor(input, FileFd::ReadOnly);
+ pkgTagFile response(&in, 100);
+ pkgTagSection section;
+
+ while (response.Step(section) == true) {
+ std::string type;
+ if (section.Exists("Install") == true)
+ type = "Install";
+ else if (section.Exists("Remove") == true)
+ type = "Remove";
+ else if (section.Exists("Progress") == true) {
+ if (Progress != NULL) {
+ string msg = section.FindS("Message");
+ if (msg.empty() == true)
+ msg = _("Prepare for receiving solution");
+ Progress->SubProgress(100, msg, section.FindI("Percentage", 0));
+ }
+ continue;
+ } else if (section.Exists("Error") == true) {
+ std::string msg = SubstVar(SubstVar(section.FindS("Message"), "\n .\n", "\n\n"), "\n ", "\n");
+ if (msg.empty() == true) {
+ msg = _("External solver failed without a proper error message");
+ _error->Error(msg.c_str());
+ } else
+ _error->Error("External solver failed with: %s", msg.substr(0,msg.find('\n')).c_str());
+ if (Progress != NULL)
+ Progress->Done();
+ std::cerr << "The solver encountered an error of type: " << section.FindS("Error") << std::endl;
+ std::cerr << "The following information might help you to understand what is wrong:" << std::endl;
+ std::cerr << msg << std::endl << std::endl;
+ return false;
+ } else if (section.Exists("Autoremove") == true)
+ type = "Autoremove";
+ else
+ continue;
+
+ size_t const id = section.FindULL(type.c_str(), VersionCount);
+ if (id == VersionCount) {
+ _error->Warning("Unable to parse %s request with id value '%s'!", type.c_str(), section.FindS(type.c_str()).c_str());
+ continue;
+ } else if (id > Cache.Head().VersionCount) {
+ _error->Warning("ID value '%s' in %s request stanza is to high to refer to a known version!", section.FindS(type.c_str()).c_str(), type.c_str());
+ continue;
+ }
+
+ pkgCache::VerIterator Ver(Cache.GetCache(), Cache.GetCache().VerP + VerIdx[id]);
+ Cache.SetCandidateVersion(Ver);
+ if (type == "Install")
+ Cache.MarkInstall(Ver.ParentPkg(), false, 0, false);
+ else if (type == "Remove")
+ Cache.MarkDelete(Ver.ParentPkg(), false);
+ else if (type == "Autoremove") {
+ Cache[Ver.ParentPkg()].Marked = false;
+ Cache[Ver.ParentPkg()].Garbage = true;
+ }
+ }
+ return true;
+}
+ /*}}}*/
+// EDSP::ReadLine - first line from the given file descriptor /*{{{*/
+// ---------------------------------------------------------------------
+/* Little helper method to read a complete line into a string. Similar to
+ fgets but we need to use the low-level read() here as otherwise the
+ listparser will be confused later on as mixing of fgets and read isn't
+ a supported action according to the manpages and results are undefined */
+bool EDSP::ReadLine(int const input, std::string &line) {
+ char one;
+ ssize_t data = 0;
+ line.erase();
+ line.reserve(100);
+ while ((data = read(input, &one, sizeof(one))) != -1) {
+ if (data != 1)
+ continue;
+ if (one == '\n')
+ return true;
+ if (one == '\r')
+ continue;
+ if (line.empty() == true && isblank(one) != 0)
+ continue;
+ line += one;
+ }
+ return false;
+}
+ /*}}}*/
+// EDSP::StringToBool - convert yes/no to bool /*{{{*/
+// ---------------------------------------------------------------------
+/* we are not as lazy as we are in the global StringToBool as we really
+ only accept yes/no here - but we will ignore leading spaces */
+bool EDSP::StringToBool(char const *answer, bool const defValue) {
+ for (; isspace(*answer) != 0; ++answer);
+ if (strncasecmp(answer, "yes", 3) == 0)
+ return true;
+ else if (strncasecmp(answer, "no", 2) == 0)
+ return false;
+ else
+ _error->Warning("Value '%s' is not a boolean 'yes' or 'no'!", answer);
+ return defValue;
+}
+ /*}}}*/
+// EDSP::ReadRequest - first stanza from the given file descriptor /*{{{*/
+bool EDSP::ReadRequest(int const input, std::list<std::string> &install,
+ std::list<std::string> &remove, bool &upgrade,
+ bool &distUpgrade, bool &autoRemove)
+{
+ install.clear();
+ remove.clear();
+ upgrade = false;
+ distUpgrade = false;
+ autoRemove = false;
+ std::string line;
+ while (ReadLine(input, line) == true)
+ {
+ // Skip empty lines before request
+ if (line.empty() == true)
+ continue;
+ // The first Tag must be a request, so search for it
+ if (line.compare(0, 8, "Request:") != 0)
+ continue;
+
+ while (ReadLine(input, line) == true)
+ {
+ // empty lines are the end of the request
+ if (line.empty() == true)
+ return true;
+
+ std::list<std::string> *request = NULL;
+ if (line.compare(0, 8, "Install:") == 0)
+ {
+ line.erase(0, 8);
+ request = &install;
+ }
+ else if (line.compare(0, 7, "Remove:") == 0)
+ {
+ line.erase(0, 7);
+ request = &remove;
+ }
+ else if (line.compare(0, 8, "Upgrade:") == 0)
+ upgrade = EDSP::StringToBool(line.c_str() + 9, false);
+ else if (line.compare(0, 13, "Dist-Upgrade:") == 0)
+ distUpgrade = EDSP::StringToBool(line.c_str() + 14, false);
+ else if (line.compare(0, 11, "Autoremove:") == 0)
+ autoRemove = EDSP::StringToBool(line.c_str() + 12, false);
+ else
+ _error->Warning("Unknown line in EDSP Request stanza: %s", line.c_str());
+
+ if (request == NULL)
+ continue;
+ size_t end = line.length();
+ do {
+ size_t begin = line.rfind(' ');
+ if (begin == std::string::npos)
+ {
+ request->push_back(line.substr(0, end));
+ break;
+ }
+ else if (begin < end)
+ request->push_back(line.substr(begin + 1, end));
+ line.erase(begin);
+ end = line.find_last_not_of(' ');
+ } while (end != std::string::npos);
+ }
+ }
+ return false;
+}
+ /*}}}*/
+// EDSP::ApplyRequest - first stanza from the given file descriptor /*{{{*/
+bool EDSP::ApplyRequest(std::list<std::string> const &install,
+ std::list<std::string> const &remove,
+ pkgDepCache &Cache)
+{
+ for (std::list<std::string>::const_iterator i = install.begin();
+ i != install.end(); ++i) {
+ pkgCache::PkgIterator P = Cache.FindPkg(*i);
+ if (P.end() == true)
+ _error->Warning("Package %s is not known, so can't be installed", i->c_str());
+ else
+ Cache.MarkInstall(P, false);
+ }
+
+ for (std::list<std::string>::const_iterator i = remove.begin();
+ i != remove.end(); ++i) {
+ pkgCache::PkgIterator P = Cache.FindPkg(*i);
+ if (P.end() == true)
+ _error->Warning("Package %s is not known, so can't be installed", i->c_str());
+ else
+ Cache.MarkDelete(P);
+ }
+ return true;
+}
+ /*}}}*/
+// EDSP::WriteSolution - to the given file descriptor /*{{{*/
+bool EDSP::WriteSolution(pkgDepCache &Cache, FILE* output)
+{
+ bool const Debug = _config->FindB("Debug::EDSP::WriteSolution", false);
+ for (pkgCache::PkgIterator Pkg = Cache.PkgBegin(); Pkg.end() == false; ++Pkg)
+ {
+ if (Cache[Pkg].Delete() == true)
+ {
+ fprintf(output, "Remove: %d\n", Pkg.CurrentVer()->ID);
+ if (Debug == true)
+ fprintf(output, "Package: %s\nVersion: %s\n", Pkg.FullName().c_str(), Pkg.CurrentVer().VerStr());
+ }
+ else if (Cache[Pkg].NewInstall() == true || Cache[Pkg].Upgrade() == true)
+ {
+ fprintf(output, "Install: %d\n", Cache.GetCandidateVer(Pkg)->ID);
+ if (Debug == true)
+ fprintf(output, "Package: %s\nVersion: %s\n", Pkg.FullName().c_str(), Cache.GetCandidateVer(Pkg).VerStr());
+ }
+ else if (Cache[Pkg].Garbage == true)
+ {
+ fprintf(output, "Autoremove: %d\n", Pkg.CurrentVer()->ID);
+ if (Debug == true)
+ fprintf(output, "Package: %s\nVersion: %s\n", Pkg.FullName().c_str(), Pkg.CurrentVer().VerStr());
+ fprintf(stderr, "Autoremove: %s\nVersion: %s\n", Pkg.FullName().c_str(), Pkg.CurrentVer().VerStr());
+ }
+ else
+ continue;
+ fprintf(output, "\n");
+ }
+
+ return true;
+}
+ /*}}}*/
+// EDSP::WriteProgess - pulse to the given file descriptor /*{{{*/
+bool EDSP::WriteProgress(unsigned short const percent, const char* const message, FILE* output) {
+ fprintf(output, "Progress: %s\n", TimeRFC1123(time(NULL)).c_str());
+ fprintf(output, "Percentage: %d\n", percent);
+ fprintf(output, "Message: %s\n\n", message);
+ fflush(output);
+ return true;
+}
+ /*}}}*/
+// EDSP::WriteError - format an error message to be send to file descriptor /*{{{*/
+bool EDSP::WriteError(char const * const uuid, std::string const &message, FILE* output) {
+ fprintf(output, "Error: %s\n", uuid);
+ fprintf(output, "Message: %s\n\n", SubstVar(SubstVar(message, "\n\n", "\n.\n"), "\n", "\n ").c_str());
+ return true;
+}
+ /*}}}*/
+// EDSP::ExecuteSolver - fork requested solver and setup ipc pipes {{{*/
+bool EDSP::ExecuteSolver(const char* const solver, int *solver_in, int *solver_out) {
+ std::vector<std::string> const solverDirs = _config->FindVector("Dir::Bin::Solvers");
+ std::string file;
+ for (std::vector<std::string>::const_iterator dir = solverDirs.begin();
+ dir != solverDirs.end(); ++dir) {
+ file = flCombine(*dir, solver);
+ if (RealFileExists(file.c_str()) == true)
+ break;
+ file.clear();
+ }
+
+ if (file.empty() == true)
+ return _error->Error("Can't call external solver '%s' as it is not in a configured directory!", solver);
+ int external[4] = {-1, -1, -1, -1};
+ if (pipe(external) != 0 || pipe(external + 2) != 0)
+ return _error->Errno("Resolve", "Can't create needed IPC pipes for EDSP");
+ for (int i = 0; i < 4; ++i)
+ SetCloseExec(external[i], true);
+
+ pid_t Solver = ExecFork();
+ if (Solver == 0) {
+ dup2(external[0], STDIN_FILENO);
+ dup2(external[3], STDOUT_FILENO);
+ const char* calling[2] = { file.c_str(), 0 };
+ execv(calling[0], (char**) calling);
+ std::cerr << "Failed to execute solver '" << solver << "'!" << std::endl;
+ _exit(100);
+ }
+ close(external[0]);
+ close(external[3]);
+
+ if (WaitFd(external[1], true, 5) == false)
+ return _error->Errno("Resolve", "Timed out while Waiting on availability of solver stdin");
+
+ *solver_in = external[1];
+ *solver_out = external[2];
+ return true;
+}
+ /*}}}*/
+// EDSP::ResolveExternal - resolve problems by asking external for help {{{*/
+bool EDSP::ResolveExternal(const char* const solver, pkgDepCache &Cache,
+ bool const upgrade, bool const distUpgrade,
+ bool const autoRemove, OpProgress *Progress) {
+ int solver_in, solver_out;
+ if (EDSP::ExecuteSolver(solver, &solver_in, &solver_out) == false)
+ return false;
+
+ FILE* output = fdopen(solver_in, "w");
+ if (output == NULL)
+ return _error->Errno("Resolve", "fdopen on solver stdin failed");
+
+ if (Progress != NULL)
+ Progress->OverallProgress(0, 100, 5, _("Execute external solver"));
+ EDSP::WriteRequest(Cache, output, upgrade, distUpgrade, autoRemove, Progress);
+ if (Progress != NULL)
+ Progress->OverallProgress(5, 100, 20, _("Execute external solver"));
+ EDSP::WriteScenario(Cache, output, Progress);
+ fclose(output);
+
+ if (Progress != NULL)
+ Progress->OverallProgress(25, 100, 75, _("Execute external solver"));
+ if (EDSP::ReadResponse(solver_out, Cache, Progress) == false)
+ return false;
+
+ return true;
+}
+ /*}}}*/
diff --git a/apt-pkg/edsp.h b/apt-pkg/edsp.h
new file mode 100644
index 000000000..743c3f5d1
--- /dev/null
+++ b/apt-pkg/edsp.h
@@ -0,0 +1,222 @@
+// -*- mode: cpp; mode: fold -*-
+/** Description \file edsp.h {{{
+ ######################################################################
+ Set of methods to help writing and reading everything needed for EDSP
+ with the noteable exception of reading a scenario for conversion into
+ a Cache as this is handled by edsp interface for listparser and friends
+ ##################################################################### */
+ /*}}}*/
+#ifndef PKGLIB_EDSP_H
+#define PKGLIB_EDSP_H
+
+#include <apt-pkg/depcache.h>
+#include <apt-pkg/cacheset.h>
+#include <apt-pkg/progress.h>
+
+#include <string>
+
+class EDSP /*{{{*/
+{
+ // we could use pkgCache::DepType and ::Priority, but these would be localized strings…
+ static const char * const PrioMap[];
+ static const char * const DepMap[];
+
+ bool static ReadLine(int const input, std::string &line);
+ bool static StringToBool(char const *answer, bool const defValue);
+
+ void static WriteScenarioVersion(pkgDepCache &Cache, FILE* output,
+ pkgCache::PkgIterator const &Pkg,
+ pkgCache::VerIterator const &Ver);
+ void static WriteScenarioDependency(pkgDepCache &Cache, FILE* output,
+ pkgCache::PkgIterator const &Pkg,
+ pkgCache::VerIterator const &Ver);
+ void static WriteScenarioLimitedDependency(pkgDepCache &Cache, FILE* output,
+ pkgCache::PkgIterator const &Pkg,
+ pkgCache::VerIterator const &Ver,
+ APT::PackageSet const &pkgset);
+public:
+ /** \brief creates the EDSP request stanza
+ *
+ * In the EDSP protocol the first thing send to the resolver is a stanza
+ * encoding the request. This method will write this stanza by looking at
+ * the given Cache and requests the installation of all packages which were
+ * marked for installation in it (equally for remove).
+ *
+ * \param Cache in which the request is encoded
+ * \param output is written to this "file"
+ * \param upgrade is true if it is an request like apt-get upgrade
+ * \param distUpgrade is true if it is a request like apt-get dist-upgrade
+ * \param autoRemove is true if removal of unneeded packages should be performed
+ * \param Progress is an instance to report progress to
+ *
+ * \return true if request was composed successfully, otherwise false
+ */
+ bool static WriteRequest(pkgDepCache &Cache, FILE* output,
+ bool const upgrade = false,
+ bool const distUpgrade = false,
+ bool const autoRemove = false,
+ OpProgress *Progress = NULL);
+
+ /** \brief creates the scenario representing the package universe
+ *
+ * After the request all known information about a package are send
+ * to the solver. The output looks similar to a Packages or status file
+ *
+ * All packages and version included in this Cache are send, even if
+ * it doesn't make sense from an APT resolver point of view like versions
+ * with a negative pin to enable the solver to propose even that as a
+ * solution or at least to be able to give a hint what can be done to
+ * statisfy a request.
+ *
+ * \param Cache is the known package universe
+ * \param output is written to this "file"
+ * \param Progress is an instance to report progress to
+ *
+ * \return true if universe was composed successfully, otherwise false
+ */
+ bool static WriteScenario(pkgDepCache &Cache, FILE* output, OpProgress *Progress = NULL);
+
+ /** \brief creates a limited scenario representing the package universe
+ *
+ * This method works similar to #WriteScenario as it works in the same
+ * way but doesn't send the complete universe to the solver but only
+ * packages included in the pkgset which will have only dependencies
+ * on packages which are in the given set. All other dependencies will
+ * be removed, so that this method can be used to create testcases
+ *
+ * \param Cache is the known package universe
+ * \param output is written to this "file"
+ * \param pkgset is a set of packages the universe should be limited to
+ * \param Progress is an instance to report progress to
+ *
+ * \return true if universe was composed successfully, otherwise false
+ */
+ bool static WriteLimitedScenario(pkgDepCache &Cache, FILE* output,
+ APT::PackageSet const &pkgset,
+ OpProgress *Progress = NULL);
+
+ /** \brief waits and acts on the information returned from the solver
+ *
+ * This method takes care of interpreting whatever the solver sends
+ * through the standard output like a solution, progress or an error.
+ * The main thread should handle his control over to this method to
+ * wait for the solver to finish the given task
+ *
+ * \param input file descriptor with the response from the solver
+ * \param Cache the solution should be applied on if any
+ * \param Progress is an instance to report progress to
+ *
+ * \return true if a solution is found and applied correctly, otherwise false
+ */
+ bool static ReadResponse(int const input, pkgDepCache &Cache, OpProgress *Progress = NULL);
+
+ /** \brief search and read the request stanza for action later
+ *
+ * This method while ignore the input up to the point it finds the
+ * Request: line as an indicator for the Request stanza.
+ * The request is stored in the parameters install and remove then,
+ * as the cache isn't build yet as the scenario follows the request.
+ *
+ * \param input file descriptor with the edsp input for the solver
+ * \param[out] install is a list which gets populated with requested installs
+ * \param[out] remove is a list which gets populated with requested removals
+ * \param[out] upgrade is true if it is a request like apt-get upgrade
+ * \param[out] distUpgrade is true if it is a request like apt-get dist-upgrade
+ * \param[out] autoRemove is true if removal of uneeded packages should be performed
+ *
+ * \return true if the request could be found and worked on, otherwise false
+ */
+ bool static ReadRequest(int const input, std::list<std::string> &install,
+ std::list<std::string> &remove, bool &upgrade,
+ bool &distUpgrade, bool &autoRemove);
+
+ /** \brief takes the request lists and applies it on the cache
+ *
+ * The lists as created by #ReadRequest will be used to find the
+ * packages in question and mark them for install/remove.
+ * No solving is done and no auto-install/-remove.
+ *
+ * \param install is a list of packages to mark for installation
+ * \param remove is a list of packages to mark for removal
+ * \param Cache is there the markers should be set
+ *
+ * \return false if the request couldn't be applied, true otherwise
+ */
+ bool static ApplyRequest(std::list<std::string> const &install,
+ std::list<std::string> const &remove,
+ pkgDepCache &Cache);
+
+ /** \brief encodes the changes in the Cache as a EDSP solution
+ *
+ * The markers in the Cache are observed and send to given
+ * file. The solution isn't checked for consistency or alike,
+ * so even broken solutions can be written successfully,
+ * but the front-end revicing it will properly fail then.
+ *
+ * \param Cache which represents the solution
+ * \param output to write the stanzas forming the solution to
+ *
+ * \return true if solution could be written, otherwise false
+ */
+ bool static WriteSolution(pkgDepCache &Cache, FILE* output);
+
+ /** \brief sends a progress report
+ *
+ * \param percent of the solving completed
+ * \param message the solver wants the user to see
+ * \param output the front-end listens for progress report
+ */
+ bool static WriteProgress(unsigned short const percent, const char* const message, FILE* output);
+
+ /** \brief sends an error report
+ *
+ * Solvers are expected to execute successfully even if
+ * they were unable to calculate a solution for a given task.
+ * Obviously they can't send a solution through, so this
+ * methods deals with formatting an error message correctly
+ * so that the front-ends can recieve and display it.
+ *
+ * The first line of the message should be a short description
+ * of the error so it can be used for dialog titles or alike
+ *
+ * \param uuid of this error message
+ * \param message is free form text to discribe the error
+ * \param output the front-end listens for error messages
+ */
+ bool static WriteError(char const * const uuid, std::string const &message, FILE* output);
+
+
+ /** \brief executes the given solver and returns the pipe ends
+ *
+ * The given solver is executed if it can be found in one of the
+ * configured directories and setup for it is performed.
+ *
+ * \param solver to execute
+ * \param[out] solver_in will be the stdin of the solver
+ * \param[out] solver_out will be the stdout of the solver
+ *
+ * \return true if the solver could be started and the pipes
+ * are set up correctly, otherwise false and the pipes are invalid
+ */
+ bool static ExecuteSolver(const char* const solver, int *solver_in, int *solver_out);
+
+ /** \brief call an external resolver to handle the request
+ *
+ * This method wraps all the methods above to call an external solver
+ *
+ * \param solver to execute
+ * \param Cache with the problem and as universe to work in
+ * \param upgrade is true if it is a request like apt-get upgrade
+ * \param distUpgrade is true if it is a request like apt-get dist-upgrade
+ * \param autoRemove is true if unneeded packages should be removed
+ * \param Progress is an instance to report progress to
+ *
+ * \return true if the solver has successfully solved the problem,
+ * otherwise false
+ */
+ bool static ResolveExternal(const char* const solver, pkgDepCache &Cache,
+ bool const upgrade, bool const distUpgrade,
+ bool const autoRemove, OpProgress *Progress = NULL);
+};
+ /*}}}*/
+#endif
diff --git a/apt-pkg/edsp/edspindexfile.cc b/apt-pkg/edsp/edspindexfile.cc
new file mode 100644
index 000000000..f5881e663
--- /dev/null
+++ b/apt-pkg/edsp/edspindexfile.cc
@@ -0,0 +1,78 @@
+// -*- mode: cpp; mode: fold -*-
+// Description /*{{{*/
+/* ######################################################################
+ The scenario file is designed to work as an intermediate file between
+ APT and the resolver. Its on propose very similar to a dpkg status file
+ ##################################################################### */
+ /*}}}*/
+// Include Files /*{{{*/
+#include <apt-pkg/edspindexfile.h>
+#include <apt-pkg/edsplistparser.h>
+#include <apt-pkg/sourcelist.h>
+#include <apt-pkg/configuration.h>
+#include <apt-pkg/progress.h>
+#include <apt-pkg/error.h>
+#include <apt-pkg/strutl.h>
+#include <apt-pkg/acquire-item.h>
+
+#include <sys/stat.h>
+ /*}}}*/
+
+// edspIndex::edspIndex - Constructor /*{{{*/
+// ---------------------------------------------------------------------
+/* */
+edspIndex::edspIndex(string File) : debStatusIndex(File)
+{
+}
+ /*}}}*/
+// StatusIndex::Merge - Load the index file into a cache /*{{{*/
+bool edspIndex::Merge(pkgCacheGenerator &Gen,OpProgress *Prog) const
+{
+ FileFd Pkg;
+ if (File != "stdin")
+ Pkg.Open(File, FileFd::ReadOnly);
+ else
+ Pkg.OpenDescriptor(STDIN_FILENO, FileFd::ReadOnly);
+ if (_error->PendingError() == true)
+ return false;
+ edspListParser Parser(&Pkg);
+ if (_error->PendingError() == true)
+ return false;
+
+ if (Prog != NULL)
+ Prog->SubProgress(0,File);
+ if (Gen.SelectFile(File,string(),*this) == false)
+ return _error->Error("Problem with SelectFile %s",File.c_str());
+
+ // Store the IMS information
+ pkgCache::PkgFileIterator CFile = Gen.GetCurFile();
+ struct stat St;
+ if (fstat(Pkg.Fd(),&St) != 0)
+ return _error->Errno("fstat","Failed to stat");
+ CFile->Size = St.st_size;
+ CFile->mtime = St.st_mtime;
+ CFile->Archive = Gen.WriteUniqString("edsp::scenario");
+
+ if (Gen.MergeList(Parser) == false)
+ return _error->Error("Problem with MergeList %s",File.c_str());
+ return true;
+}
+ /*}}}*/
+// Index File types for APT /*{{{*/
+class edspIFType: public pkgIndexFile::Type
+{
+ public:
+ virtual pkgRecords::Parser *CreatePkgParser(pkgCache::PkgFileIterator File) const
+ {
+ // we don't have a record parser for this type as the file is not presistent
+ return NULL;
+ };
+ edspIFType() {Label = "EDSP scenario file";};
+};
+static edspIFType _apt_Universe;
+
+const pkgIndexFile::Type *edspIndex::GetType() const
+{
+ return &_apt_Universe;
+}
+ /*}}}*/
diff --git a/apt-pkg/edsp/edspindexfile.h b/apt-pkg/edsp/edspindexfile.h
new file mode 100644
index 000000000..0053388eb
--- /dev/null
+++ b/apt-pkg/edsp/edspindexfile.h
@@ -0,0 +1,28 @@
+// -*- mode: cpp; mode: fold -*-
+// Description /*{{{*/
+/* ######################################################################
+ The scenario file is designed to work as an intermediate file between
+ APT and the resolver. Its on propose very similar to a dpkg status file
+ ##################################################################### */
+ /*}}}*/
+#ifndef PKGLIB_EDSPINDEXFILE_H
+#define PKGLIB_EDSPINDEXFILE_H
+
+#include <apt-pkg/indexfile.h>
+#include <apt-pkg/debindexfile.h>
+
+class edspIndex : public debStatusIndex
+{
+ /** \brief dpointer placeholder (for later in case we need it) */
+ void *d;
+
+ public:
+
+ virtual const Type *GetType() const;
+
+ virtual bool Merge(pkgCacheGenerator &Gen,OpProgress *Prog) const;
+
+ edspIndex(string File);
+};
+
+#endif
diff --git a/apt-pkg/edsp/edsplistparser.cc b/apt-pkg/edsp/edsplistparser.cc
new file mode 100644
index 000000000..3349e8cce
--- /dev/null
+++ b/apt-pkg/edsp/edsplistparser.cc
@@ -0,0 +1,90 @@
+// -*- mode: cpp; mode: fold -*-
+// Description /*{{{*/
+/* ######################################################################
+
+ Package Cache Generator - Generator for the cache structure.
+
+ This builds the cache structure from the abstract package list parser.
+
+ ##################################################################### */
+ /*}}}*/
+// Include Files /*{{{*/
+#include <apt-pkg/edsplistparser.h>
+#include <apt-pkg/error.h>
+#include <apt-pkg/configuration.h>
+#include <apt-pkg/strutl.h>
+#include <apt-pkg/md5.h>
+#include <apt-pkg/macros.h>
+ /*}}}*/
+
+// ListParser::edspListParser - Constructor /*{{{*/
+edspListParser::edspListParser(FileFd *File, string const &Arch) : debListParser(File, Arch)
+{}
+ /*}}}*/
+// ListParser::NewVersion - Fill in the version structure /*{{{*/
+bool edspListParser::NewVersion(pkgCache::VerIterator &Ver)
+{
+ Ver->ID = Section.FindI("APT-ID", Ver->ID);
+ return debListParser::NewVersion(Ver);
+}
+ /*}}}*/
+// ListParser::Description - Return the description string /*{{{*/
+// ---------------------------------------------------------------------
+/* Sorry, no description for the resolvers… */
+string edspListParser::Description()
+{
+ return "";
+}
+string edspListParser::DescriptionLanguage()
+{
+ return "";
+}
+MD5SumValue edspListParser::Description_md5()
+{
+ return MD5SumValue("");
+}
+ /*}}}*/
+// ListParser::VersionHash - Compute a unique hash for this version /*{{{*/
+// ---------------------------------------------------------------------
+/* */
+unsigned short edspListParser::VersionHash()
+{
+ if (Section.Exists("APT-Hash") == true)
+ return Section.FindI("APT-Hash");
+ else if (Section.Exists("APT-ID") == true)
+ return Section.FindI("APT-ID");
+ return 0;
+}
+ /*}}}*/
+// ListParser::ParseStatus - Parse the status field /*{{{*/
+// ---------------------------------------------------------------------
+/* The Status: line here is not a normal dpkg one but just one which tells
+ use if the package is installed or not, where missing means not. */
+bool edspListParser::ParseStatus(pkgCache::PkgIterator &Pkg,
+ pkgCache::VerIterator &Ver)
+{
+ unsigned long state = 0;
+ if (Section.FindFlag("Hold",state,pkgCache::State::Hold) == false)
+ return false;
+ if (state != 0)
+ Pkg->SelectedState = pkgCache::State::Hold;
+
+ state = 0;
+ if (Section.FindFlag("Installed",state,pkgCache::State::Installed) == false)
+ return false;
+ if (state != 0)
+ {
+ Pkg->CurrentState = pkgCache::State::Installed;
+ Pkg->CurrentVer = Ver.Index();
+ }
+
+ return true;
+}
+ /*}}}*/
+// ListParser::LoadReleaseInfo - Load the release information /*{{{*/
+bool edspListParser::LoadReleaseInfo(pkgCache::PkgFileIterator &FileI,
+ FileFd &File, string component)
+{
+ return true;
+}
+ /*}}}*/
diff --git a/apt-pkg/edsp/edsplistparser.h b/apt-pkg/edsp/edsplistparser.h
new file mode 100644
index 000000000..ec9f09905
--- /dev/null
+++ b/apt-pkg/edsp/edsplistparser.h
@@ -0,0 +1,38 @@
+// -*- mode: cpp; mode: fold -*-
+// Description /*{{{*/
+/* ######################################################################
+
+ EDSP Package List Parser - This implements the abstract parser
+ interface for the APT specific intermediate format which is passed
+ to external resolvers
+
+ ##################################################################### */
+ /*}}}*/
+#ifndef PKGLIB_EDSPLISTPARSER_H
+#define PKGLIB_EDSPLISTPARSER_H
+
+#include <apt-pkg/deblistparser.h>
+#include <apt-pkg/pkgcachegen.h>
+#include <apt-pkg/indexfile.h>
+#include <apt-pkg/tagfile.h>
+
+class edspListParser : public debListParser
+{
+ public:
+ virtual bool NewVersion(pkgCache::VerIterator &Ver);
+ virtual string Description();
+ virtual string DescriptionLanguage();
+ virtual MD5SumValue Description_md5();
+ virtual unsigned short VersionHash();
+
+ bool LoadReleaseInfo(pkgCache::PkgFileIterator &FileI,FileFd &File,
+ string section);
+
+ edspListParser(FileFd *File, string const &Arch = "");
+
+ protected:
+ virtual bool ParseStatus(pkgCache::PkgIterator &Pkg,pkgCache::VerIterator &Ver);
+
+};
+
+#endif
diff --git a/apt-pkg/edsp/edspsystem.cc b/apt-pkg/edsp/edspsystem.cc
new file mode 100644
index 000000000..ac0bb8beb
--- /dev/null
+++ b/apt-pkg/edsp/edspsystem.cc
@@ -0,0 +1,124 @@
+// -*- mode: cpp; mode: fold -*-
+// Description /*{{{*/
+/* ######################################################################
+
+ This system provides the abstraction to use the scenario file as the
+ only source of package information to be able to feed the created file
+ back to APT for its own consumption (eat your own dogfood).
+
+ ##################################################################### */
+ /*}}}*/
+// Include Files /*{{{*/
+#include <apt-pkg/edspsystem.h>
+#include <apt-pkg/debversion.h>
+#include <apt-pkg/edspindexfile.h>
+#include <apt-pkg/configuration.h>
+#include <apt-pkg/error.h>
+#include <apt-pkg/fileutl.h>
+#include <apti18n.h>
+#include <sys/types.h>
+#include <unistd.h>
+#include <dirent.h>
+#include <errno.h>
+ /*}}}*/
+
+edspSystem edspSys;
+
+// System::debSystem - Constructor /*{{{*/
+edspSystem::edspSystem()
+{
+ StatusFile = 0;
+
+ Label = "Debian APT solver interface";
+ VS = &debVS;
+}
+ /*}}}*/
+// System::~debSystem - Destructor /*{{{*/
+edspSystem::~edspSystem()
+{
+ delete StatusFile;
+}
+ /*}}}*/
+// System::Lock - Get the lock /*{{{*/
+bool edspSystem::Lock()
+{
+ return true;
+}
+ /*}}}*/
+// System::UnLock - Drop a lock /*{{{*/
+bool edspSystem::UnLock(bool NoErrors)
+{
+ return true;
+}
+ /*}}}*/
+// System::CreatePM - Create the underlying package manager /*{{{*/
+// ---------------------------------------------------------------------
+/* we can't use edsp input as input for real installations - just a
+ simulation can work, but everything else will fail bigtime */
+pkgPackageManager *edspSystem::CreatePM(pkgDepCache *Cache) const
+{
+ return NULL;
+}
+ /*}}}*/
+// System::Initialize - Setup the configuration space.. /*{{{*/
+bool edspSystem::Initialize(Configuration &Cnf)
+{
+ Cnf.Set("Dir::State::extended_states", "/dev/null");
+ Cnf.Set("Dir::State::status","/dev/null");
+ Cnf.Set("Dir::State::lists","/dev/null");
+
+ Cnf.Set("Debug::NoLocking", "true");
+ Cnf.Set("APT::Get::Simulate", "true");
+
+ if (StatusFile) {
+ delete StatusFile;
+ StatusFile = 0;
+ }
+ return true;
+}
+ /*}}}*/
+// System::ArchiveSupported - Is a file format supported /*{{{*/
+bool edspSystem::ArchiveSupported(const char *Type)
+{
+ return false;
+}
+ /*}}}*/
+// System::Score - Determine if we should use the edsp system /*{{{*/
+signed edspSystem::Score(Configuration const &Cnf)
+{
+ if (Cnf.Find("edsp::scenario", "") == "stdin")
+ return 1000;
+ if (FileExists(Cnf.FindFile("edsp::scenario","")) == true)
+ return 1000;
+ return -1000;
+}
+ /*}}}*/
+// System::AddStatusFiles - Register the status files /*{{{*/
+bool edspSystem::AddStatusFiles(vector<pkgIndexFile *> &List)
+{
+ if (StatusFile == 0)
+ {
+ if (_config->Find("edsp::scenario", "") == "stdin")
+ StatusFile = new edspIndex("stdin");
+ else
+ StatusFile = new edspIndex(_config->FindFile("edsp::scenario"));
+ }
+ List.push_back(StatusFile);
+ return true;
+}
+ /*}}}*/
+// System::FindIndex - Get an index file for status files /*{{{*/
+bool edspSystem::FindIndex(pkgCache::PkgFileIterator File,
+ pkgIndexFile *&Found) const
+{
+ if (StatusFile == 0)
+ return false;
+ if (StatusFile->FindInCache(*File.Cache()) == File)
+ {
+ Found = StatusFile;
+ return true;
+ }
+
+ return false;
+}
+ /*}}}*/
diff --git a/apt-pkg/edsp/edspsystem.h b/apt-pkg/edsp/edspsystem.h
new file mode 100644
index 000000000..ca703fa84
--- /dev/null
+++ b/apt-pkg/edsp/edspsystem.h
@@ -0,0 +1,41 @@
+// -*- mode: cpp; mode: fold -*-
+// Description /*{{{*/
+// $Id: debsystem.h,v 1.4 2003/01/11 07:16:33 jgg Exp $
+/* ######################################################################
+
+ System - Debian version of the System Class
+
+ ##################################################################### */
+ /*}}}*/
+#ifndef PKGLIB_EDSPSYSTEM_H
+#define PKGLIB_EDSPSYSTEM_H
+
+#include <apt-pkg/pkgsystem.h>
+
+class edspIndex;
+class edspSystem : public pkgSystem
+{
+ /** \brief dpointer placeholder (for later in case we need it) */
+ void *d;
+
+ edspIndex *StatusFile;
+
+ public:
+
+ virtual bool Lock();
+ virtual bool UnLock(bool NoErrors = false);
+ virtual pkgPackageManager *CreatePM(pkgDepCache *Cache) const;
+ virtual bool Initialize(Configuration &Cnf);
+ virtual bool ArchiveSupported(const char *Type);
+ virtual signed Score(Configuration const &Cnf);
+ virtual bool AddStatusFiles(std::vector<pkgIndexFile *> &List);
+ virtual bool FindIndex(pkgCache::PkgFileIterator File,
+ pkgIndexFile *&Found) const;
+
+ edspSystem();
+ ~edspSystem();
+};
+
+extern edspSystem edspSys;
+
+#endif
diff --git a/apt-pkg/indexcopy.cc b/apt-pkg/indexcopy.cc
index c2ee1c347..064fb007c 100644
--- a/apt-pkg/indexcopy.cc
+++ b/apt-pkg/indexcopy.cc
@@ -75,7 +75,7 @@ bool IndexCopy::CopyPackages(string CDROM,string Name,vector<string> &List,
// Open the package file
FileFd Pkg;
- if (FileExists(*I + GetFileName()) == true)
+ if (RealFileExists(*I + GetFileName()) == true)
{
Pkg.Open(*I + GetFileName(),FileFd::ReadOnly);
FileSize = Pkg.Size();
@@ -532,7 +532,7 @@ bool SigVerify::Verify(string prefix, string file, indexRecords *MetaIndex)
// we skip non-existing files in the verifcation to support a cdrom
// with no Packages file (just a Package.gz), see LP: #255545
// (non-existing files are not considered a error)
- if(!FileExists(prefix+file))
+ if(!RealFileExists(prefix+file))
{
_error->Warning(_("Skipping nonexistent file %s"), string(prefix+file).c_str());
return true;
@@ -601,7 +601,7 @@ bool SigVerify::CopyAndVerify(string CDROM,string Name,vector<string> &SigList,
string const release = *I+"Release";
// a Release.gpg without a Release should never happen
- if(FileExists(release) == false)
+ if(RealFileExists(release) == false)
{
delete MetaIndex;
continue;
@@ -681,7 +681,7 @@ bool SigVerify::RunGPGV(std::string const &File, std::string const &FileGPG,
std::vector<string> keyrings;
if (DirectoryExists(trustedPath))
keyrings = GetListOfFilesInDir(trustedPath, "gpg", false, true);
- if (FileExists(trustedFile) == true)
+ if (RealFileExists(trustedFile) == true)
keyrings.push_back(trustedFile);
std::vector<const char *> Args;
@@ -788,7 +788,7 @@ bool TranslationsCopy::CopyTranslations(string CDROM,string Name, /*{{{*/
// Open the package file
FileFd Pkg;
- if (FileExists(*I) == true)
+ if (RealFileExists(*I) == true)
{
Pkg.Open(*I,FileFd::ReadOnly);
FileSize = Pkg.Size();
diff --git a/apt-pkg/indexcopy.h b/apt-pkg/indexcopy.h
index 6fcd3b8ce..277fb561c 100644
--- a/apt-pkg/indexcopy.h
+++ b/apt-pkg/indexcopy.h
@@ -24,6 +24,9 @@ class pkgCdromStatus;
class IndexCopy /*{{{*/
{
+ /** \brief dpointer placeholder (for later in case we need it) */
+ void *d;
+
protected:
pkgTagSection *Section;
@@ -55,7 +58,6 @@ class PackageCopy : public IndexCopy /*{{{*/
virtual const char *GetFileName() {return "Packages";};
virtual const char *Type() {return "Package";};
- public:
};
/*}}}*/
class SourceCopy : public IndexCopy /*{{{*/
@@ -67,7 +69,6 @@ class SourceCopy : public IndexCopy /*{{{*/
virtual const char *GetFileName() {return "Sources";};
virtual const char *Type() {return "Source";};
- public:
};
/*}}}*/
class TranslationsCopy /*{{{*/
@@ -82,6 +83,9 @@ class TranslationsCopy /*{{{*/
/*}}}*/
class SigVerify /*{{{*/
{
+ /** \brief dpointer placeholder (for later in case we need it) */
+ void *d;
+
bool Verify(string prefix,string file, indexRecords *records);
bool CopyMetaIndex(string CDROM, string CDName,
string prefix, string file);
diff --git a/apt-pkg/init.cc b/apt-pkg/init.cc
index a30f27844..66b0119e6 100644
--- a/apt-pkg/init.cc
+++ b/apt-pkg/init.cc
@@ -72,7 +72,9 @@ bool pkgInitConfig(Configuration &Cnf)
Cnf.Set("Dir::Etc::preferencesparts","preferences.d");
Cnf.Set("Dir::Etc::trusted", "trusted.gpg");
Cnf.Set("Dir::Etc::trustedparts","trusted.gpg.d");
+
Cnf.Set("Dir::Bin::methods","/usr/lib/apt/methods");
+ Cnf.Set("Dir::Bin::solvers::","/usr/lib/apt/solvers");
Cnf.Set("Dir::Media::MountPath","/media/apt");
// State
@@ -85,9 +87,6 @@ bool pkgInitConfig(Configuration &Cnf)
Cnf.Set("Dir::Ignore-Files-Silently::", "\\.bak$");
Cnf.Set("Dir::Ignore-Files-Silently::", "\\.dpkg-[a-z]+$");
- // Translation
- Cnf.Set("APT::Acquire::Translation", "environment");
-
// Default cdrom mount point
Cnf.Set("Acquire::cdrom::mount", "/media/cdrom/");
diff --git a/apt-pkg/init.h b/apt-pkg/init.h
index 15a1165b9..6b92dd200 100644
--- a/apt-pkg/init.h
+++ b/apt-pkg/init.h
@@ -22,8 +22,8 @@
// Non-ABI-Breaks should only increase RELEASE number.
// See also buildlib/libversion.mak
#define APT_PKG_MAJOR 4
-#define APT_PKG_MINOR 10
-#define APT_PKG_RELEASE 1
+#define APT_PKG_MINOR 11
+#define APT_PKG_RELEASE 0
extern const char *pkgVersion;
extern const char *pkgLibVersion;
diff --git a/apt-pkg/makefile b/apt-pkg/makefile
index b94b88257..b11e35250 100644
--- a/apt-pkg/makefile
+++ b/apt-pkg/makefile
@@ -3,7 +3,7 @@ BASE=..
SUBDIR=apt-pkg
# Header location
-SUBDIRS = deb contrib
+SUBDIRS = deb edsp contrib
HEADER_TARGETDIRS = apt-pkg
# Bring in the default rules
@@ -39,7 +39,7 @@ SOURCE+= pkgcache.cc version.cc depcache.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
+ aptconfiguration.cc cachefilter.cc cacheset.cc edsp.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 \
@@ -47,7 +47,7 @@ HEADERS+= algorithms.h depcache.h pkgcachegen.h cacheiterators.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
+ cachefilter.h cacheset.h edsp.h
# Source code for the debian specific components
# In theory the deb headers do not need to be exported..
@@ -57,6 +57,10 @@ SOURCE+= deb/deblistparser.cc deb/debrecords.cc deb/dpkgpm.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))
include $(LIBRARY_H)
diff --git a/apt-pkg/orderlist.cc b/apt-pkg/orderlist.cc
index a53854a26..19661fc2d 100644
--- a/apt-pkg/orderlist.cc
+++ b/apt-pkg/orderlist.cc
@@ -128,10 +128,6 @@ bool pkgOrderList::IsMissing(PkgIterator Pkg)
if (FileList[Pkg->ID].empty() == false)
return false;
- // Missing Pseudo packages are missing if the real package is missing
- if (pkgCache::VerIterator(Cache, Cache[Pkg].CandidateVer).Pseudo() == true)
- return IsMissing(Pkg.Group().FindPkg("all"));
-
return true;
}
/*}}}*/
@@ -494,7 +490,7 @@ bool pkgOrderList::VisitRProvides(DepFunc F,VerIterator Ver)
bool Res = true;
for (PrvIterator P = Ver.ProvidesList(); P.end() == false; P++)
Res &= (this->*F)(P.ParentPkg().RevDependsList());
- return true;
+ return Res;
}
/*}}}*/
// OrderList::VisitProvides - Visit all of the providing packages /*{{{*/
@@ -511,15 +507,11 @@ bool pkgOrderList::VisitProvides(DepIterator D,bool Critical)
if (Cache[Pkg].Keep() == true && Pkg.State() == PkgIterator::NeedsNothing)
continue;
- if (D->Type != pkgCache::Dep::Conflicts &&
- D->Type != pkgCache::Dep::DpkgBreaks &&
- D->Type != pkgCache::Dep::Obsoletes &&
+ if (D.IsNegative() == false &&
Cache[Pkg].InstallVer != *I)
continue;
- if ((D->Type == pkgCache::Dep::Conflicts ||
- D->Type == pkgCache::Dep::DpkgBreaks ||
- D->Type == pkgCache::Dep::Obsoletes) &&
+ if (D.IsNegative() == true &&
(Version *)Pkg.CurrentVer() != *I)
continue;
@@ -651,9 +643,7 @@ bool pkgOrderList::DepUnPackCrit(DepIterator D)
{
/* Forward critical dependencies MUST be correct before the
package can be unpacked. */
- if (D->Type != pkgCache::Dep::Conflicts &&
- D->Type != pkgCache::Dep::DpkgBreaks &&
- D->Type != pkgCache::Dep::Obsoletes &&
+ if (D.IsNegative() == false &&
D->Type != pkgCache::Dep::PreDepends)
continue;
@@ -1081,10 +1071,14 @@ bool pkgOrderList::CheckDep(DepIterator D)
/* Conflicts requires that all versions are not present, depends
just needs one */
- if (D->Type != pkgCache::Dep::Conflicts &&
- D->Type != pkgCache::Dep::DpkgBreaks &&
- D->Type != pkgCache::Dep::Obsoletes)
+ if (D.IsNegative() == false)
{
+ // ignore provides by older versions of this package
+ if (((D.Reverse() == false && Pkg == D.ParentPkg()) ||
+ (D.Reverse() == true && Pkg == D.TargetPkg())) &&
+ Cache[Pkg].InstallVer != *I)
+ continue;
+
/* Try to find something that does not have the after flag set
if at all possible */
if (IsFlag(Pkg,After) == true)
diff --git a/apt-pkg/packagemanager.cc b/apt-pkg/packagemanager.cc
index cff34058c..1ae09347a 100644
--- a/apt-pkg/packagemanager.cc
+++ b/apt-pkg/packagemanager.cc
@@ -81,9 +81,6 @@ bool pkgPackageManager::GetArchives(pkgAcquire *Owner,pkgSourceList *Sources,
if (List->IsNow(Pkg) == false)
continue;
- if (pkgCache::VerIterator(Cache, Cache[Pkg].CandidateVer).Pseudo() == true)
- continue;
-
new pkgAcqArchive(Owner,Sources,Recs,Cache[Pkg].InstVerIter(Cache),
FileNames[Pkg->ID]);
}
@@ -281,9 +278,7 @@ bool pkgPackageManager::ConfigureAll()
{
PkgIterator Pkg(Cache,*I);
- if (ConfigurePkgs == true &&
- pkgCache::VerIterator(Cache, Cache[Pkg].CandidateVer).Pseudo() == false &&
- Configure(Pkg) == false)
+ if (ConfigurePkgs == true && Configure(Pkg) == false)
return false;
List->Flag(Pkg,pkgOrderList::Configured,pkgOrderList::States);
@@ -318,14 +313,23 @@ bool pkgPackageManager::SmartConfigure(PkgIterator Pkg)
{
PkgIterator Pkg(Cache,*I);
- if (ConfigurePkgs == true &&
- pkgCache::VerIterator(Cache, Cache[Pkg].CandidateVer).Pseudo() == false &&
- Configure(Pkg) == false)
+ if (ConfigurePkgs == true && Configure(Pkg) == false)
return false;
List->Flag(Pkg,pkgOrderList::Configured,pkgOrderList::States);
}
+ if ((Cache[Pkg].InstVerIter(Cache)->MultiArch & pkgCache::Version::Same) == pkgCache::Version::Same)
+ for (PkgIterator P = Pkg.Group().PackageList();
+ P.end() == false; P = Pkg.Group().NextPkg(P))
+ {
+ if (Pkg == P || List->IsFlag(P,pkgOrderList::Configured) == true ||
+ Cache[P].InstallVer == 0 || (P.CurrentVer() == Cache[P].InstallVer &&
+ (Cache[Pkg].iFlags & pkgDepCache::ReInstall) != pkgDepCache::ReInstall))
+ continue;
+ SmartConfigure(P);
+ }
+
// Sanity Check
if (List->IsFlag(Pkg,pkgOrderList::Configured) == false)
return _error->Error(_("Could not perform immediate configuration on '%s'. "
@@ -473,10 +477,7 @@ bool pkgPackageManager::SmartRemove(PkgIterator Pkg)
List->Flag(Pkg,pkgOrderList::Configured,pkgOrderList::States);
- if (pkgCache::VerIterator(Cache, Cache[Pkg].CandidateVer).Pseudo() == false)
- return Remove(Pkg,(Cache[Pkg].iFlags & pkgDepCache::Purge) == pkgDepCache::Purge);
- else
- return SmartRemove(Pkg.Group().FindPkg("all"));
+ return Remove(Pkg,(Cache[Pkg].iFlags & pkgDepCache::Purge) == pkgDepCache::Purge);
return true;
}
/*}}}*/
@@ -485,21 +486,28 @@ bool pkgPackageManager::SmartRemove(PkgIterator Pkg)
/* This performs the task of handling pre-depends. */
bool pkgPackageManager::SmartUnPack(PkgIterator Pkg)
{
+ return SmartUnPack(Pkg, true);
+}
+bool pkgPackageManager::SmartUnPack(PkgIterator Pkg, bool const Immediate)
+{
// Check if it is already unpacked
if (Pkg.State() == pkgCache::PkgIterator::NeedsConfigure &&
Cache[Pkg].Keep() == true)
{
List->Flag(Pkg,pkgOrderList::UnPacked,pkgOrderList::States);
- if (List->IsFlag(Pkg,pkgOrderList::Immediate) == true)
+ if (Immediate == true &&
+ List->IsFlag(Pkg,pkgOrderList::Immediate) == true)
if (SmartConfigure(Pkg) == false)
return _error->Error(_("Could not perform immediate configuration on already unpacked '%s'. "
"Please see man 5 apt.conf under APT::Immediate-Configure for details."),Pkg.Name());
return true;
}
+ VerIterator const instVer = Cache[Pkg].InstVerIter(Cache);
+
/* See if this packages install version has any predependencies
that are not met by 'now' packages. */
- for (DepIterator D = Cache[Pkg].InstVerIter(Cache).DependsList();
+ for (DepIterator D = instVer.DependsList();
D.end() == false; )
{
// Compute a single dependency element (glob or)
@@ -585,33 +593,32 @@ bool pkgPackageManager::SmartUnPack(PkgIterator Pkg)
// Check for reverse conflicts.
if (CheckRConflicts(Pkg,Pkg.RevDependsList(),
- Cache[Pkg].InstVerIter(Cache).VerStr()) == false)
+ instVer.VerStr()) == false)
return false;
- for (PrvIterator P = Cache[Pkg].InstVerIter(Cache).ProvidesList();
+ for (PrvIterator P = instVer.ProvidesList();
P.end() == false; P++)
CheckRConflicts(Pkg,P.ParentPkg().RevDependsList(),P.ProvideVersion());
- if (pkgCache::VerIterator(Cache, Cache[Pkg].CandidateVer).Pseudo() == false)
- {
- if(Install(Pkg,FileNames[Pkg->ID]) == false)
- return false;
- } else {
- // Pseudo packages will not be unpacked - instead we will do this
- // for the "real" package, but only once and if it is already
- // configured we don't need to unpack it again…
- PkgIterator const P = Pkg.Group().FindPkg("all");
- if (List->IsFlag(P,pkgOrderList::UnPacked) != true &&
- List->IsFlag(P,pkgOrderList::Configured) != true &&
- P.State() != pkgCache::PkgIterator::NeedsNothing) {
- if (SmartUnPack(P) == false)
- return false;
- }
- }
List->Flag(Pkg,pkgOrderList::UnPacked,pkgOrderList::States);
-
+
+ if ((instVer->MultiArch & pkgCache::Version::Same) == pkgCache::Version::Same)
+ for (PkgIterator P = Pkg.Group().PackageList();
+ P.end() == false; P = Pkg.Group().NextPkg(P))
+ {
+ if (Pkg == P || List->IsFlag(P,pkgOrderList::UnPacked) == true ||
+ Cache[P].InstallVer == 0 || (P.CurrentVer() == Cache[P].InstallVer &&
+ (Cache[Pkg].iFlags & pkgDepCache::ReInstall) != pkgDepCache::ReInstall))
+ continue;
+ SmartUnPack(P, false);
+ }
+
+ if(Install(Pkg,FileNames[Pkg->ID]) == false)
+ return false;
+
// Perform immedate configuration of the package.
- if (List->IsFlag(Pkg,pkgOrderList::Immediate) == true)
+ if (Immediate == true &&
+ List->IsFlag(Pkg,pkgOrderList::Immediate) == true)
if (SmartConfigure(Pkg) == false)
return _error->Error(_("Could not perform immediate configuration on '%s'. "
"Please see man 5 apt.conf under APT::Immediate-Configure for details. (%d)"),Pkg.Name(),2);
diff --git a/apt-pkg/packagemanager.h b/apt-pkg/packagemanager.h
index efd2cfac6..053b4dc13 100644
--- a/apt-pkg/packagemanager.h
+++ b/apt-pkg/packagemanager.h
@@ -69,7 +69,9 @@ class pkgPackageManager : protected pkgCache::Namespace
// Install helpers
bool ConfigureAll();
bool SmartConfigure(PkgIterator Pkg);
+ //FIXME: merge on abi break
bool SmartUnPack(PkgIterator Pkg);
+ bool SmartUnPack(PkgIterator Pkg, bool const Immediate);
bool SmartRemove(PkgIterator Pkg);
bool EarlyRemove(PkgIterator Pkg);
diff --git a/apt-pkg/pkgcache.cc b/apt-pkg/pkgcache.cc
index 616d400a2..951caeb78 100644
--- a/apt-pkg/pkgcache.cc
+++ b/apt-pkg/pkgcache.cc
@@ -211,12 +211,18 @@ pkgCache::PkgIterator pkgCache::SingleArchFindPkg(const string &Name)
// ---------------------------------------------------------------------
/* Returns 0 on error, pointer to the package otherwise */
pkgCache::PkgIterator pkgCache::FindPkg(const string &Name) {
- if (MultiArchCache() == false)
- return SingleArchFindPkg(Name);
size_t const found = Name.find(':');
if (found == string::npos)
- return FindPkg(Name, "native");
+ {
+ if (MultiArchCache() == false)
+ return SingleArchFindPkg(Name);
+ else
+ return FindPkg(Name, "native");
+ }
string const Arch = Name.substr(found+1);
+ /* Beware: This is specialcased to handle pkg:any in dependencies as
+ these are linked to virtual pkg:any named packages with all archs.
+ If you want any arch from a given pkg, use FindPkg(pkg,arch) */
if (Arch == "any")
return FindPkg(Name, "any");
return FindPkg(Name.substr(0, found), Arch);
@@ -228,7 +234,7 @@ pkgCache::PkgIterator pkgCache::FindPkg(const string &Name) {
pkgCache::PkgIterator pkgCache::FindPkg(const string &Name, string const &Arch) {
if (MultiArchCache() == false) {
if (Arch == "native" || Arch == "all" || Arch == "any" ||
- Arch == _config->Find("APT::Architecture"))
+ Arch == NativeArch())
return SingleArchFindPkg(Name);
else
return PkgIterator(*this,0);
@@ -317,22 +323,22 @@ pkgCache::PkgIterator pkgCache::GrpIterator::FindPkg(string Arch) const {
if (unlikely(IsGood() == false || S->FirstPackage == 0))
return PkgIterator(*Owner, 0);
- static string const myArch = _config->Find("APT::Architecture");
+ /* If we accept any package we simply return the "first"
+ package in this group (the last one added). */
+ if (Arch == "any")
+ return PkgIterator(*Owner, Owner->PkgP + S->FirstPackage);
+
+ char const* const myArch = Owner->NativeArch();
/* Most of the time the package for our native architecture is
the one we add at first to the cache, but this would be the
last one we check, so we do it now. */
- if (Arch == "native" || Arch == myArch) {
- Arch = myArch;
+ if (Arch == "native" || Arch == myArch || Arch == "all") {
pkgCache::Package *Pkg = Owner->PkgP + S->LastPackage;
- if (stringcasecmp(Arch, Owner->StrP + Pkg->Arch) == 0)
+ if (strcasecmp(myArch, Owner->StrP + Pkg->Arch) == 0)
return PkgIterator(*Owner, Pkg);
+ Arch = myArch;
}
- /* If we accept any package we simply return the "first"
- package in this group (the last one added). */
- if (Arch == "any")
- return PkgIterator(*Owner, Owner->PkgP + S->FirstPackage);
-
/* Iterate over the list to find the matching arch
unfortunately this list includes "package noise"
(= different packages with same calculated hash),
@@ -503,7 +509,8 @@ std::string pkgCache::PkgIterator::FullName(bool const &Pretty) const
{
string fullname = Name();
if (Pretty == false ||
- (strcmp(Arch(), "all") != 0 && _config->Find("APT::Architecture") != Arch()))
+ (strcmp(Arch(), "all") != 0 &&
+ strcmp(Owner->NativeArch(), Arch()) != 0))
return fullname.append(":").append(Arch());
return fullname;
}
@@ -514,15 +521,24 @@ std::string pkgCache::PkgIterator::FullName(bool const &Pretty) const
conflicts (including dpkg's Breaks fields). */
bool pkgCache::DepIterator::IsCritical() const
{
- if (S->Type == pkgCache::Dep::Conflicts ||
- S->Type == pkgCache::Dep::DpkgBreaks ||
- S->Type == pkgCache::Dep::Obsoletes ||
+ if (IsNegative() == true ||
S->Type == pkgCache::Dep::Depends ||
S->Type == pkgCache::Dep::PreDepends)
return true;
return false;
}
/*}}}*/
+// DepIterator::IsNegative - Returns true if the dep is a negative one /*{{{*/
+// ---------------------------------------------------------------------
+/* Some dependencies are positive like Depends and Recommends, others
+ are negative like Conflicts which can and should be handled differently */
+bool pkgCache::DepIterator::IsNegative() const
+{
+ return S->Type == Dep::DpkgBreaks ||
+ S->Type == Dep::Conflicts ||
+ S->Type == Dep::Obsoletes;
+}
+ /*}}}*/
// DepIterator::SmartTargetPkg - Resolve dep target pointers w/provides /*{{{*/
// ---------------------------------------------------------------------
/* This intellegently looks at dep target packages and tries to figure
@@ -600,9 +616,7 @@ pkgCache::Version **pkgCache::DepIterator::AllTargets() const
if (Owner->VS->CheckDep(I.VerStr(),S->CompareOp,TargetVer()) == false)
continue;
- if ((S->Type == pkgCache::Dep::Conflicts ||
- S->Type == pkgCache::Dep::DpkgBreaks ||
- S->Type == pkgCache::Dep::Obsoletes) &&
+ if (IsNegative() == true &&
ParentPkg() == I.ParentPkg())
continue;
@@ -617,9 +631,7 @@ pkgCache::Version **pkgCache::DepIterator::AllTargets() const
if (Owner->VS->CheckDep(I.ProvideVersion(),S->CompareOp,TargetVer()) == false)
continue;
- if ((S->Type == pkgCache::Dep::Conflicts ||
- S->Type == pkgCache::Dep::DpkgBreaks ||
- S->Type == pkgCache::Dep::Obsoletes) &&
+ if (IsNegative() == true &&
ParentPkg() == I.OwnerPkg())
continue;
@@ -737,23 +749,6 @@ bool pkgCache::VerIterator::Automatic() const
return false;
}
/*}}}*/
-// VerIterator::Pseudo - Check if this version is a pseudo one /*{{{*/
-// ---------------------------------------------------------------------
-/* Sometimes you have the need to express dependencies with versions
- which doesn't really exist or exist multiply times for "different"
- packages. We need these versions for dependency resolution but they
- are a problem everytime we need to download/install something. */
-bool pkgCache::VerIterator::Pseudo() const
-{
- if (S->MultiArch == pkgCache::Version::All &&
- strcmp(Arch(true),"all") != 0)
- {
- GrpIterator const Grp = ParentPkg().Group();
- return (Grp->LastPackage != Grp->FirstPackage);
- }
- return false;
-}
- /*}}}*/
// VerIterator::NewestFile - Return the newest file version relation /*{{{*/
// ---------------------------------------------------------------------
/* This looks at the version numbers associated with all of the sources
diff --git a/apt-pkg/pkgcache.h b/apt-pkg/pkgcache.h
index 82a69b2ca..280f37bca 100644
--- a/apt-pkg/pkgcache.h
+++ b/apt-pkg/pkgcache.h
@@ -215,6 +215,7 @@ class pkgCache /*{{{*/
private:
bool MultiArchEnabled;
PkgIterator SingleArchFindPkg(const string &Name);
+ inline char const * const NativeArch() const;
};
/*}}}*/
// Header structure /*{{{*/
@@ -499,15 +500,18 @@ struct pkgCache::Version
map_ptrloc VerStr; // StringItem
/** \brief section this version is filled in */
map_ptrloc Section; // StringItem
+
+ /** \brief Multi-Arch capabilities of a package version */
+ enum VerMultiArch { None = 0, /*!< is the default and doesn't trigger special behaviour */
+ All = (1<<0), /*!< will cause that Ver.Arch() will report "all" */
+ Foreign = (1<<1), /*!< can satisfy dependencies in another architecture */
+ Same = (1<<2), /*!< can be co-installed with itself from other architectures */
+ Allowed = (1<<3) /*!< other packages are allowed to depend on thispkg:any */ };
/** \brief stores the MultiArch capabilities of this version
- None is the default and doesn't trigger special behaviour,
- Foreign means that this version can fulfill dependencies even
- if it is built for another architecture as the requester.
- Same indicates that builds for different architectures can
- be co-installed on the system and All is the marker for a
- version with the Architecture: all. */
- enum {None, All, Foreign, Same, Allowed} MultiArch;
+ Flags used are defined in pkgCache::Version::VerMultiArch
+ */
+ unsigned char MultiArch;
/** \brief references all the PackageFile's that this version came from
@@ -649,6 +653,11 @@ struct pkgCache::StringItem
map_ptrloc NextItem; // StringItem
};
/*}}}*/
+
+
+inline char const * const pkgCache::NativeArch() const
+ { return StrP + HeaderP->Architecture; };
+
#include <apt-pkg/cacheiterators.h>
inline pkgCache::GrpIterator pkgCache::GrpBegin()
diff --git a/apt-pkg/pkgcachegen.cc b/apt-pkg/pkgcachegen.cc
index ed35174bb..8e088ba68 100644
--- a/apt-pkg/pkgcachegen.cc
+++ b/apt-pkg/pkgcachegen.cc
@@ -178,23 +178,12 @@ bool pkgCacheGenerator::MergeList(ListParser &List,
if (PackageName.empty() == true)
return false;
- /* As we handle Arch all packages as architecture bounded
- we add all information to every (simulated) arch package */
- std::vector<string> genArch;
- if (List.ArchitectureAll() == true) {
- genArch = APT::Configuration::getArchitectures();
- if (genArch.size() != 1)
- genArch.push_back("all");
- } else
- genArch.push_back(List.Architecture());
-
- for (std::vector<string>::const_iterator arch = genArch.begin();
- arch != genArch.end(); ++arch)
- {
+ string const Arch = List.Architecture();
+
// Get a pointer to the package structure
pkgCache::PkgIterator Pkg;
Dynamic<pkgCache::PkgIterator> DynPkg(Pkg);
- if (NewPackage(Pkg, PackageName, *arch) == false)
+ if (NewPackage(Pkg, PackageName, Arch) == false)
return _error->Error(_("Error occurred while processing %s (NewPackage)"),PackageName.c_str());
Counter++;
if (Counter % 100 == 0 && Progress != 0)
@@ -351,7 +340,6 @@ bool pkgCacheGenerator::MergeList(ListParser &List,
if ((*LastDesc == 0 && _error->PendingError()) || NewFileDesc(Desc,List) == false)
return _error->Error(_("Error occurred while processing %s (NewFileDesc2)"),PackageName.c_str());
- }
}
FoundFileDeps |= List.HasFileDeps();
@@ -491,7 +479,8 @@ bool pkgCacheGenerator::NewPackage(pkgCache::PkgIterator &Pkg,const string &Name
// Set the name, arch and the ID
Pkg->Name = Grp->Name;
Pkg->Group = Grp.Index();
- map_ptrloc const idxArch = WriteUniqString(Arch.c_str());
+ // all is mapped to the native architecture
+ map_ptrloc const idxArch = (Arch == "all") ? Cache.HeaderP->Architecture : WriteUniqString(Arch.c_str());
if (unlikely(idxArch == 0))
return false;
Pkg->Arch = idxArch;
@@ -638,27 +627,22 @@ bool pkgCacheGenerator::FinishCache(OpProgress *Progress)
Dynamic<pkgCache::PkgIterator> DynP(P);
for (; P.end() != true; P = G.NextPkg(P))
{
- if (strcmp(P.Arch(),"all") == 0)
- continue;
pkgCache::PkgIterator allPkg;
Dynamic<pkgCache::PkgIterator> DynallPkg(allPkg);
pkgCache::VerIterator V = P.VersionList();
Dynamic<pkgCache::VerIterator> DynV(V);
for (; V.end() != true; V++)
{
- string const Arch = V.Arch(true);
+ char const * const Arch = P.Arch();
map_ptrloc *OldDepLast = NULL;
/* MultiArch handling introduces a lot of implicit Dependencies:
- MultiArch: same → Co-Installable if they have the same version
- Architecture: all → Need to be Co-Installable for internal reasons
- All others conflict with all other group members */
- bool const coInstall = (V->MultiArch == pkgCache::Version::All ||
- V->MultiArch == pkgCache::Version::Same);
- if (V->MultiArch == pkgCache::Version::All && allPkg.end() == true)
- allPkg = G.FindPkg("all");
+ bool const coInstall = ((V->MultiArch & pkgCache::Version::Same) == pkgCache::Version::Same);
for (vector<string>::const_iterator A = archs.begin(); A != archs.end(); ++A)
{
- if (*A == Arch)
+ if (Arch == 0 || *A == Arch)
continue;
/* We allow only one installed arch at the time
per group, therefore each group member conflicts
@@ -677,13 +661,6 @@ bool pkgCacheGenerator::FinishCache(OpProgress *Progress)
NewDepends(D, V, V.VerStr(),
pkgCache::Dep::NotEquals, pkgCache::Dep::DpkgBreaks,
OldDepLast);
- if (V->MultiArch == pkgCache::Version::All)
- {
- // Depend on ${self}:all which does depend on nothing
- NewDepends(allPkg, V, V.VerStr(),
- pkgCache::Dep::Equals, pkgCache::Dep::Depends,
- OldDepLast);
- }
} else {
// Conflicts: ${self}:other
NewDepends(D, V, "",
@@ -806,7 +783,8 @@ bool pkgCacheGenerator::ListParser::NewProvides(pkgCache::VerIterator &Ver,
pkgCache &Cache = Owner->Cache;
// We do not add self referencing provides
- if (Ver.ParentPkg().Name() == PkgName && PkgArch == Ver.Arch(true))
+ if (Ver.ParentPkg().Name() == PkgName && (PkgArch == Ver.ParentPkg().Arch() ||
+ (PkgArch == "all" && strcmp((Cache.StrP + Cache.HeaderP->Architecture), Ver.ParentPkg().Arch()) == 0)))
return true;
// Get a structure
diff --git a/apt-pkg/pkgrecords.h b/apt-pkg/pkgrecords.h
index 2d994211d..78e39e577 100644
--- a/apt-pkg/pkgrecords.h
+++ b/apt-pkg/pkgrecords.h
@@ -28,12 +28,13 @@ class pkgRecords /*{{{*/
class Parser;
private:
+ /** \brief dpointer placeholder (for later in case we need it) */
+ void *d;
pkgCache &Cache;
std::vector<Parser *>Files;
- public:
-
+ public:
// Lookup function
Parser &Lookup(pkgCache::VerFileIterator const &Ver);
Parser &Lookup(pkgCache::DescFileIterator const &Desc);
diff --git a/apt-pkg/policy.cc b/apt-pkg/policy.cc
index 5427271b6..be96d4c84 100644
--- a/apt-pkg/policy.cc
+++ b/apt-pkg/policy.cc
@@ -152,13 +152,6 @@ pkgCache::VerIterator pkgPolicy::GetCandidateVer(pkgCache::PkgIterator const &Pk
{
/* Lets see if this version is the installed version */
bool instVer = (Pkg.CurrentVer() == Ver);
- if (Ver.Pseudo() == true && instVer == false)
- {
- pkgCache::PkgIterator const allPkg = Ver.ParentPkg().Group().FindPkg("all");
- if (allPkg->CurrentVer != 0 && allPkg.CurrentVer()->Hash == Ver->Hash &&
- strcmp(allPkg.CurVersion(), Ver.VerStr()) == 0)
- instVer = true;
- }
for (pkgCache::VerFileIterator VF = Ver.FileList(); VF.end() == false; VF++)
{
@@ -217,35 +210,71 @@ void pkgPolicy::CreatePin(pkgVersionMatch::MatchType Type,string Name,
{
if (Name.empty() == true)
{
- Pin *P = &*Defaults.insert(Defaults.end(),PkgPin());
+ Pin *P = &*Defaults.insert(Defaults.end(),Pin());
P->Type = Type;
P->Priority = Priority;
P->Data = Data;
return;
}
- // Get a spot to put the pin
- pkgCache::GrpIterator Grp = Cache->FindGrp(Name);
- for (pkgCache::PkgIterator Pkg = Grp.FindPkg("any");
- Pkg.end() != true; Pkg = Grp.NextPkg(Pkg))
+ size_t found = Name.rfind(':');
+ string Arch;
+ if (found != string::npos) {
+ Arch = Name.substr(found+1);
+ Name.erase(found);
+ }
+
+ // Allow pinning by wildcards
+ // TODO: Maybe we should always prefer specific pins over non-
+ // specific ones.
+ if (Name[0] == '/' || Name.find_first_of("*[?") != string::npos)
{
- Pin *P = 0;
- if (Pkg.end() == false)
- P = Pins + Pkg->ID;
- else
- {
- // Check the unmatched table
- for (vector<PkgPin>::iterator I = Unmatched.begin();
- I != Unmatched.end() && P == 0; I++)
- if (I->Pkg == Name)
- P = &*I;
+ pkgVersionMatch match(Data, Type);
+ for (pkgCache::GrpIterator G = Cache->GrpBegin(); G.end() != true; ++G)
+ if (match.ExpressionMatches(Name, G.Name()))
+ {
+ if (Arch.empty() == false)
+ CreatePin(Type, string(G.Name()).append(":").append(Arch), Data, Priority);
+ else
+ CreatePin(Type, G.Name(), Data, Priority);
+ }
+ return;
+ }
- if (P == 0)
- P = &*Unmatched.insert(Unmatched.end(),PkgPin());
- }
+ // find the package (group) this pin applies to
+ pkgCache::GrpIterator Grp;
+ pkgCache::PkgIterator Pkg;
+ if (Arch.empty() == false)
+ Pkg = Cache->FindPkg(Name, Arch);
+ else {
+ Grp = Cache->FindGrp(Name);
+ if (Grp.end() == false)
+ Pkg = Grp.PackageList();
+ }
+
+ if (Pkg.end() == true)
+ {
+ PkgPin *P = &*Unmatched.insert(Unmatched.end(),PkgPin(Name));
+ if (Arch.empty() == false)
+ P->Pkg.append(":").append(Arch);
+ P->Type = Type;
+ P->Priority = Priority;
+ P->Data = Data;
+ return;
+ }
+
+ for (; Pkg.end() != true; Pkg = Grp.NextPkg(Pkg))
+ {
+ Pin *P = Pins + Pkg->ID;
+ // the first specific stanza for a package is the ruler,
+ // all others need to be ignored
+ if (P->Type != pkgVersionMatch::None)
+ P = &*Unmatched.insert(Unmatched.end(),PkgPin(Pkg.FullName()));
P->Type = Type;
P->Priority = Priority;
P->Data = Data;
+ if (Grp.end() == true)
+ break;
}
}
/*}}}*/
@@ -277,6 +306,10 @@ signed short pkgPolicy::GetPriority(pkgCache::PkgIterator const &Pkg)
return 0;
}
+signed short pkgPolicy::GetPriority(pkgCache::PkgFileIterator const &File)
+{
+ return PFPriority[File->ID];
+}
/*}}}*/
// PreferenceSection class - Overriding the default TrimRecord method /*{{{*/
// ---------------------------------------------------------------------
diff --git a/apt-pkg/policy.h b/apt-pkg/policy.h
index f8b2678de..92d32728f 100644
--- a/apt-pkg/policy.h
+++ b/apt-pkg/policy.h
@@ -55,6 +55,7 @@ class pkgPolicy : public pkgDepCache::Policy
struct PkgPin : Pin
{
string Pkg;
+ PkgPin(string const &Pkg) : Pin(), Pkg(Pkg) {};
};
Pin *Pins;
@@ -69,14 +70,13 @@ class pkgPolicy : public pkgDepCache::Policy
// Things for manipulating pins
void CreatePin(pkgVersionMatch::MatchType Type,string Pkg,
string Data,signed short Priority);
- inline signed short GetPriority(pkgCache::PkgFileIterator const &File)
- {return PFPriority[File->ID];};
- signed short GetPriority(pkgCache::PkgIterator const &Pkg);
pkgCache::VerIterator GetMatch(pkgCache::PkgIterator const &Pkg);
// Things for the cache interface.
virtual pkgCache::VerIterator GetCandidateVer(pkgCache::PkgIterator const &Pkg);
- virtual bool IsImportantDep(pkgCache::DepIterator const &Dep) {return pkgDepCache::Policy::IsImportantDep(Dep);};
+ virtual signed short GetPriority(pkgCache::PkgIterator const &Pkg);
+ virtual signed short GetPriority(pkgCache::PkgFileIterator const &File);
+
bool InitDefaults();
pkgPolicy(pkgCache *Owner);
diff --git a/apt-pkg/srcrecords.h b/apt-pkg/srcrecords.h
index a49533864..8a78d7711 100644
--- a/apt-pkg/srcrecords.h
+++ b/apt-pkg/srcrecords.h
@@ -79,6 +79,8 @@ class pkgSrcRecords
};
private:
+ /** \brief dpointer placeholder (for later in case we need it) */
+ void *d;
// The list of files and the current parser pointer
vector<Parser*> Files;
@@ -93,7 +95,7 @@ class pkgSrcRecords
Parser *Find(const char *Package,bool const &SrcOnly = false);
pkgSrcRecords(pkgSourceList &List);
- ~pkgSrcRecords();
+ virtual ~pkgSrcRecords();
};
#endif
diff --git a/apt-pkg/tagfile.cc b/apt-pkg/tagfile.cc
index b7245073d..a8f04b23a 100644
--- a/apt-pkg/tagfile.cc
+++ b/apt-pkg/tagfile.cc
@@ -24,26 +24,40 @@
using std::string;
+class pkgTagFilePrivate
+{
+public:
+ pkgTagFilePrivate(FileFd *pFd, unsigned long Size) : Fd(*pFd), Size(Size)
+ {
+ }
+ FileFd &Fd;
+ char *Buffer;
+ char *Start;
+ char *End;
+ bool Done;
+ unsigned long iOffset;
+ unsigned long Size;
+};
+
// TagFile::pkgTagFile - Constructor /*{{{*/
// ---------------------------------------------------------------------
/* */
-pkgTagFile::pkgTagFile(FileFd *pFd,unsigned long Size) :
- Fd(*pFd),
- Size(Size)
+pkgTagFile::pkgTagFile(FileFd *pFd,unsigned long Size)
{
- if (Fd.IsOpen() == false)
+ d = new pkgTagFilePrivate(pFd, Size);
+
+ if (d->Fd.IsOpen() == false)
{
- Buffer = 0;
- Start = End = Buffer = 0;
- Done = true;
- iOffset = 0;
+ d->Start = d->End = d->Buffer = 0;
+ d->Done = true;
+ d->iOffset = 0;
return;
}
- Buffer = new char[Size];
- Start = End = Buffer;
- Done = false;
- iOffset = 0;
+ d->Buffer = new char[Size];
+ d->Start = d->End = d->Buffer;
+ d->Done = false;
+ d->iOffset = 0;
Fill();
}
/*}}}*/
@@ -52,7 +66,14 @@ pkgTagFile::pkgTagFile(FileFd *pFd,unsigned long Size) :
/* */
pkgTagFile::~pkgTagFile()
{
- delete [] Buffer;
+ delete [] d->Buffer;
+ delete d;
+}
+ /*}}}*/
+// TagFile::Offset - Return the current offset in the buffer /*{{{*/
+unsigned long pkgTagFile::Offset()
+{
+ return d->iOffset;
}
/*}}}*/
// TagFile::Resize - Resize the internal buffer /*{{{*/
@@ -63,22 +84,22 @@ pkgTagFile::~pkgTagFile()
bool pkgTagFile::Resize()
{
char *tmp;
- unsigned long EndSize = End - Start;
+ unsigned long EndSize = d->End - d->Start;
// fail is the buffer grows too big
- if(Size > 1024*1024+1)
+ if(d->Size > 1024*1024+1)
return false;
// get new buffer and use it
- tmp = new char[2*Size];
- memcpy(tmp, Buffer, Size);
- Size = Size*2;
- delete [] Buffer;
- Buffer = tmp;
+ tmp = new char[2*d->Size];
+ memcpy(tmp, d->Buffer, d->Size);
+ d->Size = d->Size*2;
+ delete [] d->Buffer;
+ d->Buffer = tmp;
// update the start/end pointers to the new buffer
- Start = Buffer;
- End = Start + EndSize;
+ d->Start = d->Buffer;
+ d->End = d->Start + EndSize;
return true;
}
/*}}}*/
@@ -90,20 +111,20 @@ bool pkgTagFile::Resize()
*/
bool pkgTagFile::Step(pkgTagSection &Tag)
{
- while (Tag.Scan(Start,End - Start) == false)
+ while (Tag.Scan(d->Start,d->End - d->Start) == false)
{
if (Fill() == false)
return false;
- if(Tag.Scan(Start,End - Start))
+ if(Tag.Scan(d->Start,d->End - d->Start))
break;
if (Resize() == false)
return _error->Error(_("Unable to parse package file %s (1)"),
- Fd.Name().c_str());
+ d->Fd.Name().c_str());
}
- Start += Tag.size();
- iOffset += Tag.size();
+ d->Start += Tag.size();
+ d->iOffset += Tag.size();
Tag.Trim();
return true;
@@ -115,37 +136,37 @@ bool pkgTagFile::Step(pkgTagSection &Tag)
then fills the rest from the file */
bool pkgTagFile::Fill()
{
- unsigned long EndSize = End - Start;
+ unsigned long EndSize = d->End - d->Start;
unsigned long Actual = 0;
- memmove(Buffer,Start,EndSize);
- Start = Buffer;
- End = Buffer + EndSize;
+ memmove(d->Buffer,d->Start,EndSize);
+ d->Start = d->Buffer;
+ d->End = d->Buffer + EndSize;
- if (Done == false)
+ if (d->Done == false)
{
// See if only a bit of the file is left
- if (Fd.Read(End,Size - (End - Buffer),&Actual) == false)
+ if (d->Fd.Read(d->End, d->Size - (d->End - d->Buffer),&Actual) == false)
return false;
- if (Actual != Size - (End - Buffer))
- Done = true;
- End += Actual;
+ if (Actual != d->Size - (d->End - d->Buffer))
+ d->Done = true;
+ d->End += Actual;
}
- if (Done == true)
+ if (d->Done == true)
{
if (EndSize <= 3 && Actual == 0)
return false;
- if (Size - (End - Buffer) < 4)
+ if (d->Size - (d->End - d->Buffer) < 4)
return true;
// Append a double new line if one does not exist
unsigned int LineCount = 0;
- for (const char *E = End - 1; E - End < 6 && (*E == '\n' || *E == '\r'); E--)
+ for (const char *E = d->End - 1; E - d->End < 6 && (*E == '\n' || *E == '\r'); E--)
if (*E == '\n')
LineCount++;
for (; LineCount < 2; LineCount++)
- *End++ = '\n';
+ *d->End++ = '\n';
return true;
}
@@ -160,33 +181,33 @@ bool pkgTagFile::Fill()
bool pkgTagFile::Jump(pkgTagSection &Tag,unsigned long Offset)
{
// We are within a buffer space of the next hit..
- if (Offset >= iOffset && iOffset + (End - Start) > Offset)
+ if (Offset >= d->iOffset && d->iOffset + (d->End - d->Start) > Offset)
{
- unsigned long Dist = Offset - iOffset;
- Start += Dist;
- iOffset += Dist;
+ unsigned long Dist = Offset - d->iOffset;
+ d->Start += Dist;
+ d->iOffset += Dist;
return Step(Tag);
}
// Reposition and reload..
- iOffset = Offset;
- Done = false;
- if (Fd.Seek(Offset) == false)
+ d->iOffset = Offset;
+ d->Done = false;
+ if (d->Fd.Seek(Offset) == false)
return false;
- End = Start = Buffer;
+ d->End = d->Start = d->Buffer;
if (Fill() == false)
return false;
- if (Tag.Scan(Start,End - Start) == true)
+ if (Tag.Scan(d->Start, d->End - d->Start) == true)
return true;
// This appends a double new line (for the real eof handling)
if (Fill() == false)
return false;
- if (Tag.Scan(Start,End - Start) == false)
- return _error->Error(_("Unable to parse package file %s (2)"),Fd.Name().c_str());
+ if (Tag.Scan(d->Start, d->End - d->Start) == false)
+ return _error->Error(_("Unable to parse package file %s (2)"),d->Fd.Name().c_str());
return true;
}
diff --git a/apt-pkg/tagfile.h b/apt-pkg/tagfile.h
index 61491aa04..23f5c57e6 100644
--- a/apt-pkg/tagfile.h
+++ b/apt-pkg/tagfile.h
@@ -23,16 +23,16 @@
#include <apt-pkg/fileutl.h>
#include <stdio.h>
-
+
class pkgTagSection
{
const char *Section;
-
// We have a limit of 256 tags per section.
unsigned int Indexes[256];
unsigned int AlphaIndexes[0x100];
-
unsigned int TagCount;
+ // dpointer placeholder (for later in case we need it)
+ void *d;
/* This very simple hash function for the last 8 letters gives
very good performance on the debian package files */
@@ -44,7 +44,6 @@ class pkgTagSection
return Res & 0xFF;
}
-
protected:
const char *Stop;
@@ -80,17 +79,13 @@ class pkgTagSection
};
pkgTagSection() : Section(0), Stop(0) {};
+ virtual ~pkgTagSection() {};
};
+class pkgTagFilePrivate;
class pkgTagFile
{
- FileFd &Fd;
- char *Buffer;
- char *Start;
- char *End;
- bool Done;
- unsigned long iOffset;
- unsigned long Size;
+ pkgTagFilePrivate *d;
bool Fill();
bool Resize();
@@ -98,11 +93,11 @@ class pkgTagFile
public:
bool Step(pkgTagSection &Section);
- inline unsigned long Offset() {return iOffset;};
+ unsigned long Offset();
bool Jump(pkgTagSection &Tag,unsigned long Offset);
pkgTagFile(FileFd *F,unsigned long Size = 32*1024);
- ~pkgTagFile();
+ virtual ~pkgTagFile();
};
/* This is the list of things to rewrite. The rewriter
diff --git a/apt-pkg/vendor.h b/apt-pkg/vendor.h
index 2d39fd15f..df229737a 100644
--- a/apt-pkg/vendor.h
+++ b/apt-pkg/vendor.h
@@ -4,11 +4,12 @@
#include <vector>
#include <map>
+#include <apt-pkg/macros.h>
using std::string;
// A class representing a particular software provider.
-class Vendor
+class __deprecated Vendor
{
public:
struct Fingerprint
diff --git a/apt-pkg/vendorlist.cc b/apt-pkg/vendorlist.cc
index 92ff38894..48ac12cee 100644
--- a/apt-pkg/vendorlist.cc
+++ b/apt-pkg/vendorlist.cc
@@ -1,8 +1,13 @@
-#include <apt-pkg/vendorlist.h>
#include <apt-pkg/fileutl.h>
#include <apt-pkg/error.h>
#include <apti18n.h>
+#if __GNUC__ >= 4
+ #pragma GCC diagnostic ignored "-Wdeprecated-declarations"
+#endif
+
+#include <apt-pkg/vendorlist.h>
+
pkgVendorList::~pkgVendorList()
{
for (vector<const Vendor *>::const_iterator I = VendorList.begin();
@@ -143,3 +148,7 @@ const Vendor* pkgVendorList::FindVendor(const std::vector<string> GPGVOutput) /*
return NULL;
}
/*}}}*/
+
+#if __GNUC__ >= 4
+ #pragma GCC diagnostic warning "-Wdeprecated-declarations"
+#endif
diff --git a/apt-pkg/vendorlist.h b/apt-pkg/vendorlist.h
index ff2f4ed5d..eaeecb173 100644
--- a/apt-pkg/vendorlist.h
+++ b/apt-pkg/vendorlist.h
@@ -17,12 +17,13 @@
#include <vector>
#include <apt-pkg/vendor.h>
#include <apt-pkg/configuration.h>
+#include <apt-pkg/macros.h>
using std::string;
using std::vector;
-class pkgVendorList
+class __deprecated pkgVendorList
{
protected:
vector<Vendor const *> VendorList;