summaryrefslogtreecommitdiff
path: root/apt-pkg/deb
diff options
context:
space:
mode:
Diffstat (limited to 'apt-pkg/deb')
-rw-r--r--apt-pkg/deb/debindexfile.cc63
-rw-r--r--apt-pkg/deb/debindexfile.h15
-rw-r--r--apt-pkg/deb/deblistparser.cc289
-rw-r--r--apt-pkg/deb/deblistparser.h25
-rw-r--r--apt-pkg/deb/debmetaindex.cc286
-rw-r--r--apt-pkg/deb/debmetaindex.h28
-rw-r--r--apt-pkg/deb/debrecords.cc12
-rw-r--r--apt-pkg/deb/debsrcrecords.cc5
-rw-r--r--apt-pkg/deb/debsrcrecords.h6
-rw-r--r--apt-pkg/deb/debsystem.cc12
-rw-r--r--apt-pkg/deb/debversion.cc18
-rw-r--r--apt-pkg/deb/dpkgpm.cc322
-rw-r--r--apt-pkg/deb/dpkgpm.h22
13 files changed, 853 insertions, 250 deletions
diff --git a/apt-pkg/deb/debindexfile.cc b/apt-pkg/deb/debindexfile.cc
index 3b11ad2eb..5e6db3f38 100644
--- a/apt-pkg/deb/debindexfile.cc
+++ b/apt-pkg/deb/debindexfile.cc
@@ -149,9 +149,12 @@ unsigned long debSourcesIndex::Size() const
// PackagesIndex::debPackagesIndex - Contructor /*{{{*/
// ---------------------------------------------------------------------
/* */
-debPackagesIndex::debPackagesIndex(string URI,string Dist,string Section,bool Trusted) :
- pkgIndexFile(Trusted), URI(URI), Dist(Dist), Section(Section)
+debPackagesIndex::debPackagesIndex(string const &URI, string const &Dist, string const &Section,
+ bool const &Trusted, string const &Arch) :
+ pkgIndexFile(Trusted), URI(URI), Dist(Dist), Section(Section), Architecture(Arch)
{
+ if (Architecture == "native")
+ Architecture = _config->Find("APT::Architecture");
}
/*}}}*/
// PackagesIndex::ArchiveInfo - Short version of the archive url /*{{{*/
@@ -171,6 +174,8 @@ string debPackagesIndex::ArchiveInfo(pkgCache::VerIterator Ver) const
Res += " ";
Res += Ver.ParentPkg().Name();
Res += " ";
+ Res += Ver.Arch();
+ Res += " ";
Res += Ver.VerStr();
return Res;
}
@@ -204,6 +209,8 @@ string debPackagesIndex::Info(const char *Type) const
else
Info += Dist + '/' + Section;
Info += " ";
+ Info += Architecture;
+ Info += " ";
Info += Type;
return Info;
}
@@ -227,7 +234,7 @@ string debPackagesIndex::IndexURI(const char *Type) const
}
else
Res = URI + "dists/" + Dist + '/' + Section +
- "/binary-" + _config->Find("APT::Architecture") + '/';
+ "/binary-" + Architecture + '/';
Res += Type;
return Res;
@@ -255,21 +262,22 @@ unsigned long debPackagesIndex::Size() const
// PackagesIndex::Merge - Load the index file into a cache /*{{{*/
// ---------------------------------------------------------------------
/* */
-bool debPackagesIndex::Merge(pkgCacheGenerator &Gen,OpProgress &Prog) const
+bool debPackagesIndex::Merge(pkgCacheGenerator &Gen,OpProgress *Prog) const
{
string PackageFile = IndexFile("Packages");
FileFd Pkg(PackageFile,FileFd::ReadOnly);
- debListParser Parser(&Pkg);
+ debListParser Parser(&Pkg, Architecture);
if (_error->PendingError() == true)
return _error->Error("Problem opening %s",PackageFile.c_str());
-
- Prog.SubProgress(0,Info("Packages"));
+ if (Prog != NULL)
+ Prog->SubProgress(0,Info("Packages"));
::URI Tmp(URI);
if (Gen.SelectFile(PackageFile,Tmp.Host,*this) == false)
return _error->Error("Problem with SelectFile %s",PackageFile.c_str());
// Store the IMS information
pkgCache::PkgFileIterator File = Gen.GetCurFile();
+ pkgCacheGenerator::Dynamic<pkgCache::PkgFileIterator> DynFile(File);
struct stat St;
if (fstat(Pkg.Fd(),&St) != 0)
return _error->Errno("fstat","Failed to stat");
@@ -329,10 +337,11 @@ pkgCache::PkgFileIterator debPackagesIndex::FindInCache(pkgCache &Cache) const
// TranslationsIndex::debTranslationsIndex - Contructor /*{{{*/
// ---------------------------------------------------------------------
/* */
-debTranslationsIndex::debTranslationsIndex(string URI,string Dist,string Section) :
- pkgIndexFile(true), URI(URI), Dist(Dist), Section(Section)
-{
-}
+debTranslationsIndex::debTranslationsIndex(string URI,string Dist,string Section,
+ char const * const Translation) :
+ pkgIndexFile(true), URI(URI), Dist(Dist), Section(Section),
+ Language(Translation)
+{}
/*}}}*/
// TranslationIndex::Trans* - Return the URI to the translation files /*{{{*/
// ---------------------------------------------------------------------
@@ -365,8 +374,8 @@ string debTranslationsIndex::IndexURI(const char *Type) const
bool debTranslationsIndex::GetIndexes(pkgAcquire *Owner) const
{
if (TranslationsAvailable()) {
- string TranslationFile = "Translation-" + LanguageCode();
- new pkgAcqIndexTrans(Owner, IndexURI(LanguageCode().c_str()),
+ string const TranslationFile = string("Translation-").append(Language);
+ new pkgAcqIndexTrans(Owner, IndexURI(Language),
Info(TranslationFile.c_str()),
TranslationFile);
}
@@ -385,7 +394,7 @@ string debTranslationsIndex::Describe(bool Short) const
snprintf(S,sizeof(S),"%s",Info(TranslationFile().c_str()).c_str());
else
snprintf(S,sizeof(S),"%s (%s)",Info(TranslationFile().c_str()).c_str(),
- IndexFile(LanguageCode().c_str()).c_str());
+ IndexFile(Language).c_str());
return S;
}
/*}}}*/
@@ -407,20 +416,20 @@ string debTranslationsIndex::Info(const char *Type) const
return Info;
}
/*}}}*/
-bool debTranslationsIndex::HasPackages() const
+bool debTranslationsIndex::HasPackages() const /*{{{*/
{
if(!TranslationsAvailable())
return false;
- return FileExists(IndexFile(LanguageCode().c_str()));
+ return FileExists(IndexFile(Language));
}
-
+ /*}}}*/
// TranslationsIndex::Exists - Check if the index is available /*{{{*/
// ---------------------------------------------------------------------
/* */
bool debTranslationsIndex::Exists() const
{
- return FileExists(IndexFile(LanguageCode().c_str()));
+ return FileExists(IndexFile(Language));
}
/*}}}*/
// TranslationsIndex::Size - Return the size of the index /*{{{*/
@@ -429,7 +438,7 @@ bool debTranslationsIndex::Exists() const
unsigned long debTranslationsIndex::Size() const
{
struct stat S;
- if (stat(IndexFile(LanguageCode().c_str()).c_str(),&S) != 0)
+ if (stat(IndexFile(Language).c_str(),&S) != 0)
return 0;
return S.st_size;
}
@@ -437,10 +446,10 @@ unsigned long debTranslationsIndex::Size() const
// TranslationsIndex::Merge - Load the index file into a cache /*{{{*/
// ---------------------------------------------------------------------
/* */
-bool debTranslationsIndex::Merge(pkgCacheGenerator &Gen,OpProgress &Prog) const
+bool debTranslationsIndex::Merge(pkgCacheGenerator &Gen,OpProgress *Prog) const
{
// Check the translation file, if in use
- string TranslationFile = IndexFile(LanguageCode().c_str());
+ string TranslationFile = IndexFile(Language);
if (TranslationsAvailable() && FileExists(TranslationFile))
{
FileFd Trans(TranslationFile,FileFd::ReadOnly);
@@ -448,7 +457,8 @@ bool debTranslationsIndex::Merge(pkgCacheGenerator &Gen,OpProgress &Prog) const
if (_error->PendingError() == true)
return false;
- Prog.SubProgress(0, Info(TranslationFile.c_str()));
+ if (Prog != NULL)
+ Prog->SubProgress(0, Info(TranslationFile.c_str()));
if (Gen.SelectFile(TranslationFile,string(),*this) == false)
return _error->Error("Problem with SelectFile %s",TranslationFile.c_str());
@@ -472,7 +482,7 @@ bool debTranslationsIndex::Merge(pkgCacheGenerator &Gen,OpProgress &Prog) const
/* */
pkgCache::PkgFileIterator debTranslationsIndex::FindInCache(pkgCache &Cache) const
{
- string FileName = IndexFile(LanguageCode().c_str());
+ string FileName = IndexFile(Language);
pkgCache::PkgFileIterator File = Cache.FileBegin();
for (; File.end() == false; File++)
@@ -521,7 +531,7 @@ unsigned long debStatusIndex::Size() const
// StatusIndex::Merge - Load the index file into a cache /*{{{*/
// ---------------------------------------------------------------------
/* */
-bool debStatusIndex::Merge(pkgCacheGenerator &Gen,OpProgress &Prog) const
+bool debStatusIndex::Merge(pkgCacheGenerator &Gen,OpProgress *Prog) const
{
FileFd Pkg(File,FileFd::ReadOnly);
if (_error->PendingError() == true)
@@ -529,8 +539,9 @@ bool debStatusIndex::Merge(pkgCacheGenerator &Gen,OpProgress &Prog) const
debListParser Parser(&Pkg);
if (_error->PendingError() == true)
return false;
-
- Prog.SubProgress(0,File);
+
+ if (Prog != NULL)
+ Prog->SubProgress(0,File);
if (Gen.SelectFile(File,string(),*this,pkgCache::Flag::NotSource) == false)
return _error->Error("Problem with SelectFile %s",File.c_str());
diff --git a/apt-pkg/deb/debindexfile.h b/apt-pkg/deb/debindexfile.h
index b0012c96b..b5085992d 100644
--- a/apt-pkg/deb/debindexfile.h
+++ b/apt-pkg/deb/debindexfile.h
@@ -35,7 +35,7 @@ class debStatusIndex : public pkgIndexFile
virtual bool Exists() const;
virtual bool HasPackages() const {return true;};
virtual unsigned long Size() const;
- virtual bool Merge(pkgCacheGenerator &Gen,OpProgress &Prog) const;
+ virtual bool Merge(pkgCacheGenerator &Gen,OpProgress *Prog) const;
virtual pkgCache::PkgFileIterator FindInCache(pkgCache &Cache) const;
debStatusIndex(string File);
@@ -46,6 +46,7 @@ class debPackagesIndex : public pkgIndexFile
string URI;
string Dist;
string Section;
+ string Architecture;
string Info(const char *Type) const;
string IndexFile(const char *Type) const;
@@ -66,10 +67,11 @@ class debPackagesIndex : public pkgIndexFile
virtual bool Exists() const;
virtual bool HasPackages() const {return true;};
virtual unsigned long Size() const;
- virtual bool Merge(pkgCacheGenerator &Gen,OpProgress &Prog) const;
+ virtual bool Merge(pkgCacheGenerator &Gen,OpProgress *Prog) const;
virtual pkgCache::PkgFileIterator FindInCache(pkgCache &Cache) const;
- debPackagesIndex(string URI,string Dist,string Section,bool Trusted);
+ debPackagesIndex(string const &URI, string const &Dist, string const &Section,
+ bool const &Trusted, string const &Arch = "native");
};
class debTranslationsIndex : public pkgIndexFile
@@ -77,12 +79,13 @@ class debTranslationsIndex : public pkgIndexFile
string URI;
string Dist;
string Section;
+ const char * const Language;
string Info(const char *Type) const;
string IndexFile(const char *Type) const;
string IndexURI(const char *Type) const;
- inline string TranslationFile() const {return "Translation-" + LanguageCode();};
+ inline string TranslationFile() const {return string("Translation-").append(Language);};
public:
@@ -96,10 +99,10 @@ class debTranslationsIndex : public pkgIndexFile
virtual bool Exists() const;
virtual bool HasPackages() const;
virtual unsigned long Size() const;
- virtual bool Merge(pkgCacheGenerator &Gen,OpProgress &Prog) const;
+ virtual bool Merge(pkgCacheGenerator &Gen,OpProgress *Prog) const;
virtual pkgCache::PkgFileIterator FindInCache(pkgCache &Cache) const;
- debTranslationsIndex(string URI,string Dist,string Section);
+ debTranslationsIndex(string URI,string Dist,string Section, char const * const Language);
};
class debSourcesIndex : public pkgIndexFile
diff --git a/apt-pkg/deb/deblistparser.cc b/apt-pkg/deb/deblistparser.cc
index 25b0953e0..2cfeb23e9 100644
--- a/apt-pkg/deb/deblistparser.cc
+++ b/apt-pkg/deb/deblistparser.cc
@@ -13,11 +13,13 @@
#include <apt-pkg/deblistparser.h>
#include <apt-pkg/error.h>
#include <apt-pkg/configuration.h>
+#include <apt-pkg/aptconfiguration.h>
#include <apt-pkg/strutl.h>
#include <apt-pkg/crc-16.h>
#include <apt-pkg/md5.h>
#include <apt-pkg/macros.h>
+#include <fnmatch.h>
#include <ctype.h>
/*}}}*/
@@ -30,10 +32,15 @@ static debListParser::WordList PrioList[] = {{"important",pkgCache::State::Impor
// ListParser::debListParser - Constructor /*{{{*/
// ---------------------------------------------------------------------
-/* */
-debListParser::debListParser(FileFd *File) : Tags(File)
-{
- Arch = _config->Find("APT::architecture");
+/* Provide an architecture and only this one and "all" will be accepted
+ in Step(), if no Architecture is given we will accept every arch
+ we would accept in general with checkArchitecture() */
+debListParser::debListParser(FileFd *File, string const &Arch) : Tags(File),
+ Arch(Arch) {
+ if (Arch == "native")
+ this->Arch = _config->Find("APT::Architecture");
+ Architectures = APT::Configuration::getArchitectures();
+ MultiArchEnabled = Architectures.size() > 1;
}
/*}}}*/
// ListParser::UniqFindTagWrite - Find the tag and write a unq string /*{{{*/
@@ -51,14 +58,41 @@ unsigned long debListParser::UniqFindTagWrite(const char *Tag)
// ListParser::Package - Return the package name /*{{{*/
// ---------------------------------------------------------------------
/* This is to return the name of the package this section describes */
-string debListParser::Package()
-{
- string Result = Section.FindS("Package");
- if (Result.empty() == true)
+string debListParser::Package() {
+ string const Result = Section.FindS("Package");
+ if(unlikely(Result.empty() == true))
_error->Error("Encountered a section with no Package: header");
return Result;
}
/*}}}*/
+// 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. */
+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;
+}
+ /*}}}*/
+// ListParser::ArchitectureAll /*{{{*/
+// ---------------------------------------------------------------------
+/* */
+bool debListParser::ArchitectureAll() {
+ return Section.FindS("Architecture") == "all";
+}
+ /*}}}*/
// ListParser::Version - Return the version string /*{{{*/
// ---------------------------------------------------------------------
/* This is to return the string describing the version in debian form,
@@ -72,17 +106,39 @@ string debListParser::Version()
// ListParser::NewVersion - Fill in the version structure /*{{{*/
// ---------------------------------------------------------------------
/* */
-bool debListParser::NewVersion(pkgCache::VerIterator Ver)
+bool debListParser::NewVersion(pkgCache::VerIterator &Ver)
{
// Parse the section
Ver->Section = UniqFindTagWrite("Section");
- Ver->Arch = UniqFindTagWrite("Architecture");
-
+
+ // 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
+ {
+ _error->Warning("Unknown Multi-Arch type »%s« for package »%s«",
+ MultiArch.c_str(), Section.FindS("Package").c_str());
+ Ver->MultiArch = pkgCache::Version::None;
+ }
+ }
+
// Archive Size
- Ver->Size = (unsigned)Section.FindI("Size");
-
+ Ver->Size = Section.FindULL("Size");
// Unpacked Size (in K)
- Ver->InstalledSize = (unsigned)Section.FindI("Installed-Size");
+ Ver->InstalledSize = Section.FindULL("Installed-Size");
Ver->InstalledSize *= 1024;
// Priority
@@ -94,6 +150,24 @@ 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)
@@ -128,10 +202,11 @@ bool debListParser::NewVersion(pkgCache::VerIterator Ver)
only describe package properties */
string debListParser::Description()
{
- if (DescriptionLanguage().empty())
+ string const lang = DescriptionLanguage();
+ if (lang.empty())
return Section.FindS("Description");
else
- return Section.FindS(("Description-" + pkgIndexFile::LanguageCode()).c_str());
+ return Section.FindS(string("Description-").append(lang).c_str());
}
/*}}}*/
// ListParser::DescriptionLanguage - Return the description lang string /*{{{*/
@@ -141,7 +216,16 @@ string debListParser::Description()
assumed to describe original description. */
string debListParser::DescriptionLanguage()
{
- return Section.FindS("Description").empty() ? pkgIndexFile::LanguageCode() : "";
+ if (Section.FindS("Description").empty() == false)
+ return "";
+
+ std::vector<string> const lang = APT::Configuration::getLanguages();
+ for (std::vector<string>::const_iterator l = lang.begin();
+ l != lang.end(); l++)
+ if (Section.FindS(string("Description-").append(*l).c_str()).empty() == false)
+ return *l;
+
+ return "";
}
/*}}}*/
// ListParser::Description - Return the description_md5 MD5SumValue /*{{{*/
@@ -167,13 +251,21 @@ MD5SumValue debListParser::Description_md5()
// ---------------------------------------------------------------------
/* This is called to update the package with any new information
that might be found in the section */
-bool debListParser::UsePackage(pkgCache::PkgIterator Pkg,
- pkgCache::VerIterator Ver)
+bool debListParser::UsePackage(pkgCache::PkgIterator &Pkg,
+ pkgCache::VerIterator &Ver)
{
if (Pkg->Section == 0)
Pkg->Section = UniqFindTagWrite("Section");
- if (Section.FindFlag("Essential",Pkg->Flags,pkgCache::Flag::Essential) == false)
- return false;
+
+ // Packages which are not from the "native" arch doesn't get the essential flag
+ // in the default "native" mode - it is also possible to mark "all" or "none".
+ // The "installed" mode is handled by ParseStatus(), See #544481 and friends.
+ string const static myArch = _config->Find("APT::Architecture");
+ string const static essential = _config->Find("pkgCacheGen::Essential", "native");
+ if ((essential == "native" && Pkg->Arch != 0 && myArch == Pkg.Arch()) ||
+ essential == "all")
+ if (Section.FindFlag("Essential",Pkg->Flags,pkgCache::Flag::Essential) == false)
+ return false;
if (Section.FindFlag("Important",Pkg->Flags,pkgCache::Flag::Important) == false)
return false;
@@ -240,14 +332,20 @@ unsigned short debListParser::VersionHash()
Some of the above are obsolete (I think?) flag = hold-* and
status = post-inst-failed, removal-failed at least.
*/
-bool debListParser::ParseStatus(pkgCache::PkgIterator Pkg,
- pkgCache::VerIterator Ver)
+bool debListParser::ParseStatus(pkgCache::PkgIterator &Pkg,
+ pkgCache::VerIterator &Ver)
{
const char *Start;
const char *Stop;
if (Section.Find("Status",Start,Stop) == false)
return true;
-
+
+ // UsePackage() is responsible for setting the flag in the default case
+ bool const static essential = _config->Find("pkgCacheGen::Essential", "") == "installed";
+ if (essential == true &&
+ Section.FindFlag("Essential",Pkg->Flags,pkgCache::Flag::Essential) == false)
+ return false;
+
// Isolate the first word
const char *I = Start;
for(; I < Stop && *I != ' '; I++);
@@ -376,6 +474,20 @@ const char *debListParser::ConvertRelation(const char *I,unsigned int &Op)
return I;
}
+/*
+ * CompleteArch:
+ *
+ * The complete architecture, consisting of <kernel>-<cpu>.
+ */
+static string CompleteArch(std::string& arch) {
+ if (arch == "armel") return "linux-arm";
+ if (arch == "lpia") return "linux-i386";
+ if (arch == "powerpcspe") return "linux-powerpc";
+ if (arch == "uclibc-linux-armel") return "linux-arm";
+ if (arch == "uclinux-armel") return "uclinux-arm";
+
+ return (arch.find("-") != string::npos) ? arch : "linux-" + arch;
+}
/*}}}*/
// ListParser::ParseDepends - Parse a dependency element /*{{{*/
// ---------------------------------------------------------------------
@@ -383,7 +495,8 @@ const char *debListParser::ConvertRelation(const char *I,unsigned int &Op)
bit by bit. */
const char *debListParser::ParseDepends(const char *Start,const char *Stop,
string &Package,string &Ver,
- unsigned int &Op, bool ParseArchFlags)
+ unsigned int &Op, bool const &ParseArchFlags,
+ bool const &StripMultiArch)
{
// Strip off leading space
for (;Start != Stop && isspace(*Start) != 0; Start++);
@@ -402,7 +515,14 @@ const char *debListParser::ParseDepends(const char *Start,const char *Stop,
// Stash the package name
Package.assign(Start,I - Start);
-
+
+ // We don't want to confuse library users which can't handle MultiArch
+ if (StripMultiArch == true) {
+ size_t const found = Package.rfind(':');
+ if (found != string::npos)
+ Package = Package.substr(0,found);
+ }
+
// Skip white space to the '('
for (;I != Stop && isspace(*I) != 0 ; I++);
@@ -441,6 +561,7 @@ const char *debListParser::ParseDepends(const char *Start,const char *Stop,
if (ParseArchFlags == true)
{
string arch = _config->Find("APT::Architecture");
+ string completeArch = CompleteArch(arch);
// Parse an architecture
if (I != Stop && *I == '[')
@@ -468,8 +589,13 @@ const char *debListParser::ParseDepends(const char *Start,const char *Stop,
I++;
}
- if (stringcmp(arch,I,End) == 0)
+ if (stringcmp(arch,I,End) == 0) {
Found = true;
+ } else {
+ std::string wildcard = SubstVar(string(I, End), "any", "*");
+ if (fnmatch(wildcard.c_str(), completeArch.c_str(), 0) == 0)
+ Found = true;
+ }
if (*End++ == ']') {
I = End;
@@ -508,15 +634,16 @@ const char *debListParser::ParseDepends(const char *Start,const char *Stop,
// ---------------------------------------------------------------------
/* This is the higher level depends parser. It takes a tag and generates
a complete depends tree for the given version. */
-bool debListParser::ParseDepends(pkgCache::VerIterator Ver,
+bool debListParser::ParseDepends(pkgCache::VerIterator &Ver,
const char *Tag,unsigned int Type)
{
const char *Start;
const char *Stop;
if (Section.Find(Tag,Start,Stop) == false)
return true;
-
+
string Package;
+ string const pkgArch = Ver.Arch(true);
string Version;
unsigned int Op;
@@ -525,8 +652,18 @@ bool debListParser::ParseDepends(pkgCache::VerIterator Ver,
Start = ParseDepends(Start,Stop,Package,Version,Op);
if (Start == 0)
return _error->Error("Problem parsing dependency %s",Tag);
-
- if (NewDepends(Ver,Package,Version,Op,Type) == false)
+
+ if (MultiArchEnabled == true &&
+ (Type == pkgCache::Dep::Conflicts ||
+ Type == pkgCache::Dep::DpkgBreaks ||
+ Type == pkgCache::Dep::Replaces))
+ {
+ for (std::vector<std::string>::const_iterator a = Architectures.begin();
+ a != Architectures.end(); ++a)
+ if (NewDepends(Ver,Package,*a,Version,Op,Type) == false)
+ return false;
+ }
+ else if (NewDepends(Ver,Package,pkgArch,Version,Op,Type) == false)
return false;
if (Start == Stop)
break;
@@ -537,33 +674,55 @@ bool debListParser::ParseDepends(pkgCache::VerIterator Ver,
// ListParser::ParseProvides - Parse the provides list /*{{{*/
// ---------------------------------------------------------------------
/* */
-bool debListParser::ParseProvides(pkgCache::VerIterator Ver)
+bool debListParser::ParseProvides(pkgCache::VerIterator &Ver)
{
const char *Start;
const char *Stop;
- if (Section.Find("Provides",Start,Stop) == false)
- return true;
-
- string Package;
- string Version;
- unsigned int Op;
-
- while (1)
+ if (Section.Find("Provides",Start,Stop) == true)
{
- Start = ParseDepends(Start,Stop,Package,Version,Op);
- if (Start == 0)
- return _error->Error("Problem parsing Provides line");
- if (Op != pkgCache::Dep::NoOp) {
- _error->Warning("Ignoring Provides line with DepCompareOp for package %s", Package.c_str());
- } else {
- if (NewProvides(Ver,Package,Version) == false)
- return false;
+ string Package;
+ string Version;
+ string const Arch = Ver.Arch(true);
+ unsigned int Op;
+
+ while (1)
+ {
+ Start = ParseDepends(Start,Stop,Package,Version,Op);
+ if (Start == 0)
+ return _error->Error("Problem parsing Provides line");
+ if (Op != pkgCache::Dep::NoOp) {
+ _error->Warning("Ignoring Provides line with DepCompareOp for package %s", Package.c_str());
+ } else {
+ if (NewProvides(Ver, Package, Arch, Version) == false)
+ return false;
+ }
+
+ if (Start == Stop)
+ break;
}
+ }
- if (Start == Stop)
- break;
+ if (Ver->MultiArch == pkgCache::Version::Allowed)
+ {
+ string const Package = string(Ver.ParentPkg().Name()).append(":").append("any");
+ NewProvides(Ver, Package, "any", 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();
+ for (std::vector<string>::const_iterator a = Architectures.begin();
+ a != Architectures.end(); ++a)
+ {
+ if (NewProvides(Ver, Package, *a, Version) == false)
+ return false;
+ }
+
return true;
}
/*}}}*/
@@ -594,16 +753,23 @@ bool debListParser::Step()
/* See if this is the correct Architecture, if it isn't then we
drop the whole section. A missing arch tag only happens (in theory)
inside the Status file, so that is a positive return */
- const char *Start;
- const char *Stop;
- if (Section.Find("Architecture",Start,Stop) == false)
+ string const Architecture = Section.FindS("Architecture");
+ if (Architecture.empty() == true)
return true;
- if (stringcmp(Arch,Start,Stop) == 0)
- return true;
+ if (Arch.empty() == true || MultiArchEnabled == false)
+ {
+ if (APT::Configuration::checkArchitecture(Architecture) == true)
+ return true;
+ }
+ else
+ {
+ if (Architecture == Arch)
+ return true;
- if (stringcmp(Start,Stop,"all") == 0)
- return true;
+ if (Architecture == "all")
+ return true;
+ }
iOffset = Tags.Offset();
}
@@ -613,7 +779,7 @@ bool debListParser::Step()
// ListParser::LoadReleaseInfo - Load the release information /*{{{*/
// ---------------------------------------------------------------------
/* */
-bool debListParser::LoadReleaseInfo(pkgCache::PkgFileIterator FileI,
+bool debListParser::LoadReleaseInfo(pkgCache::PkgFileIterator &FileI,
FileFd &File, string component)
{
pkgTagFile Tags(&File, File.Size() + 256); // XXX
@@ -621,8 +787,9 @@ bool debListParser::LoadReleaseInfo(pkgCache::PkgFileIterator FileI,
if (Tags.Step(Section) == false)
return false;
- //mvo: I don't think we need to fill that in (it's unused since apt-0.6)
- //FileI->Architecture = WriteUniqString(Arch);
+ // FIXME: Do we need it now for multi-arch?
+ // mvo: I don't think we need to fill that in (it's unused since apt-0.6)
+// FileI->Architecture = WriteUniqString(Arch);
// apt-secure does no longer download individual (per-section) Release
// file. to provide Component pinning we use the section name now
diff --git a/apt-pkg/deb/deblistparser.h b/apt-pkg/deb/deblistparser.h
index 34bb29c72..4bc1bd93c 100644
--- a/apt-pkg/deb/deblistparser.h
+++ b/apt-pkg/deb/deblistparser.h
@@ -32,12 +32,14 @@ class debListParser : public pkgCacheGenerator::ListParser
pkgTagSection Section;
unsigned long iOffset;
string Arch;
-
+ std::vector<std::string> Architectures;
+ bool MultiArchEnabled;
+
unsigned long UniqFindTagWrite(const char *Tag);
- bool ParseStatus(pkgCache::PkgIterator Pkg,pkgCache::VerIterator Ver);
- bool ParseDepends(pkgCache::VerIterator Ver,const char *Tag,
+ 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 ParseProvides(pkgCache::VerIterator &Ver);
static bool GrabWord(string Word,WordList *List,unsigned char &Out);
public:
@@ -46,28 +48,31 @@ class debListParser : public pkgCacheGenerator::ListParser
// These all operate against the current section
virtual string Package();
+ virtual string Architecture();
+ virtual bool ArchitectureAll();
virtual string Version();
- virtual bool NewVersion(pkgCache::VerIterator Ver);
+ virtual bool NewVersion(pkgCache::VerIterator &Ver);
virtual string Description();
virtual string DescriptionLanguage();
virtual MD5SumValue Description_md5();
virtual unsigned short VersionHash();
- virtual bool UsePackage(pkgCache::PkgIterator Pkg,
- pkgCache::VerIterator Ver);
+ virtual bool UsePackage(pkgCache::PkgIterator &Pkg,
+ pkgCache::VerIterator &Ver);
virtual unsigned long Offset() {return iOffset;};
virtual unsigned long Size() {return Section.size();};
virtual bool Step();
- bool LoadReleaseInfo(pkgCache::PkgFileIterator FileI,FileFd &File,
+ bool LoadReleaseInfo(pkgCache::PkgFileIterator &FileI,FileFd &File,
string section);
static const char *ParseDepends(const char *Start,const char *Stop,
string &Package,string &Ver,unsigned int &Op,
- bool ParseArchFlags = false);
+ bool const &ParseArchFlags = false,
+ bool const &StripMultiArch = false);
static const char *ConvertRelation(const char *I,unsigned int &Op);
- debListParser(FileFd *File);
+ debListParser(FileFd *File, string const &Arch = "");
};
#endif
diff --git a/apt-pkg/deb/debmetaindex.cc b/apt-pkg/deb/debmetaindex.cc
index f3ab6960c..8df3ed18d 100644
--- a/apt-pkg/deb/debmetaindex.cc
+++ b/apt-pkg/deb/debmetaindex.cc
@@ -5,11 +5,14 @@
#include <apt-pkg/strutl.h>
#include <apt-pkg/acquire-item.h>
#include <apt-pkg/configuration.h>
+#include <apt-pkg/aptconfiguration.h>
#include <apt-pkg/error.h>
+#include <set>
+
using namespace std;
-string debReleaseIndex::Info(const char *Type, const string Section) const
+string debReleaseIndex::Info(const char *Type, string const &Section, string const &Arch) const
{
string Info = ::URI::SiteOnly(URI) + ' ';
if (Dist[Dist.size() - 1] == '/')
@@ -18,7 +21,11 @@ string debReleaseIndex::Info(const char *Type, const string Section) const
Info += Dist;
}
else
- Info += Dist + '/' + Section;
+ {
+ Info += Dist + '/' + Section;
+ if (Arch.empty() == true)
+ Info += " " + Arch;
+ }
Info += " ";
Info += Type;
return Info;
@@ -60,16 +67,21 @@ string debReleaseIndex::MetaIndexURI(const char *Type) const
return Res;
}
-string debReleaseIndex::IndexURISuffix(const char *Type, const string Section) const
+string debReleaseIndex::IndexURISuffix(const char *Type, string const &Section, string const &Arch) const
{
string Res ="";
if (Dist[Dist.size() - 1] != '/')
- Res += Section + "/binary-" + _config->Find("APT::Architecture") + '/';
+ {
+ if (Arch == "native")
+ Res += Section + "/binary-" + _config->Find("APT::Architecture") + '/';
+ else
+ Res += Section + "/binary-" + Arch + '/';
+ }
return Res + Type;
}
-string debReleaseIndex::IndexURI(const char *Type, const string Section) const
+string debReleaseIndex::IndexURI(const char *Type, string const &Section, string const &Arch) const
{
if (Dist[Dist.size() - 1] == '/')
{
@@ -81,10 +93,10 @@ string debReleaseIndex::IndexURI(const char *Type, const string Section) const
return Res + Type;
}
else
- return URI + "dists/" + Dist + '/' + IndexURISuffix(Type, Section);
+ return URI + "dists/" + Dist + '/' + IndexURISuffix(Type, Section, Arch);
}
-string debReleaseIndex::SourceIndexURISuffix(const char *Type, const string Section) const
+string debReleaseIndex::SourceIndexURISuffix(const char *Type, const string &Section) const
{
string Res ="";
if (Dist[Dist.size() - 1] != '/')
@@ -92,7 +104,7 @@ string debReleaseIndex::SourceIndexURISuffix(const char *Type, const string Sect
return Res + Type;
}
-string debReleaseIndex::SourceIndexURI(const char *Type, const string Section) const
+string debReleaseIndex::SourceIndexURI(const char *Type, const string &Section) const
{
string Res;
if (Dist[Dist.size() - 1] == '/')
@@ -107,44 +119,61 @@ string debReleaseIndex::SourceIndexURI(const char *Type, const string Section) c
return URI + "dists/" + Dist + "/" + SourceIndexURISuffix(Type, Section);
}
-debReleaseIndex::debReleaseIndex(string URI,string Dist)
-{
- this->URI = URI;
- this->Dist = Dist;
- this->Indexes = NULL;
- this->Type = "deb";
+debReleaseIndex::debReleaseIndex(string const &URI, string const &Dist) {
+ this->URI = URI;
+ this->Dist = Dist;
+ this->Indexes = NULL;
+ this->Type = "deb";
}
-debReleaseIndex::~debReleaseIndex()
-{
- for (vector<const debSectionEntry *>::const_iterator I = SectionEntries.begin();
- I != SectionEntries.end(); I++)
- delete *I;
+debReleaseIndex::~debReleaseIndex() {
+ for (map<string, vector<debSectionEntry const*> >::const_iterator A = ArchEntries.begin();
+ A != ArchEntries.end(); ++A)
+ for (vector<const debSectionEntry *>::const_iterator S = A->second.begin();
+ S != A->second.end(); ++S)
+ delete *S;
}
-vector <struct IndexTarget *>* debReleaseIndex::ComputeIndexTargets() const
-{
- vector <struct IndexTarget *>* IndexTargets = new vector <IndexTarget *>;
- for (vector <const debSectionEntry *>::const_iterator I = SectionEntries.begin();
- I != SectionEntries.end();
- I++)
- {
- IndexTarget * Target = new IndexTarget();
- Target->ShortDesc = (*I)->IsSrc ? "Sources" : "Packages";
- Target->MetaKey
- = (*I)->IsSrc ? SourceIndexURISuffix(Target->ShortDesc.c_str(), (*I)->Section)
- : IndexURISuffix(Target->ShortDesc.c_str(), (*I)->Section);
- Target->URI
- = (*I)->IsSrc ? SourceIndexURI(Target->ShortDesc.c_str(), (*I)->Section)
- : IndexURI(Target->ShortDesc.c_str(), (*I)->Section);
-
- Target->Description = Info (Target->ShortDesc.c_str(), (*I)->Section);
- IndexTargets->push_back (Target);
- }
- return IndexTargets;
+vector <struct IndexTarget *>* debReleaseIndex::ComputeIndexTargets() const {
+ vector <struct IndexTarget *>* IndexTargets = new vector <IndexTarget *>;
+
+ map<string, vector<debSectionEntry const*> >::const_iterator const src = ArchEntries.find("source");
+ if (src != ArchEntries.end()) {
+ vector<debSectionEntry const*> const SectionEntries = src->second;
+ for (vector<debSectionEntry const*>::const_iterator I = SectionEntries.begin();
+ I != SectionEntries.end(); ++I) {
+ IndexTarget * Target = new IndexTarget();
+ Target->ShortDesc = "Sources";
+ Target->MetaKey = SourceIndexURISuffix(Target->ShortDesc.c_str(), (*I)->Section);
+ Target->URI = SourceIndexURI(Target->ShortDesc.c_str(), (*I)->Section);
+ Target->Description = Info (Target->ShortDesc.c_str(), (*I)->Section);
+ IndexTargets->push_back (Target);
+ }
+ }
+
+ // Only source release
+ if (IndexTargets->empty() == false && ArchEntries.size() == 1)
+ return IndexTargets;
+
+ for (map<string, vector<debSectionEntry const*> >::const_iterator a = ArchEntries.begin();
+ a != ArchEntries.end(); ++a) {
+ if (a->first == "source")
+ continue;
+ for (vector <const debSectionEntry *>::const_iterator I = a->second.begin();
+ I != a->second.end(); ++I) {
+ IndexTarget * Target = new IndexTarget();
+ Target->ShortDesc = "Packages";
+ Target->MetaKey = IndexURISuffix(Target->ShortDesc.c_str(), (*I)->Section, a->first);
+ Target->URI = IndexURI(Target->ShortDesc.c_str(), (*I)->Section, a->first);
+ Target->Description = Info (Target->ShortDesc.c_str(), (*I)->Section, a->first);
+ IndexTargets->push_back (Target);
+ }
+ }
+
+ return IndexTargets;
}
/*}}}*/
-bool debReleaseIndex::GetIndexes(pkgAcquire *Owner, bool GetAll) const
+bool debReleaseIndex::GetIndexes(pkgAcquire *Owner, bool const &GetAll) const
{
// special case for --print-uris
if (GetAll) {
@@ -169,17 +198,28 @@ bool debReleaseIndex::GetIndexes(pkgAcquire *Owner, bool GetAll) const
ComputeIndexTargets(),
new indexRecords (Dist));
- // Queue the translations
- for (vector<const debSectionEntry *>::const_iterator I = SectionEntries.begin();
- I != SectionEntries.end(); I++) {
-
- if((*I)->IsSrc)
- continue;
- debTranslationsIndex i = debTranslationsIndex(URI,Dist,(*I)->Section);
- i.GetIndexes(Owner);
- }
-
- return true;
+ // Queue the translations
+ std::vector<std::string> const lang = APT::Configuration::getLanguages(true);
+ map<string, set<string> > sections;
+ for (map<string, vector<debSectionEntry const*> >::const_iterator a = ArchEntries.begin();
+ a != ArchEntries.end(); ++a) {
+ if (a->first == "source")
+ continue;
+ for (vector<debSectionEntry const*>::const_iterator I = a->second.begin();
+ I != a->second.end(); I++)
+ sections[(*I)->Section].insert(lang.begin(), lang.end());
+ }
+
+ for (map<string, set<string> >::const_iterator s = sections.begin();
+ s != sections.end(); ++s)
+ for (set<string>::const_iterator l = s->second.begin();
+ l != s->second.end(); l++) {
+ if (*l == "none") continue;
+ debTranslationsIndex i = debTranslationsIndex(URI,Dist,s->first,(*l).c_str());
+ i.GetIndexes(Owner);
+ }
+
+ return true;
}
bool debReleaseIndex::IsTrusted() const
@@ -196,67 +236,113 @@ bool debReleaseIndex::IsTrusted() const
return false;
}
-vector <pkgIndexFile *> *debReleaseIndex::GetIndexFiles()
-{
- if (Indexes != NULL)
- return Indexes;
-
- Indexes = new vector <pkgIndexFile*>;
- for (vector<const debSectionEntry *>::const_iterator I = SectionEntries.begin();
- I != SectionEntries.end(); I++) {
- if ((*I)->IsSrc)
- Indexes->push_back(new debSourcesIndex (URI, Dist, (*I)->Section, IsTrusted()));
- else
- {
- Indexes->push_back(new debPackagesIndex (URI, Dist, (*I)->Section, IsTrusted()));
- Indexes->push_back(new debTranslationsIndex(URI, Dist, (*I)->Section));
- }
- }
+vector <pkgIndexFile *> *debReleaseIndex::GetIndexFiles() {
+ if (Indexes != NULL)
+ return Indexes;
+
+ Indexes = new vector <pkgIndexFile*>;
+ map<string, vector<debSectionEntry const*> >::const_iterator const src = ArchEntries.find("source");
+ if (src != ArchEntries.end()) {
+ vector<debSectionEntry const*> const SectionEntries = src->second;
+ for (vector<debSectionEntry const*>::const_iterator I = SectionEntries.begin();
+ I != SectionEntries.end(); I++)
+ Indexes->push_back(new debSourcesIndex (URI, Dist, (*I)->Section, IsTrusted()));
+ }
+
+ // Only source release
+ if (Indexes->empty() == false && ArchEntries.size() == 1)
+ return Indexes;
+
+ std::vector<std::string> const lang = APT::Configuration::getLanguages(true);
+ map<string, set<string> > sections;
+ for (map<string, vector<debSectionEntry const*> >::const_iterator a = ArchEntries.begin();
+ a != ArchEntries.end(); ++a) {
+ if (a->first == "source")
+ continue;
+ for (vector<debSectionEntry const*>::const_iterator I = a->second.begin();
+ I != a->second.end(); I++) {
+ Indexes->push_back(new debPackagesIndex (URI, Dist, (*I)->Section, IsTrusted(), a->first));
+ sections[(*I)->Section].insert(lang.begin(), lang.end());
+ }
+ }
+
+ for (map<string, set<string> >::const_iterator s = sections.begin();
+ s != sections.end(); ++s)
+ for (set<string>::const_iterator l = s->second.begin();
+ l != s->second.end(); l++) {
+ if (*l == "none") continue;
+ Indexes->push_back(new debTranslationsIndex(URI,Dist,s->first,(*l).c_str()));
+ }
+
+ return Indexes;
+}
- return Indexes;
+void debReleaseIndex::PushSectionEntry(vector<string> const &Archs, const debSectionEntry *Entry) {
+ for (vector<string>::const_iterator a = Archs.begin();
+ a != Archs.end(); ++a)
+ ArchEntries[*a].push_back(new debSectionEntry(Entry->Section, Entry->IsSrc));
+ delete Entry;
}
-void debReleaseIndex::PushSectionEntry(const debSectionEntry *Entry)
-{
- SectionEntries.push_back(Entry);
+void debReleaseIndex::PushSectionEntry(string const &Arch, const debSectionEntry *Entry) {
+ ArchEntries[Arch].push_back(Entry);
}
-debReleaseIndex::debSectionEntry::debSectionEntry (string Section, bool IsSrc): Section(Section)
-{
- this->IsSrc = IsSrc;
+void debReleaseIndex::PushSectionEntry(const debSectionEntry *Entry) {
+ if (Entry->IsSrc == true)
+ PushSectionEntry("source", Entry);
+ else {
+ for (map<string, vector<const debSectionEntry *> >::iterator a = ArchEntries.begin();
+ a != ArchEntries.end(); ++a) {
+ a->second.push_back(Entry);
+ }
+ }
}
+debReleaseIndex::debSectionEntry::debSectionEntry (string const &Section,
+ bool const &IsSrc): Section(Section), IsSrc(IsSrc)
+{}
+
class debSLTypeDebian : public pkgSourceList::Type
{
protected:
- bool CreateItemInternal(vector<metaIndex *> &List,string URI,
- string Dist,string Section,
- bool IsSrc) const
+ bool CreateItemInternal(vector<metaIndex *> &List, string const &URI,
+ string const &Dist, string const &Section,
+ bool const &IsSrc, map<string, string> const &Options) const
{
- for (vector<metaIndex *>::const_iterator I = List.begin();
+ map<string, string>::const_iterator const arch = Options.find("arch");
+ vector<string> const Archs =
+ (arch != Options.end()) ? VectorizeString(arch->second, ',') :
+ APT::Configuration::getArchitectures();
+
+ for (vector<metaIndex *>::const_iterator I = List.begin();
I != List.end(); I++)
{
- // This check insures that there will be only one Release file
- // queued for all the Packages files and Sources files it
- // corresponds to.
- if (strcmp((*I)->GetType(), "deb") == 0)
+ // We only worry about debian entries here
+ if (strcmp((*I)->GetType(), "deb") != 0)
+ continue;
+
+ debReleaseIndex *Deb = (debReleaseIndex *) (*I);
+ /* This check insures that there will be only one Release file
+ queued for all the Packages files and Sources files it
+ corresponds to. */
+ if (Deb->GetURI() == URI && Deb->GetDist() == Dist)
{
- debReleaseIndex *Deb = (debReleaseIndex *) (*I);
- // This check insures that there will be only one Release file
- // queued for all the Packages files and Sources files it
- // corresponds to.
- if (Deb->GetURI() == URI && Deb->GetDist() == Dist)
- {
- Deb->PushSectionEntry(new debReleaseIndex::debSectionEntry(Section, IsSrc));
- return true;
- }
+ if (IsSrc == true)
+ Deb->PushSectionEntry("source", new debReleaseIndex::debSectionEntry(Section, IsSrc));
+ else
+ Deb->PushSectionEntry(Archs, new debReleaseIndex::debSectionEntry(Section, IsSrc));
+ return true;
}
}
// No currently created Release file indexes this entry, so we create a new one.
// XXX determine whether this release is trusted or not
- debReleaseIndex *Deb = new debReleaseIndex(URI,Dist);
- Deb->PushSectionEntry (new debReleaseIndex::debSectionEntry(Section, IsSrc));
+ debReleaseIndex *Deb = new debReleaseIndex(URI, Dist);
+ if (IsSrc == true)
+ Deb->PushSectionEntry ("source", new debReleaseIndex::debSectionEntry(Section, IsSrc));
+ else
+ Deb->PushSectionEntry (Archs, new debReleaseIndex::debSectionEntry(Section, IsSrc));
List.push_back(Deb);
return true;
}
@@ -266,10 +352,11 @@ class debSLTypeDeb : public debSLTypeDebian
{
public:
- bool CreateItem(vector<metaIndex *> &List,string URI,
- string Dist,string Section) const
+ bool CreateItem(vector<metaIndex *> &List, string const &URI,
+ string const &Dist, string const &Section,
+ std::map<string, string> const &Options) const
{
- return CreateItemInternal(List, URI, Dist, Section, false);
+ return CreateItemInternal(List, URI, Dist, Section, false, Options);
}
debSLTypeDeb()
@@ -283,10 +370,11 @@ class debSLTypeDebSrc : public debSLTypeDebian
{
public:
- bool CreateItem(vector<metaIndex *> &List,string URI,
- string Dist,string Section) const
+ bool CreateItem(vector<metaIndex *> &List, string const &URI,
+ string const &Dist, string const &Section,
+ std::map<string, string> const &Options) const
{
- return CreateItemInternal(List, URI, Dist, Section, true);
+ return CreateItemInternal(List, URI, Dist, Section, true, Options);
}
debSLTypeDebSrc()
diff --git a/apt-pkg/deb/debmetaindex.h b/apt-pkg/deb/debmetaindex.h
index 8e6a1463b..360fa5419 100644
--- a/apt-pkg/deb/debmetaindex.h
+++ b/apt-pkg/deb/debmetaindex.h
@@ -5,40 +5,44 @@
#include <apt-pkg/metaindex.h>
#include <apt-pkg/sourcelist.h>
+#include <map>
+
class debReleaseIndex : public metaIndex {
public:
class debSectionEntry
{
public:
- debSectionEntry (string Section, bool IsSrc);
- bool IsSrc;
- string Section;
+ debSectionEntry (string const &Section, bool const &IsSrc);
+ string const Section;
+ bool const IsSrc;
};
private:
- vector <const debSectionEntry *> SectionEntries;
+ std::map<string, vector<debSectionEntry const*> > ArchEntries;
public:
- debReleaseIndex(string URI, string Dist);
+ debReleaseIndex(string const &URI, string const &Dist);
~debReleaseIndex();
- virtual string ArchiveURI(string File) const {return URI + File;};
- virtual bool GetIndexes(pkgAcquire *Owner, bool GetAll=false) const;
+ virtual string ArchiveURI(string const &File) const {return URI + File;};
+ virtual bool GetIndexes(pkgAcquire *Owner, bool const &GetAll=false) const;
vector <struct IndexTarget *>* ComputeIndexTargets() const;
- string Info(const char *Type, const string Section) const;
+ string Info(const char *Type, string const &Section, string const &Arch="") const;
string MetaIndexInfo(const char *Type) const;
string MetaIndexFile(const char *Types) const;
string MetaIndexURI(const char *Type) const;
- string IndexURI(const char *Type, const string Section) const;
- string IndexURISuffix(const char *Type, const string Section) const;
- string SourceIndexURI(const char *Type, const string Section) const;
- string SourceIndexURISuffix(const char *Type, const string Section) const;
+ string IndexURI(const char *Type, string const &Section, string const &Arch="native") const;
+ string IndexURISuffix(const char *Type, string const &Section, string const &Arch="native") const;
+ string SourceIndexURI(const char *Type, const string &Section) const;
+ string SourceIndexURISuffix(const char *Type, const string &Section) const;
virtual vector <pkgIndexFile *> *GetIndexFiles();
virtual bool IsTrusted() const;
+ void PushSectionEntry(vector<string> const &Archs, const debSectionEntry *Entry);
+ void PushSectionEntry(string const &Arch, const debSectionEntry *Entry);
void PushSectionEntry(const debSectionEntry *Entry);
};
diff --git a/apt-pkg/deb/debrecords.cc b/apt-pkg/deb/debrecords.cc
index 57d30dc62..34ef0d8f2 100644
--- a/apt-pkg/deb/debrecords.cc
+++ b/apt-pkg/deb/debrecords.cc
@@ -11,6 +11,7 @@
#include <apt-pkg/debrecords.h>
#include <apt-pkg/strutl.h>
#include <apt-pkg/error.h>
+#include <apt-pkg/aptconfiguration.h>
#include <langinfo.h>
/*}}}*/
@@ -110,13 +111,18 @@ string debRecordParser::ShortDesc()
string debRecordParser::LongDesc()
{
string orig, dest;
- char *codeset = nl_langinfo(CODESET);
if (!Section.FindS("Description").empty())
orig = Section.FindS("Description").c_str();
- else
- orig = Section.FindS(("Description-" + pkgIndexFile::LanguageCode()).c_str()).c_str();
+ else
+ {
+ vector<string> const lang = APT::Configuration::getLanguages();
+ for (vector<string>::const_iterator l = lang.begin();
+ orig.empty() && l != lang.end(); l++)
+ orig = Section.FindS(string("Description-").append(*l).c_str());
+ }
+ char const * const codeset = nl_langinfo(CODESET);
if (strcmp(codeset,"UTF-8") != 0) {
UTF8ToCodeset(codeset, orig, &dest);
orig = dest;
diff --git a/apt-pkg/deb/debsrcrecords.cc b/apt-pkg/deb/debsrcrecords.cc
index bde10aa6d..21336e1af 100644
--- a/apt-pkg/deb/debsrcrecords.cc
+++ b/apt-pkg/deb/debsrcrecords.cc
@@ -54,7 +54,8 @@ const char **debSrcRecordParser::Binaries()
package/version records representing the build dependency. The returned
array need not be freed and will be reused by the next call to this
function */
-bool debSrcRecordParser::BuildDepends(vector<pkgSrcRecords::Parser::BuildDepRec> &BuildDeps, bool ArchOnly)
+bool debSrcRecordParser::BuildDepends(vector<pkgSrcRecords::Parser::BuildDepRec> &BuildDeps,
+ bool const &ArchOnly, bool const &StripMultiArch)
{
unsigned int I;
const char *Start, *Stop;
@@ -77,7 +78,7 @@ bool debSrcRecordParser::BuildDepends(vector<pkgSrcRecords::Parser::BuildDepRec>
while (1)
{
Start = debListParser::ParseDepends(Start, Stop,
- rec.Package,rec.Version,rec.Op,true);
+ rec.Package,rec.Version,rec.Op,true, StripMultiArch);
if (Start == 0)
return _error->Error("Problem parsing dependency: %s", fields[I]);
diff --git a/apt-pkg/deb/debsrcrecords.h b/apt-pkg/deb/debsrcrecords.h
index a3b5a8286..c39d78bae 100644
--- a/apt-pkg/deb/debsrcrecords.h
+++ b/apt-pkg/deb/debsrcrecords.h
@@ -30,14 +30,14 @@ class debSrcRecordParser : public pkgSrcRecords::Parser
virtual bool Restart() {return Tags.Jump(Sect,0);};
virtual bool Step() {iOffset = Tags.Offset(); return Tags.Step(Sect);};
- virtual bool Jump(unsigned long Off) {iOffset = Off; return Tags.Jump(Sect,Off);};
+ virtual bool Jump(unsigned long const &Off) {iOffset = Off; return Tags.Jump(Sect,Off);};
virtual string Package() const {return Sect.FindS("Package");};
virtual string Version() const {return Sect.FindS("Version");};
virtual string Maintainer() const {return Sect.FindS("Maintainer");};
virtual string Section() const {return Sect.FindS("Section");};
virtual const char **Binaries();
- virtual bool BuildDepends(vector<BuildDepRec> &BuildDeps, bool ArchOnly);
+ virtual bool BuildDepends(vector<BuildDepRec> &BuildDeps, bool const &ArchOnly, bool const &StripMultiArch = true);
virtual unsigned long Offset() {return iOffset;};
virtual string AsStr()
{
@@ -47,7 +47,7 @@ class debSrcRecordParser : public pkgSrcRecords::Parser
};
virtual bool Files(vector<pkgSrcRecords::File> &F);
- debSrcRecordParser(string File,pkgIndexFile const *Index)
+ debSrcRecordParser(string const &File,pkgIndexFile const *Index)
: Parser(Index), Fd(File,FileFd::ReadOnly), Tags(&Fd,102400),
Buffer(0), BufSize(0) {}
~debSrcRecordParser();
diff --git a/apt-pkg/deb/debsystem.cc b/apt-pkg/deb/debsystem.cc
index 59f826d96..7056d771d 100644
--- a/apt-pkg/deb/debsystem.cc
+++ b/apt-pkg/deb/debsystem.cc
@@ -18,7 +18,6 @@
#include <apt-pkg/error.h>
#include <apt-pkg/fileutl.h>
#include <apti18n.h>
-
#include <sys/types.h>
#include <unistd.h>
#include <dirent.h>
@@ -79,8 +78,15 @@ bool debSystem::Lock()
{
close(LockFD);
LockFD = -1;
+ const char *cmd;
+ if (getenv("SUDO_USER") != NULL)
+ cmd = "sudo dpkg --configure -a";
+ else
+ cmd = "dpkg --configure -a";
+ // TRANSLATORS: the %s contains the recovery command, usually
+ // dpkg --configure -a
return _error->Error(_("dpkg was interrupted, you must manually "
- "run 'dpkg --configure -a' to correct the problem. "));
+ "run '%s' to correct the problem. "), cmd);
}
LockCount++;
@@ -158,7 +164,7 @@ bool debSystem::Initialize(Configuration &Cnf)
/* These really should be jammed into a generic 'Local Database' engine
which is yet to be determined. The functions in pkgcachegen should
be the only users of these */
- Cnf.CndSet("Dir::State::userstatus","status.user"); // Defunct
+ Cnf.CndSet("Dir::State::extended_states", Cnf.FindDir("Dir::State").append("extended_states"));
Cnf.CndSet("Dir::State::status","/var/lib/dpkg/status");
Cnf.CndSet("Dir::Bin::dpkg","/usr/bin/dpkg");
diff --git a/apt-pkg/deb/debversion.cc b/apt-pkg/deb/debversion.cc
index ad45e9a44..755ffbe96 100644
--- a/apt-pkg/deb/debversion.cc
+++ b/apt-pkg/deb/debversion.cc
@@ -190,8 +190,22 @@ int debVersioningSystem::DoCmpVersion(const char *A,const char *AEnd,
dlhs++;
if (drhs != rhs)
drhs++;
-
- return CmpFragment(dlhs,AEnd,drhs,BEnd);
+
+ // no debian revision need to be treated like -0
+ if (*(dlhs-1) == '-' && *(drhs-1) == '-')
+ return CmpFragment(dlhs,AEnd,drhs,BEnd);
+ else if (*(dlhs-1) == '-')
+ {
+ const char* null = "0";
+ return CmpFragment(dlhs,AEnd,null, null+1);
+ }
+ else if (*(drhs-1) == '-')
+ {
+ const char* null = "0";
+ return CmpFragment(null, null+1, drhs, BEnd);
+ }
+ else
+ return 0;
}
/*}}}*/
// debVS::CheckDep - Check a single dependency /*{{{*/
diff --git a/apt-pkg/deb/dpkgpm.cc b/apt-pkg/deb/dpkgpm.cc
index 2bbc7a4ba..67291063c 100644
--- a/apt-pkg/deb/dpkgpm.cc
+++ b/apt-pkg/deb/dpkgpm.cc
@@ -12,6 +12,7 @@
#include <apt-pkg/error.h>
#include <apt-pkg/configuration.h>
#include <apt-pkg/depcache.h>
+#include <apt-pkg/pkgrecords.h>
#include <apt-pkg/strutl.h>
#include <apti18n.h>
#include <apt-pkg/fileutl.h>
@@ -25,6 +26,7 @@
#include <sys/wait.h>
#include <signal.h>
#include <errno.h>
+#include <string.h>
#include <stdio.h>
#include <string.h>
#include <algorithm>
@@ -51,6 +53,7 @@ namespace
std::make_pair("configure", N_("Configuring %s")),
std::make_pair("remove", N_("Removing %s")),
std::make_pair("purge", N_("Completely removing %s")),
+ std::make_pair("disappear", N_("Noting disappearance of %s")),
std::make_pair("trigproc", N_("Running post-installation trigger %s"))
};
@@ -106,7 +109,7 @@ ionice(int PID)
/* */
pkgDPkgPM::pkgDPkgPM(pkgDepCache *Cache)
: pkgPackageManager(Cache), dpkgbuf_pos(0),
- term_out(NULL), PackagesDone(0), PackagesTotal(0)
+ term_out(NULL), history_out(NULL), PackagesDone(0), PackagesTotal(0)
{
}
/*}}}*/
@@ -125,7 +128,19 @@ bool pkgDPkgPM::Install(PkgIterator Pkg,string File)
if (File.empty() == true || Pkg.end() == true)
return _error->Error("Internal Error, No file name for %s",Pkg.Name());
- List.push_back(Item(Item::Install,Pkg,File));
+ // If the filename string begins with DPkg::Chroot-Directory, return the
+ // substr that is within the chroot so dpkg can access it.
+ string const chrootdir = _config->FindDir("DPkg::Chroot-Directory","/");
+ if (chrootdir != "/" && File.find(chrootdir) == 0)
+ {
+ size_t len = chrootdir.length();
+ if (chrootdir.at(len - 1) == '/')
+ len--;
+ List.push_back(Item(Item::Install,Pkg,File.substr(len)));
+ }
+ else
+ List.push_back(Item(Item::Install,Pkg,File));
+
return true;
}
/*}}}*/
@@ -342,7 +357,6 @@ bool pkgDPkgPM::RunScriptsWithPkgs(const char *Cnf)
return true;
}
-
/*}}}*/
// DPkgPM::DoStdin - Read stdin and pass to slave pty /*{{{*/
// ---------------------------------------------------------------------
@@ -408,11 +422,12 @@ void pkgDPkgPM::ProcessDpkgStatusLine(int OutStatusFd, char *line)
'processing: install: pkg'
'processing: configure: pkg'
'processing: remove: pkg'
- 'processing: purge: pkg' - but for apt is it a ignored "unknown" action
+ 'processing: purge: pkg'
+ 'processing: disappear: pkg'
'processing: trigproc: trigger'
*/
- char* list[5];
+ char* list[6];
// dpkg sends multiline error messages sometimes (see
// #374195 for a example. we should support this by
// either patching dpkg to not send multiline over the
@@ -455,11 +470,22 @@ void pkgDPkgPM::ProcessDpkgStatusLine(int OutStatusFd, char *line)
write(OutStatusFd, status.str().c_str(), status.str().size());
if (Debug == true)
std::clog << "send: '" << status.str() << "'" << endl;
+
+ if (strncmp(action, "disappear", strlen("disappear")) == 0)
+ handleDisappearAction(pkg_or_trigger);
return;
}
if(strncmp(action,"error",strlen("error")) == 0)
{
+ // urgs, sometime has ":" in its error string so that we
+ // end up with the error message split between list[3]
+ // and list[4], e.g. the message:
+ // "failed in buffer_write(fd) (10, ret=-1): backend dpkg-deb ..."
+ // concat them again
+ if( list[4] != NULL )
+ list[3][strlen(list[3])] = ':';
+
status << "pmerror:" << list[1]
<< ":" << (PackagesDone/float(PackagesTotal)*100.0)
<< ":" << list[3]
@@ -468,6 +494,8 @@ void pkgDPkgPM::ProcessDpkgStatusLine(int OutStatusFd, char *line)
write(OutStatusFd, status.str().c_str(), status.str().size());
if (Debug == true)
std::clog << "send: '" << status.str() << "'" << endl;
+ pkgFailures++;
+ WriteApportReport(list[1], list[3]);
return;
}
else if(strncmp(action,"conffile",strlen("conffile")) == 0)
@@ -514,6 +542,51 @@ void pkgDPkgPM::ProcessDpkgStatusLine(int OutStatusFd, char *line)
<< " action: " << action << endl;
}
/*}}}*/
+// DPkgPM::handleDisappearAction /*{{{*/
+void pkgDPkgPM::handleDisappearAction(string const &pkgname)
+{
+ // record the package name for display and stuff later
+ disappearedPkgs.insert(pkgname);
+
+ pkgCache::PkgIterator Pkg = Cache.FindPkg(pkgname);
+ if (unlikely(Pkg.end() == true))
+ return;
+ // the disappeared package was auto-installed - nothing to do
+ if ((Cache[Pkg].Flags & pkgCache::Flag::Auto) == pkgCache::Flag::Auto)
+ return;
+ pkgCache::VerIterator PkgVer = Pkg.CurrentVer();
+ if (unlikely(PkgVer.end() == true))
+ return;
+ /* search in the list of dependencies for (Pre)Depends,
+ check if this dependency has a Replaces on our package
+ and if so transfer the manual installed flag to it */
+ for (pkgCache::DepIterator Dep = PkgVer.DependsList(); Dep.end() != true; ++Dep)
+ {
+ if (Dep->Type != pkgCache::Dep::Depends &&
+ Dep->Type != pkgCache::Dep::PreDepends)
+ continue;
+ pkgCache::PkgIterator Tar = Dep.TargetPkg();
+ if (unlikely(Tar.end() == true))
+ continue;
+ // the package is already marked as manual
+ if ((Cache[Tar].Flags & pkgCache::Flag::Auto) != pkgCache::Flag::Auto)
+ continue;
+ pkgCache::VerIterator TarVer = Tar.CurrentVer();
+ for (pkgCache::DepIterator Rep = TarVer.DependsList(); Rep.end() != true; ++Rep)
+ {
+ if (Rep->Type != pkgCache::Dep::Replaces)
+ continue;
+ if (Pkg != Rep.TargetPkg())
+ continue;
+ // okay, they are strongly connected - transfer manual-bit
+ if (Debug == true)
+ std::clog << "transfer manual-bit from disappeared »" << pkgname << "« to »" << Tar.FullName() << "«" << std::endl;
+ Cache[Tar].Flags &= ~Flag::Auto;
+ break;
+ }
+ }
+}
+ /*}}}*/
// DPkgPM::DoDpkgStatusFd /*{{{*/
// ---------------------------------------------------------------------
/*
@@ -552,48 +625,50 @@ void pkgDPkgPM::DoDpkgStatusFd(int statusfd, int OutStatusFd)
}
/*}}}*/
// DPkgPM::WriteHistoryTag /*{{{*/
-void pkgDPkgPM::WriteHistoryTag(string tag, string value)
+void pkgDPkgPM::WriteHistoryTag(string const &tag, string value)
{
- if (value.size() > 0)
- {
- // poor mans rstrip(", ")
- if (value[value.size()-2] == ',' && value[value.size()-1] == ' ')
- value.erase(value.size() - 2, 2);
- fprintf(history_out, "%s: %s\n", tag.c_str(), value.c_str());
- }
+ size_t const length = value.length();
+ if (length == 0)
+ return;
+ // 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());
} /*}}}*/
// DPkgPM::OpenLog /*{{{*/
bool pkgDPkgPM::OpenLog()
{
- string logdir = _config->FindDir("Dir::Log");
+ string const logdir = _config->FindDir("Dir::Log");
if(not FileExists(logdir))
return _error->Error(_("Directory '%s' missing"), logdir.c_str());
// get current time
char timestr[200];
- time_t t = time(NULL);
- struct tm *tmp = localtime(&t);
+ time_t const t = time(NULL);
+ struct tm const * const tmp = localtime(&t);
strftime(timestr, sizeof(timestr), "%F %T", tmp);
// open terminal log
- string logfile_name = flCombine(logdir,
+ string const logfile_name = flCombine(logdir,
_config->Find("Dir::Log::Terminal"));
if (!logfile_name.empty())
{
term_out = fopen(logfile_name.c_str(),"a");
if (term_out == NULL)
- return _error->WarningE(_("Could not open file '%s'"), logfile_name.c_str());
+ return _error->WarningE("OpenLog", _("Could not open file '%s'"), logfile_name.c_str());
setvbuf(term_out, NULL, _IONBF, 0);
chmod(logfile_name.c_str(), 0600);
fprintf(term_out, "\nLog started: %s\n", timestr);
}
- // write
- string history_name = flCombine(logdir,
+ // write your history
+ string const history_name = flCombine(logdir,
_config->Find("Dir::Log::History"));
if (!history_name.empty())
{
history_out = fopen(history_name.c_str(),"a");
+ if (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;
@@ -613,6 +688,8 @@ bool pkgDPkgPM::OpenLog()
remove += I.Name() + string(" (") + Cache[I].CurVersion + string("), ");
}
}
+ if (_config->Exists("Commandline::AsString") == true)
+ WriteHistoryTag("Commandline", _config->Find("Commandline::AsString"));
WriteHistoryTag("Install", install);
WriteHistoryTag("Upgrade", upgrade);
WriteHistoryTag("Downgrade",downgrade);
@@ -643,11 +720,27 @@ bool pkgDPkgPM::CloseLog()
if(history_out)
{
- if (dpkg_error.size() > 0)
+ if (disappearedPkgs.empty() == false)
+ {
+ string disappear;
+ for (std::set<std::string>::const_iterator d = disappearedPkgs.begin();
+ d != disappearedPkgs.end(); ++d)
+ {
+ pkgCache::PkgIterator P = Cache.FindPkg(*d);
+ disappear.append(*d);
+ if (P.end() == true)
+ disappear.append(", ");
+ else
+ disappear.append(" (").append(Cache[P].CurVersion).append("), ");
+ }
+ 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);
}
+ history_out = NULL;
return true;
}
@@ -895,6 +988,8 @@ bool pkgDPkgPM::Go(int OutStatusFd)
{
if((*I).Pkg.end() == true)
continue;
+ if (I->Op == Item::Configure && disappearedPkgs.find(I->Pkg.Name()) != disappearedPkgs.end())
+ continue;
Args[n++] = I->Pkg.Name();
Size += strlen(Args[n-1]);
}
@@ -1065,7 +1160,7 @@ bool pkgDPkgPM::Go(int OutStatusFd)
// wait for input or output here
FD_ZERO(&rfds);
- if (!stdin_is_dev_null)
+ if (master >= 0 && !stdin_is_dev_null)
FD_SET(0, &rfds);
FD_SET(_dpkgin, &rfds);
if(master >= 0)
@@ -1152,3 +1247,186 @@ void pkgDPkgPM::Reset()
List.erase(List.begin(),List.end());
}
/*}}}*/
+// pkgDpkgPM::WriteApportReport - write out error report pkg failure /*{{{*/
+// ---------------------------------------------------------------------
+/* */
+void pkgDPkgPM::WriteApportReport(const char *pkgpath, const char *errormsg)
+{
+ string pkgname, reportfile, srcpkgname, pkgver, arch;
+ string::size_type pos;
+ FILE *report;
+
+ if (_config->FindB("Dpkg::ApportFailureReport", false) == false)
+ {
+ std::clog << "configured to not write apport reports" << std::endl;
+ return;
+ }
+
+ // only report the first errors
+ if(pkgFailures > _config->FindI("APT::Apport::MaxReports", 3))
+ {
+ std::clog << _("No apport report written because MaxReports is reached already") << std::endl;
+ return;
+ }
+
+ // check if its not a follow up error
+ const char *needle = dgettext("dpkg", "dependency problems - leaving unconfigured");
+ if(strstr(errormsg, needle) != NULL) {
+ std::clog << _("No apport report written because the error message indicates its a followup error from a previous failure.") << std::endl;
+ return;
+ }
+
+ // do not report disk-full failures
+ if(strstr(errormsg, strerror(ENOSPC)) != NULL) {
+ std::clog << _("No apport report written because the error message indicates a disk full error") << std::endl;
+ return;
+ }
+
+ // do not report out-of-memory failures
+ if(strstr(errormsg, strerror(ENOMEM)) != NULL) {
+ std::clog << _("No apport report written because the error message indicates a out of memory error") << std::endl;
+ return;
+ }
+
+ // do not report dpkg I/O errors
+ // XXX - this message is localized, but this only matches the English version. This is better than nothing.
+ if(strstr(errormsg, "short read in buffer_copy (")) {
+ std::clog << _("No apport report written because the error message indicates a dpkg I/O error") << std::endl;
+ return;
+ }
+
+ // get the pkgname and reportfile
+ pkgname = flNotDir(pkgpath);
+ pos = pkgname.find('_');
+ if(pos != string::npos)
+ pkgname = pkgname.substr(0, pos);
+
+ // find the package versin and source package name
+ pkgCache::PkgIterator Pkg = Cache.FindPkg(pkgname);
+ if (Pkg.end() == true)
+ return;
+ pkgCache::VerIterator Ver = Cache.GetCandidateVer(Pkg);
+ if (Ver.end() == true)
+ return;
+ pkgver = Ver.VerStr() == NULL ? "unknown" : Ver.VerStr();
+ pkgRecords Recs(Cache);
+ pkgRecords::Parser &Parse = Recs.Lookup(Ver.FileList());
+ srcpkgname = Parse.SourcePkg();
+ if(srcpkgname.empty())
+ srcpkgname = pkgname;
+
+ // if the file exists already, we check:
+ // - if it was reported already (touched by apport).
+ // If not, we do nothing, otherwise
+ // we overwrite it. This is the same behaviour as apport
+ // - if we have a report with the same pkgversion already
+ // then we skip it
+ reportfile = flCombine("/var/crash",pkgname+".0.crash");
+ if(FileExists(reportfile))
+ {
+ struct stat buf;
+ char strbuf[255];
+
+ // check atime/mtime
+ stat(reportfile.c_str(), &buf);
+ if(buf.st_mtime > buf.st_atime)
+ return;
+
+ // check if the existing report is the same version
+ report = fopen(reportfile.c_str(),"r");
+ while(fgets(strbuf, sizeof(strbuf), report) != NULL)
+ {
+ if(strstr(strbuf,"Package:") == strbuf)
+ {
+ char pkgname[255], version[255];
+ if(sscanf(strbuf, "Package: %s %s", pkgname, version) == 2)
+ if(strcmp(pkgver.c_str(), version) == 0)
+ {
+ fclose(report);
+ return;
+ }
+ }
+ }
+ fclose(report);
+ }
+
+ // now write the report
+ arch = _config->Find("APT::Architecture");
+ report = fopen(reportfile.c_str(),"w");
+ if(report == NULL)
+ return;
+ if(_config->FindB("DPkgPM::InitialReportOnly",false) == true)
+ chmod(reportfile.c_str(), 0);
+ else
+ chmod(reportfile.c_str(), 0600);
+ fprintf(report, "ProblemType: Package\n");
+ fprintf(report, "Architecture: %s\n", arch.c_str());
+ time_t now = time(NULL);
+ fprintf(report, "Date: %s" , ctime(&now));
+ fprintf(report, "Package: %s %s\n", pkgname.c_str(), pkgver.c_str());
+ fprintf(report, "SourcePackage: %s\n", srcpkgname.c_str());
+ fprintf(report, "ErrorMessage:\n %s\n", errormsg);
+
+ // ensure that the log is flushed
+ if(term_out)
+ fflush(term_out);
+
+ // attach terminal log it if we have it
+ string logfile_name = _config->FindFile("Dir::Log::Terminal");
+ if (!logfile_name.empty())
+ {
+ FILE *log = NULL;
+ char buf[1024];
+
+ fprintf(report, "DpkgTerminalLog:\n");
+ log = fopen(logfile_name.c_str(),"r");
+ if(log != NULL)
+ {
+ while( fgets(buf, sizeof(buf), log) != NULL)
+ fprintf(report, " %s", buf);
+ fclose(log);
+ }
+ }
+
+ // log the ordering
+ const char *ops_str[] = {"Install", "Configure","Remove","Purge"};
+ fprintf(report, "AptOrdering:\n");
+ for (vector<Item>::iterator I = List.begin(); I != List.end(); I++)
+ fprintf(report, " %s: %s\n", (*I).Pkg.Name(), ops_str[(*I).Op]);
+
+ // attach dmesg log (to learn about segfaults)
+ if (FileExists("/bin/dmesg"))
+ {
+ FILE *log = NULL;
+ char buf[1024];
+
+ fprintf(report, "Dmesg:\n");
+ log = popen("/bin/dmesg","r");
+ if(log != NULL)
+ {
+ while( fgets(buf, sizeof(buf), log) != NULL)
+ fprintf(report, " %s", buf);
+ fclose(log);
+ }
+ }
+
+ // attach df -l log (to learn about filesystem status)
+ if (FileExists("/bin/df"))
+ {
+ FILE *log = NULL;
+ char buf[1024];
+
+ fprintf(report, "Df:\n");
+ log = popen("/bin/df -l","r");
+ if(log != NULL)
+ {
+ while( fgets(buf, sizeof(buf), log) != NULL)
+ fprintf(report, " %s", buf);
+ fclose(log);
+ }
+ }
+
+ fclose(report);
+
+}
+ /*}}}*/
diff --git a/apt-pkg/deb/dpkgpm.h b/apt-pkg/deb/dpkgpm.h
index 330c788a2..b7b5a6def 100644
--- a/apt-pkg/deb/dpkgpm.h
+++ b/apt-pkg/deb/dpkgpm.h
@@ -32,7 +32,23 @@ class pkgDPkgPM : public pkgPackageManager
FILE *history_out;
string dpkg_error;
+ /** \brief record the disappear action and handle accordingly
+
+ dpkg let packages disappear then they have no files any longer and
+ nothing depends on them. We need to collect this as dpkg as well as
+ APT doesn't know beforehand that the package will disappear, so the
+ only possible option is to tell the user afterwards about it.
+ To enhance the experience we also try to forward the auto-install
+ flag so the disappear-causer(s) are not autoremoved next time -
+ for the transfer to happen the disappeared version needs to depend
+ on the package the flag should be forwarded to and this package
+ needs to declare a Replaces on the disappeared package.
+ \param pkgname Name of the package that disappeared
+ */
+ void handleDisappearAction(string const &pkgname);
+
protected:
+ int pkgFailures;
// progress reporting
struct DpkgState
@@ -49,6 +65,7 @@ class pkgDPkgPM : public pkgPackageManager
// the int is the state that is already done (e.g. a package that is
// going to be install is already in state "half-installed")
map<string,unsigned int> PackageOpsDone;
+
// progress reporting
unsigned int PackagesDone;
unsigned int PackagesTotal;
@@ -68,7 +85,10 @@ class pkgDPkgPM : public pkgPackageManager
// Helpers
bool RunScriptsWithPkgs(const char *Cnf);
bool SendV2Pkgs(FILE *F);
- void WriteHistoryTag(string tag, string value);
+ void WriteHistoryTag(string const &tag, string value);
+
+ // apport integration
+ void WriteApportReport(const char *pkgpath, const char *errormsg);
// dpkg log
bool OpenLog();