From a52f938bcf7f31d348c6ce1d462a8ce14a38b8cc Mon Sep 17 00:00:00 2001 From: Otavio Salvador Date: Wed, 23 Mar 2005 21:01:54 +0000 Subject: Port DDTP to APT 0.6 branch --- apt-pkg/deb/debindexfile.cc | 138 +++++++++++++++++++++++++++++++++++++++++++ apt-pkg/deb/debindexfile.h | 29 +++++++++ apt-pkg/deb/deblistparser.cc | 41 +++++++++++++ apt-pkg/deb/deblistparser.h | 4 ++ apt-pkg/deb/debmetaindex.cc | 1 + apt-pkg/deb/debrecords.cc | 23 +++++++- apt-pkg/deb/debrecords.h | 2 + 7 files changed, 236 insertions(+), 2 deletions(-) (limited to 'apt-pkg/deb') diff --git a/apt-pkg/deb/debindexfile.cc b/apt-pkg/deb/debindexfile.cc index f26265fff..1d8c1e8ec 100644 --- a/apt-pkg/deb/debindexfile.cc +++ b/apt-pkg/deb/debindexfile.cc @@ -320,6 +320,140 @@ pkgCache::PkgFileIterator debPackagesIndex::FindInCache(pkgCache &Cache) const } /*}}}*/ +// TranslationsIndex::debTranslationsIndex - Contructor /*{{{*/ +// --------------------------------------------------------------------- +/* */ +debTranslationsIndex::debTranslationsIndex(string URI,string Dist,string Section) : + URI(URI), Dist(Dist), Section(Section) +{ +} + /*}}}*/ +// TranslationIndex::Trans* - Return the URI to the translation files /*{{{*/ +// --------------------------------------------------------------------- +/* */ +inline string debTranslationsIndex::IndexFile(const char *Type) const +{ + return _config->FindDir("Dir::State::lists") + URItoFileName(IndexURI(Type)); +} +string debTranslationsIndex::IndexURI(const char *Type) const +{ + string Res; + if (Dist[Dist.size() - 1] == '/') + { + if (Dist != "/") + Res = URI + Dist; + else + Res = URI; + } + else + Res = URI + "dists/" + Dist + '/' + Section + + "/i18n/Translation-"; + + Res += Type; + return Res; +} + /*}}}*/ +// TranslationsIndex::GetIndexes - Fetch the index files /*{{{*/ +// --------------------------------------------------------------------- +/* */ +bool debTranslationsIndex::GetIndexes(pkgAcquire *Owner) const +{ + if (UseTranslation()) { + string TranslationFile = "Translation-" + LanguageCode(); + new pkgAcqIndexTrans(Owner, IndexURI(LanguageCode().c_str()), + Info(TranslationFile.c_str()), + TranslationFile); + } + + return true; +} + /*}}}*/ +// TranslationsIndex::Describe - Give a descriptive path to the index /*{{{*/ +// --------------------------------------------------------------------- +/* This should help the user find the index in the sources.list and + in the filesystem for problem solving */ +string debTranslationsIndex::Describe(bool Short) const +{ + char S[300]; + if (Short == true) + 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()); + return S; +} + /*}}}*/ +// TranslationsIndex::Info - One liner describing the index URI /*{{{*/ +// --------------------------------------------------------------------- +/* */ +string debTranslationsIndex::Info(const char *Type) const +{ + string Info = ::URI::SiteOnly(URI) + ' '; + if (Dist[Dist.size() - 1] == '/') + { + if (Dist != "/") + Info += Dist; + } + else + Info += Dist + '/' + Section; + Info += " "; + Info += Type; + return Info; +} + /*}}}*/ +// TranslationsIndex::Exists - Check if the index is available /*{{{*/ +// --------------------------------------------------------------------- +/* */ +bool debTranslationsIndex::Exists() const +{ + return true; +} + /*}}}*/ +// TranslationsIndex::Size - Return the size of the index /*{{{*/ +// --------------------------------------------------------------------- +/* This is really only used for progress reporting. */ +unsigned long debTranslationsIndex::Size() const +{ + struct stat S; + if (stat(IndexFile(LanguageCode().c_str()).c_str(),&S) != 0) + return 0; + return S.st_size; +} + /*}}}*/ +// TranslationsIndex::Merge - Load the index file into a cache /*{{{*/ +// --------------------------------------------------------------------- +/* */ +bool debTranslationsIndex::Merge(pkgCacheGenerator &Gen,OpProgress &Prog) const +{ + // Check the translation file, if in use + string TranslationFile = IndexFile(LanguageCode().c_str()); + if (UseTranslation() && FileExists(TranslationFile)) + { + FileFd Trans(TranslationFile,FileFd::ReadOnly); + debListParser TransParser(&Trans); + if (_error->PendingError() == true) + return false; + + Prog.SubProgress(0, Info(TranslationFile.c_str())); + if (Gen.SelectFile(TranslationFile,string(),*this) == false) + return _error->Error("Problem with SelectFile %s",TranslationFile.c_str()); + + // Store the IMS information + pkgCache::PkgFileIterator TransFile = Gen.GetCurFile(); + struct stat TransSt; + if (fstat(Trans.Fd(),&TransSt) != 0) + return _error->Errno("fstat","Failed to stat"); + TransFile->Size = TransSt.st_size; + TransFile->mtime = TransSt.st_mtime; + + if (Gen.MergeList(TransParser) == false) + return _error->Error("Problem with MergeList %s",TranslationFile.c_str()); + } + + return true; +} + /*}}}*/ + // StatusIndex::debStatusIndex - Constructor /*{{{*/ // --------------------------------------------------------------------- /* */ @@ -438,6 +572,10 @@ const pkgIndexFile::Type *debPackagesIndex::GetType() const { return &_apt_Pkg; } +const pkgIndexFile::Type *debTranslationsIndex::GetType() const +{ + return &_apt_Pkg; +} const pkgIndexFile::Type *debStatusIndex::GetType() const { return &_apt_Status; diff --git a/apt-pkg/deb/debindexfile.h b/apt-pkg/deb/debindexfile.h index a1b9583a4..7bd7ea4f3 100644 --- a/apt-pkg/deb/debindexfile.h +++ b/apt-pkg/deb/debindexfile.h @@ -74,6 +74,35 @@ class debPackagesIndex : public pkgIndexFile debPackagesIndex(string URI,string Dist,string Section,bool Trusted); }; +class debTranslationsIndex : public pkgIndexFile +{ + string URI; + string Dist; + string Section; + + 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();}; + + public: + + virtual const Type *GetType() const; + + // Interface for acquire + virtual string Describe(bool Short) const; + virtual bool GetIndexes(pkgAcquire *Owner) const; + + // Interface for the Cache Generator + virtual bool Exists() const; + virtual bool HasPackages() const {return true;}; + virtual unsigned long Size() const; + virtual bool Merge(pkgCacheGenerator &Gen,OpProgress &Prog) const; + + debTranslationsIndex(string URI,string Dist,string Section); +}; + class debSourcesIndex : public pkgIndexFile { string URI; diff --git a/apt-pkg/deb/deblistparser.cc b/apt-pkg/deb/deblistparser.cc index 96a80582d..6e78ed42b 100644 --- a/apt-pkg/deb/deblistparser.cc +++ b/apt-pkg/deb/deblistparser.cc @@ -15,6 +15,7 @@ #include #include #include +#include #include @@ -117,6 +118,46 @@ bool debListParser::NewVersion(pkgCache::VerIterator Ver) return true; } /*}}}*/ +// ListParser::Description - Return the description string /*{{{*/ +// --------------------------------------------------------------------- +/* This is to return the string describing the package in debian + form. If this returns the blank string then the entry is assumed to + only describe package properties */ +string debListParser::Description() +{ + if (DescriptionLanguage().empty()) + return Section.FindS("Description"); + else + return Section.FindS(("Description-" + pkgIndexFile::LanguageCode()).c_str()); +} + /*}}}*/ +// ListParser::DescriptionLanguage - Return the description lang string /*{{{*/ +// --------------------------------------------------------------------- +/* This is to return the string describing the language of + description. If this returns the blank string then the entry is + assumed to describe original description. */ +string debListParser::DescriptionLanguage() +{ + return Section.FindS("Description").empty() ? pkgIndexFile::LanguageCode() : ""; +} + /*}}}*/ +// ListParser::Description - Return the description_md5 MD5SumValue /*{{{*/ +// --------------------------------------------------------------------- +/* This is to return the md5 string to allow the check if is the right + description. If thisreturns a blank string then calculate the md5 + value. */ +MD5SumValue debListParser::Description_md5() +{ + string value = Section.FindS("Description-md5"); + + if (value.empty()) { + MD5Summation md5; + md5.Add((Description() + "\n").c_str()); + return md5.Result(); + } else + return MD5SumValue(value); +} + /*}}}*/ // ListParser::UsePackage - Update a package structure /*{{{*/ // --------------------------------------------------------------------- /* This is called to update the package with any new information diff --git a/apt-pkg/deb/deblistparser.h b/apt-pkg/deb/deblistparser.h index 9f305211a..3a8aec3a5 100644 --- a/apt-pkg/deb/deblistparser.h +++ b/apt-pkg/deb/deblistparser.h @@ -12,6 +12,7 @@ #define PKGLIB_DEBLISTPARSER_H #include +#include #include class debListParser : public pkgCacheGenerator::ListParser @@ -47,6 +48,9 @@ class debListParser : public pkgCacheGenerator::ListParser virtual string Package(); virtual string Version(); 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); diff --git a/apt-pkg/deb/debmetaindex.cc b/apt-pkg/deb/debmetaindex.cc index 526c8c0b2..c7ae25256 100644 --- a/apt-pkg/deb/debmetaindex.cc +++ b/apt-pkg/deb/debmetaindex.cc @@ -227,6 +227,7 @@ class debSLTypeDebian : public pkgSourceList::Type debReleaseIndex *Deb = new debReleaseIndex(URI,Dist); Deb->PushSectionEntry (new debReleaseIndex::debSectionEntry(Section, IsSrc)); List.push_back(Deb); + List.push_back(new debTranslationsIndex(URI,Dist,Section)); return true; } }; diff --git a/apt-pkg/deb/debrecords.cc b/apt-pkg/deb/debrecords.cc index 6652a6ad9..518988bb6 100644 --- a/apt-pkg/deb/debrecords.cc +++ b/apt-pkg/deb/debrecords.cc @@ -12,7 +12,9 @@ #pragma implementation "apt-pkg/debrecords.h" #endif #include +#include #include +#include /*}}}*/ // RecordParser::debRecordParser - Constructor /*{{{*/ @@ -30,6 +32,10 @@ debRecordParser::debRecordParser(string FileName,pkgCache &Cache) : bool debRecordParser::Jump(pkgCache::VerFileIterator const &Ver) { return Tags.Jump(Section,Ver->Offset); +} +bool debRecordParser::Jump(pkgCache::DescFileIterator const &Desc) +{ + return Tags.Jump(Section,Desc->Offset); } /*}}}*/ // RecordParser::FileName - Return the archive filename on the site /*{{{*/ @@ -77,7 +83,7 @@ string debRecordParser::Maintainer() /* */ string debRecordParser::ShortDesc() { - string Res = Section.FindS("Description"); + string Res = LongDesc(); string::size_type Pos = Res.find('\n'); if (Pos == string::npos) return Res; @@ -89,7 +95,20 @@ string debRecordParser::ShortDesc() /* */ string debRecordParser::LongDesc() { - return Section.FindS("Description"); + 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(); + + if (strcmp(codeset,"UTF-8") != 0) { + UTF8ToCodeset(codeset, orig, &dest); + orig = dest; + } + + return orig; } /*}}}*/ // RecordParser::SourcePkg - Return the source package name if any /*{{{*/ diff --git a/apt-pkg/deb/debrecords.h b/apt-pkg/deb/debrecords.h index efef2e588..24e5aab88 100644 --- a/apt-pkg/deb/debrecords.h +++ b/apt-pkg/deb/debrecords.h @@ -19,6 +19,7 @@ #endif #include +#include #include class debRecordParser : public pkgRecords::Parser @@ -30,6 +31,7 @@ class debRecordParser : public pkgRecords::Parser protected: virtual bool Jump(pkgCache::VerFileIterator const &Ver); + virtual bool Jump(pkgCache::DescFileIterator const &Desc); public: -- cgit v1.2.3 From a7a5b0d941a8e56a1be2822226a5a81cd94d6ea6 Mon Sep 17 00:00:00 2001 From: Otavio Salvador Date: Wed, 23 Mar 2005 22:38:53 +0000 Subject: Fix problems due APT and structural changes. - apt-pkg/acquire-item.cc: pass the expected md5 and compressed extenssion as empty in pkgAcqIndexTrans::pkgAcqIndexTrans(...) constructor; - apt-pkg/deb/debindexfile.cc: identify translation files as trusted; - apt-pkg/deb/debmetaindex.cc: change the way it's queue the translation file due a change in APT structure did in 0.6 branch; --- apt-pkg/deb/debindexfile.cc | 2 +- apt-pkg/deb/debmetaindex.cc | 6 ++++-- 2 files changed, 5 insertions(+), 3 deletions(-) (limited to 'apt-pkg/deb') diff --git a/apt-pkg/deb/debindexfile.cc b/apt-pkg/deb/debindexfile.cc index 1d8c1e8ec..4113137eb 100644 --- a/apt-pkg/deb/debindexfile.cc +++ b/apt-pkg/deb/debindexfile.cc @@ -324,7 +324,7 @@ pkgCache::PkgFileIterator debPackagesIndex::FindInCache(pkgCache &Cache) const // --------------------------------------------------------------------- /* */ debTranslationsIndex::debTranslationsIndex(string URI,string Dist,string Section) : - URI(URI), Dist(Dist), Section(Section) + pkgIndexFile(true), URI(URI), Dist(Dist), Section(Section) { } /*}}}*/ diff --git a/apt-pkg/deb/debmetaindex.cc b/apt-pkg/deb/debmetaindex.cc index c7ae25256..7f15fd2e1 100644 --- a/apt-pkg/deb/debmetaindex.cc +++ b/apt-pkg/deb/debmetaindex.cc @@ -177,11 +177,14 @@ vector *debReleaseIndex::GetIndexFiles() Indexes = new vector ; for (vector::const_iterator I = SectionEntries.begin(); - I != SectionEntries.end(); I++) + 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)); + } + return Indexes; } @@ -227,7 +230,6 @@ class debSLTypeDebian : public pkgSourceList::Type debReleaseIndex *Deb = new debReleaseIndex(URI,Dist); Deb->PushSectionEntry (new debReleaseIndex::debSectionEntry(Section, IsSrc)); List.push_back(Deb); - List.push_back(new debTranslationsIndex(URI,Dist,Section)); return true; } }; -- cgit v1.2.3 From c51c6f08ab15d09e1585ab7e680b53f87d654d6b Mon Sep 17 00:00:00 2001 From: Otavio Salvador Date: Fri, 13 May 2005 14:05:10 +0000 Subject: Add FindInCache method to skip the rebuild of cache every time. --- apt-pkg/deb/debindexfile.cc | 23 ++++++++++++++++++++++- apt-pkg/deb/debindexfile.h | 1 + 2 files changed, 23 insertions(+), 1 deletion(-) (limited to 'apt-pkg/deb') diff --git a/apt-pkg/deb/debindexfile.cc b/apt-pkg/deb/debindexfile.cc index 4113137eb..b8435a6bc 100644 --- a/apt-pkg/deb/debindexfile.cc +++ b/apt-pkg/deb/debindexfile.cc @@ -453,7 +453,28 @@ bool debTranslationsIndex::Merge(pkgCacheGenerator &Gen,OpProgress &Prog) const return true; } /*}}}*/ - +// TranslationsIndex::FindInCache - Find this index /*{{{*/ +// --------------------------------------------------------------------- +/* */ +pkgCache::PkgFileIterator debTranslationsIndex::FindInCache(pkgCache &Cache) const +{ + pkgCache::PkgFileIterator File = Cache.FileBegin(); + if (this->UseTranslation()) + for (; File.end() == false; File++) + { + if (IndexFile(LanguageCode().c_str()) != File.FileName()) + continue; + + struct stat St; + if (stat(File.FileName(),&St) != 0) + return pkgCache::PkgFileIterator(Cache); + if ((unsigned)St.st_size != File->Size || St.st_mtime != File->mtime) + return pkgCache::PkgFileIterator(Cache); + return File; + } + return File; +} + /*}}}*/ // StatusIndex::debStatusIndex - Constructor /*{{{*/ // --------------------------------------------------------------------- /* */ diff --git a/apt-pkg/deb/debindexfile.h b/apt-pkg/deb/debindexfile.h index 7bd7ea4f3..6d423318e 100644 --- a/apt-pkg/deb/debindexfile.h +++ b/apt-pkg/deb/debindexfile.h @@ -99,6 +99,7 @@ class debTranslationsIndex : public pkgIndexFile virtual bool HasPackages() const {return true;}; virtual unsigned long Size() const; virtual bool Merge(pkgCacheGenerator &Gen,OpProgress &Prog) const; + virtual pkgCache::PkgFileIterator FindInCache(pkgCache &Cache) const; debTranslationsIndex(string URI,string Dist,string Section); }; -- cgit v1.2.3 From f416d22e97c56eedc8b4303a5aecfffaaa23eb1c Mon Sep 17 00:00:00 2001 From: Michael Vogt Date: Fri, 13 May 2005 14:40:29 +0000 Subject: * fixed a problem when it comes to the cache rebuilding --- apt-pkg/deb/debindexfile.cc | 25 +++++++++++++------------ apt-pkg/deb/debindexfile.h | 2 +- 2 files changed, 14 insertions(+), 13 deletions(-) (limited to 'apt-pkg/deb') diff --git a/apt-pkg/deb/debindexfile.cc b/apt-pkg/deb/debindexfile.cc index b8435a6bc..67fddfbd4 100644 --- a/apt-pkg/deb/debindexfile.cc +++ b/apt-pkg/deb/debindexfile.cc @@ -458,20 +458,21 @@ bool debTranslationsIndex::Merge(pkgCacheGenerator &Gen,OpProgress &Prog) const /* */ pkgCache::PkgFileIterator debTranslationsIndex::FindInCache(pkgCache &Cache) const { + string FileName = TranslationFile(); + pkgCache::PkgFileIterator File = Cache.FileBegin(); - if (this->UseTranslation()) - for (; File.end() == false; File++) - { - if (IndexFile(LanguageCode().c_str()) != File.FileName()) - continue; + for (; File.end() == false; File++) + { + if (FileName != File.FileName()) + continue; - struct stat St; - if (stat(File.FileName(),&St) != 0) - return pkgCache::PkgFileIterator(Cache); - if ((unsigned)St.st_size != File->Size || St.st_mtime != File->mtime) - return pkgCache::PkgFileIterator(Cache); - return File; - } + struct stat St; + if (stat(File.FileName(),&St) != 0) + return pkgCache::PkgFileIterator(Cache); + if ((unsigned)St.st_size != File->Size || St.st_mtime != File->mtime) + return pkgCache::PkgFileIterator(Cache); + return File; + } return File; } /*}}}*/ diff --git a/apt-pkg/deb/debindexfile.h b/apt-pkg/deb/debindexfile.h index 6d423318e..02c776882 100644 --- a/apt-pkg/deb/debindexfile.h +++ b/apt-pkg/deb/debindexfile.h @@ -96,7 +96,7 @@ class debTranslationsIndex : public pkgIndexFile // Interface for the Cache Generator virtual bool Exists() const; - virtual bool HasPackages() const {return true;}; + virtual bool HasPackages() const { return UseTranslation();}; virtual unsigned long Size() const; virtual bool Merge(pkgCacheGenerator &Gen,OpProgress &Prog) const; virtual pkgCache::PkgFileIterator FindInCache(pkgCache &Cache) const; -- cgit v1.2.3 From e82bdb118257ddea01a26f0c5503e06d17ae8794 Mon Sep 17 00:00:00 2001 From: Michael Vogt Date: Fri, 13 May 2005 17:51:05 +0000 Subject: * fix for output of the description and the debTranslationsIndex::Exists() --- apt-pkg/deb/debindexfile.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'apt-pkg/deb') diff --git a/apt-pkg/deb/debindexfile.cc b/apt-pkg/deb/debindexfile.cc index 67fddfbd4..ffecbdfca 100644 --- a/apt-pkg/deb/debindexfile.cc +++ b/apt-pkg/deb/debindexfile.cc @@ -406,7 +406,7 @@ string debTranslationsIndex::Info(const char *Type) const /* */ bool debTranslationsIndex::Exists() const { - return true; + return FileExists(IndexFile(LanguageCode().c_str())); } /*}}}*/ // TranslationsIndex::Size - Return the size of the index /*{{{*/ -- cgit v1.2.3 From 97234432dbd652bc13a419dc37fda1e5cd3622a5 Mon Sep 17 00:00:00 2001 From: Michael Vogt Date: Fri, 13 May 2005 19:43:07 +0000 Subject: * made the translation downloading work --- apt-pkg/deb/debindexfile.cc | 8 +++++++- apt-pkg/deb/debmetaindex.cc | 8 ++++++++ 2 files changed, 15 insertions(+), 1 deletion(-) (limited to 'apt-pkg/deb') diff --git a/apt-pkg/deb/debindexfile.cc b/apt-pkg/deb/debindexfile.cc index ffecbdfca..c7c36b89a 100644 --- a/apt-pkg/deb/debindexfile.cc +++ b/apt-pkg/deb/debindexfile.cc @@ -572,6 +572,11 @@ class debIFTypePkg : public pkgIndexFile::Type }; debIFTypePkg() {Label = "Debian Package Index";}; }; +class debIFTypeTrans : public debIFTypePkg +{ + public: + debIFTypeTrans() {Label = "Debian Translation Index";}; +}; class debIFTypeStatus : public pkgIndexFile::Type { public: @@ -584,6 +589,7 @@ class debIFTypeStatus : public pkgIndexFile::Type }; static debIFTypeSrc _apt_Src; static debIFTypePkg _apt_Pkg; +static debIFTypeTrans _apt_Trans; static debIFTypeStatus _apt_Status; const pkgIndexFile::Type *debSourcesIndex::GetType() const @@ -596,7 +602,7 @@ const pkgIndexFile::Type *debPackagesIndex::GetType() const } const pkgIndexFile::Type *debTranslationsIndex::GetType() const { - return &_apt_Pkg; + return &_apt_Trans; } const pkgIndexFile::Type *debStatusIndex::GetType() const { diff --git a/apt-pkg/deb/debmetaindex.cc b/apt-pkg/deb/debmetaindex.cc index 7f15fd2e1..9c7828d6a 100644 --- a/apt-pkg/deb/debmetaindex.cc +++ b/apt-pkg/deb/debmetaindex.cc @@ -157,6 +157,14 @@ bool debReleaseIndex::GetIndexes(pkgAcquire *Owner, bool GetAll) const ComputeIndexTargets(), new indexRecords (Dist)); + // Queue the translations + for (vector::const_iterator I = SectionEntries.begin(); + I != SectionEntries.end(); I++) { + + debTranslationsIndex i = debTranslationsIndex(URI,Dist,(*I)->Section); + i.GetIndexes(Owner); + } + return true; } -- cgit v1.2.3 From 4d34acf1a0c8319fa498d4dd6ac5cfd369d3c29e Mon Sep 17 00:00:00 2001 From: Michael Vogt Date: Fri, 13 May 2005 19:56:27 +0000 Subject: * FindInCache() uses the correct file now --- apt-pkg/deb/debindexfile.cc | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'apt-pkg/deb') diff --git a/apt-pkg/deb/debindexfile.cc b/apt-pkg/deb/debindexfile.cc index c7c36b89a..b57493b9e 100644 --- a/apt-pkg/deb/debindexfile.cc +++ b/apt-pkg/deb/debindexfile.cc @@ -458,14 +458,14 @@ bool debTranslationsIndex::Merge(pkgCacheGenerator &Gen,OpProgress &Prog) const /* */ pkgCache::PkgFileIterator debTranslationsIndex::FindInCache(pkgCache &Cache) const { - string FileName = TranslationFile(); - + string FileName = IndexFile(LanguageCode().c_str()); + pkgCache::PkgFileIterator File = Cache.FileBegin(); for (; File.end() == false; File++) { if (FileName != File.FileName()) continue; - + struct stat St; if (stat(File.FileName(),&St) != 0) return pkgCache::PkgFileIterator(Cache); -- cgit v1.2.3 From 11680bfd380d52c96feeb76600e50a145838b329 Mon Sep 17 00:00:00 2001 From: Michael Vogt Date: Fri, 13 May 2005 21:31:54 +0000 Subject: * don't throw any more warnings --- apt-pkg/deb/debindexfile.cc | 8 ++++++++ apt-pkg/deb/debindexfile.h | 2 +- 2 files changed, 9 insertions(+), 1 deletion(-) (limited to 'apt-pkg/deb') diff --git a/apt-pkg/deb/debindexfile.cc b/apt-pkg/deb/debindexfile.cc index b57493b9e..5510ad161 100644 --- a/apt-pkg/deb/debindexfile.cc +++ b/apt-pkg/deb/debindexfile.cc @@ -401,6 +401,14 @@ string debTranslationsIndex::Info(const char *Type) const return Info; } /*}}}*/ +bool debTranslationsIndex::HasPackages() const +{ + if(!UseTranslation()) + return false; + + return FileExists(IndexFile(LanguageCode().c_str())); +} + // TranslationsIndex::Exists - Check if the index is available /*{{{*/ // --------------------------------------------------------------------- /* */ diff --git a/apt-pkg/deb/debindexfile.h b/apt-pkg/deb/debindexfile.h index 02c776882..57005222f 100644 --- a/apt-pkg/deb/debindexfile.h +++ b/apt-pkg/deb/debindexfile.h @@ -96,7 +96,7 @@ class debTranslationsIndex : public pkgIndexFile // Interface for the Cache Generator virtual bool Exists() const; - virtual bool HasPackages() const { return UseTranslation();}; + virtual bool HasPackages() const; virtual unsigned long Size() const; virtual bool Merge(pkgCacheGenerator &Gen,OpProgress &Prog) const; virtual pkgCache::PkgFileIterator FindInCache(pkgCache &Cache) const; -- cgit v1.2.3 From 770c32ec8572c397d035d2703a15b699d4a76842 Mon Sep 17 00:00:00 2001 From: Michael Vogt Date: Thu, 28 Jul 2005 09:59:06 +0000 Subject: * code cleanups (thanks matt!), moved UsePackage before the description list build in pkgcachegen to catch MMap errors early --- apt-pkg/deb/debindexfile.cc | 6 +++--- apt-pkg/deb/deblistparser.cc | 10 ++++++---- apt-pkg/deb/debmetaindex.cc | 4 +++- 3 files changed, 12 insertions(+), 8 deletions(-) (limited to 'apt-pkg/deb') diff --git a/apt-pkg/deb/debindexfile.cc b/apt-pkg/deb/debindexfile.cc index 5510ad161..23cc7d075 100644 --- a/apt-pkg/deb/debindexfile.cc +++ b/apt-pkg/deb/debindexfile.cc @@ -358,7 +358,7 @@ string debTranslationsIndex::IndexURI(const char *Type) const /* */ bool debTranslationsIndex::GetIndexes(pkgAcquire *Owner) const { - if (UseTranslation()) { + if (TranslationsAvailable()) { string TranslationFile = "Translation-" + LanguageCode(); new pkgAcqIndexTrans(Owner, IndexURI(LanguageCode().c_str()), Info(TranslationFile.c_str()), @@ -403,7 +403,7 @@ string debTranslationsIndex::Info(const char *Type) const /*}}}*/ bool debTranslationsIndex::HasPackages() const { - if(!UseTranslation()) + if(!TranslationsAvailable()) return false; return FileExists(IndexFile(LanguageCode().c_str())); @@ -435,7 +435,7 @@ bool debTranslationsIndex::Merge(pkgCacheGenerator &Gen,OpProgress &Prog) const { // Check the translation file, if in use string TranslationFile = IndexFile(LanguageCode().c_str()); - if (UseTranslation() && FileExists(TranslationFile)) + if (TranslationsAvailable() && FileExists(TranslationFile)) { FileFd Trans(TranslationFile,FileFd::ReadOnly); debListParser TransParser(&Trans); diff --git a/apt-pkg/deb/deblistparser.cc b/apt-pkg/deb/deblistparser.cc index 6e78ed42b..fcc31ec2c 100644 --- a/apt-pkg/deb/deblistparser.cc +++ b/apt-pkg/deb/deblistparser.cc @@ -143,14 +143,16 @@ string debListParser::DescriptionLanguage() /*}}}*/ // ListParser::Description - Return the description_md5 MD5SumValue /*{{{*/ // --------------------------------------------------------------------- -/* This is to return the md5 string to allow the check if is the right - description. If thisreturns a blank string then calculate the md5 - value. */ +/* This is to return the md5 string to allow the check if it is the right + description. If no Description-md5 is found in the section it will be + calculated. + */ MD5SumValue debListParser::Description_md5() { string value = Section.FindS("Description-md5"); - if (value.empty()) { + if (value.empty()) + { MD5Summation md5; md5.Add((Description() + "\n").c_str()); return md5.Result(); diff --git a/apt-pkg/deb/debmetaindex.cc b/apt-pkg/deb/debmetaindex.cc index 9c7828d6a..8dfbf7aff 100644 --- a/apt-pkg/deb/debmetaindex.cc +++ b/apt-pkg/deb/debmetaindex.cc @@ -189,8 +189,10 @@ vector *debReleaseIndex::GetIndexFiles() 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)); + Indexes->push_back(new debTranslationsIndex(URI, Dist, (*I)->Section)); + } } return Indexes; -- cgit v1.2.3 From e011829d8727296996909fd4f744962bf236d751 Mon Sep 17 00:00:00 2001 From: Michael Vogt Date: Tue, 30 Aug 2005 13:44:03 +0000 Subject: * updated with mainline Patches applied: * andrelop@debian.org/apt--translation--0--base-0 tag of apt@packages.debian.org/apt--main--0--patch-79 * andrelop@debian.org/apt--translation--0--patch-1 Sync with Matt version. * andrelop@debian.org/apt--translation--0--patch-2 Update pt_BR translation * andrelop@debian.org/apt--translation--0--patch-3 Sync with bubulle's branch. * apt@packages.debian.org/apt--main--0--patch-88 Change debian/bugscript to use #!/bin/bash (Closes: #313402) * apt@packages.debian.org/apt--main--0--patch-89 Branch for Debian * apt@packages.debian.org/apt--main--0--patch-90 Update version in configure * apt@packages.debian.org/apt--main--0--patch-91 Fix French man page build * apt@packages.debian.org/apt--main--0--patch-92 Add the current Debian archive signing key * apt@packages.debian.org/apt--main--0--patch-93 Merge with mvo * apt@packages.debian.org/apt--main--0--patch-94 Update changelog * apt@packages.debian.org/apt--main--0--patch-95 Merge Christian's branch * apt@packages.debian.org/apt--main--0--patch-96 Update changelog * apt@packages.debian.org/apt--main--0--patch-97 Update priority of apt-utils to important, to match the override file * apt@packages.debian.org/apt--main--0--patch-98 Install only one keyring on each branch (Closes: #316119) * apt@packages.debian.org/apt--main--0--patch-99 Finalize 0.6.39 * apt@packages.debian.org/apt--main--0--patch-100 Use debian.org address in mainline * apt@packages.debian.org/apt--main--0--patch-101 Update pot file * apt@packages.debian.org/apt--main--0--patch-102 Open 0.6.40 * apt@packages.debian.org/apt--main--0--patch-103 Patch from Jordi Mallach to mark some additional strings for translation * apt@packages.debian.org/apt--main--0--patch-104 Updated Catalan translation from Jordi Mallach * apt@packages.debian.org/apt--main--0--patch-105 Merge from bubulle@debian.org--2005/apt--main--0 * apt@packages.debian.org/apt--main--0--patch-106 Restore lost changelog entries * apt@packages.debian.org/apt--main--0--patch-107 Merge michael.vogt@ubuntu.com--2005/apt--progress-reporting--0 * apt@packages.debian.org/apt--main--0--patch-108 Merge michael.vogt@ubuntu.com--2005/apt--progress-reporting--0 * apt@packages.debian.org/apt--main--0--patch-109 Merge michael.vogt@ubuntu.com--2005/apt--progress-reporting--0 * apt@packages.debian.org/apt--main--0--patch-110 Merge michael.vogt@ubuntu.com--2005/apt--progress-reporting--0 * bubulle@debian.org--2005/apt--main--0--patch-82 Fix permissions * bubulle@debian.org--2005/apt--main--0--patch-83 French translation spellchecked * bubulle@debian.org--2005/apt--main--0--patch-84 Spell corrections in German translations * bubulle@debian.org--2005/apt--main--0--patch-85 Correct some file permissions * bubulle@debian.org--2005/apt--main--0--patch-86 Correct Hebrew translation * bubulle@debian.org--2005/apt--main--0--patch-87 Sync Portuguese translation with the POT file * bubulle@debian.org--2005/apt--main--0--patch-88 Updated Danish translation (not yet complete) * bubulle@debian.org--2005/apt--main--0--patch-89 Sync with Andre Luis Lopes and Otavio branches * bubulle@debian.org--2005/apt--main--0--patch-90 Merge with Matt * bubulle@debian.org--2005/apt--main--0--patch-91 Updated Slovak translation * bubulle@debian.org--2005/apt--main--0--patch-92 Add apt-key French man page * bubulle@debian.org--2005/apt--main--0--patch-93 Update Greek translations * bubulle@debian.org--2005/apt--main--0--patch-94 Merge with Matt * bubulle@debian.org--2005/apt--main--0--patch-95 Sync PO files with the POT file/French translation update * michael.vogt@ubuntu.com--2005/apt--fixes--0--patch-5 * merged with apt--main--0 * michael.vogt@ubuntu.com--2005/apt--fixes--0--patch-6 * build fix for apt--main--0 * michael.vogt@ubuntu.com--2005/apt--mvo--0--patch-22 * added myself to uploaders, changelog is signed with mvo@debian.org and in sync with the debian/experimental upload * michael.vogt@ubuntu.com--2005/apt--mvo--0--patch-23 * apt-cache show shows all virtual packages instead of nothing (thanks to otavio) * michael.vogt@ubuntu.com--2005/apt--mvo--0--patch-24 * changelog updated * michael.vogt@ubuntu.com--2005/apt--mvo--0--patch-25 * make pinning on component work again (we just use the section, as apt-0.6 don't use per-section Release files anymore) * michael.vogt@ubuntu.com--2005/apt--mvo--0--patch-27 * updated the changelog * michael.vogt@ubuntu.com--2005/apt--mvo--0--patch-28 * merged with my apt--fixes--0 branch * michael.vogt@ubuntu.com--2005/apt--mvo--0--patch-29 * added a missing OpProgress::Done() in depCache::Init(), removed the show-virtual-packages patch in apt-cache because matt does not like him :/ * michael.vogt@ubuntu.com--2005/apt--mvo--0--patch-30 * fix a stupid bug in the depcache::Init() code * michael.vogt@ubuntu.com--2005/apt--mvo--0--patch-31 * merged/removed conflicts with apt--main--0 * michael.vogt@ubuntu.com--2005/apt--mvo--0--patch-32 * merged apt--main and make sure that the po files come from apt--main (because they are more recent) * michael.vogt@ubuntu.com--2005/apt--progress-reporting--0--base-0 tag of apt@packages.debian.org/apt--main--0--patch-85 * michael.vogt@ubuntu.com--2005/apt--progress-reporting--0--patch-1 * inital proof of concept code, understands what dpkg tells it already * michael.vogt@ubuntu.com--2005/apt--progress-reporting--0--patch-2 * progress reporting works now * michael.vogt@ubuntu.com--2005/apt--progress-reporting--0--patch-3 * added "APT::Status-Fd" variable * michael.vogt@ubuntu.com--2005/apt--progress-reporting--0--patch-4 * do i18n now too * michael.vogt@ubuntu.com--2005/apt--progress-reporting--0--patch-5 * define N_(x) if it is not defined already * michael.vogt@ubuntu.com--2005/apt--progress-reporting--0--patch-6 * PackageManager::DoInstall(int status_fd) added (does not break the ABI) * michael.vogt@ubuntu.com--2005/apt--progress-reporting--0--patch-7 * merged with apt--fixes--0 to make it build again * michael.vogt@ubuntu.com--2005/apt--progress-reporting--0--patch-8 * added support for "error" and "conffile-prompt" messages from dpkg * michael.vogt@ubuntu.com--2005/apt--progress-reporting--0--patch-9 merge with main * michael.vogt@ubuntu.com--2005/apt--progress-reporting--0--patch-10 * use sizeof() for all snprintf() uses; fix a potential line break problem in the status reading code; changed the N_() to _() calls * michael.vogt@ubuntu.com--2005/apt--progress-reporting--0--patch-11 * added APT::KeepFDs configuration list for file descriptors that apt should leave open (needed for various frontends like debconf, synaptic) * michael.vogt@ubuntu.com--2005/apt--progress-reporting--0--patch-12 * fixed a API breakage * michael.vogt@ubuntu.com--2005/apt--progress-reporting--0--patch-13 * doc added, should be releasable now * michael.vogt@ubuntu.com--2005/apt--progress-reporting--0--patch-14 * merged with apt--main--0 * michael.vogt@ubuntu.com--2005/apt--progress-reporting--0--patch-15 * more source comments, added Debug::DpkgPM debug code to inspect the dpkg<->apt communication, broke the abi (ok with matt) * michael.vogt@ubuntu.com--2005/apt--progress-reporting--0--patch-16 * the progress reporting has it's own "Debug::pkgDPkgProgressReporting" debug variable now * michael.vogt@ubuntu.com--2005/apt--progress-reporting--0--patch-17 * merged PackageOps and TranslatedPackageOps into a single Map with the new DpkgState struct * michael.vogt@ubuntu.com--2005/apt--progress-reporting--0--patch-18 * clear the APT::Keep-Fds configuration when it's no longer needed * michael.vogt@ubuntu.com--2005/apt--progress-reporting--0--patch-19 * rewrote the reading from dpkg so that it never blocks * michael.vogt@ubuntu.com--2005/apt--progress-reporting--0--patch-20 * merged the two status arrays into one * michael.vogt@ubuntu.com--2005/apt--progress-reporting--0--patch-21 * added support for download progress reporting too (for Kamion and base-config) * michael.vogt@ubuntu.com--2005/apt--progress-reporting--0--patch-22 * ABI break; added Configuration::Clear(string List, {int,string} value) added (to remove a single Value from a list); test/conf_clear.cc added * michael.vogt@ubuntu.com--2005/apt--progress-reporting--0--patch-23 * remvoed a debug string * michael.vogt@ubuntu.com--2005/apt--progress-reporting--0--patch-24 * soname changed, fixed a bug in the parsing code when dpkg send the same state more than once (at the end) * michael.vogt@ubuntu.com--2005/apt--progress-reporting--0--patch-25 * merged with apt@packages.debian.org/apt--main--0, added changelog entry for the 0.6.40.1 upload * michael.vogt@ubuntu.com--2005/apt--progress-reporting--0--patch-26 * fix a bug when out-of-order states are send from dpkg * michael.vogt@ubuntu.com--2005/apt--progress-reporting--0--patch-27 * changelog update * michael.vogt@ubuntu.com--2005/apt--progress-reporting--0--patch-28 * a real changelog entry now * michael.vogt@ubuntu.com--2005/apt--progress-reporting--0--patch-29 * changelog finalized * michael.vogt@ubuntu.com--2005/apt--progress-reporting--0--patch-30 * propper (and sane) support for pmerror and pmconffile added --- apt-pkg/deb/debindexfile.cc | 4 +- apt-pkg/deb/deblistparser.cc | 11 +- apt-pkg/deb/deblistparser.h | 3 +- apt-pkg/deb/dpkgpm.cc | 242 ++++++++++++++++++++++++++++++++++++++----- apt-pkg/deb/dpkgpm.h | 9 +- 5 files changed, 237 insertions(+), 32 deletions(-) (limited to 'apt-pkg/deb') diff --git a/apt-pkg/deb/debindexfile.cc b/apt-pkg/deb/debindexfile.cc index 23cc7d075..38ecdd16a 100644 --- a/apt-pkg/deb/debindexfile.cc +++ b/apt-pkg/deb/debindexfile.cc @@ -24,7 +24,7 @@ #include #include #include - + #include /*}}}*/ @@ -290,7 +290,7 @@ bool debPackagesIndex::Merge(pkgCacheGenerator &Gen,OpProgress &Prog) const FileFd Rel(ReleaseFile,FileFd::ReadOnly); if (_error->PendingError() == true) return false; - Parser.LoadReleaseInfo(File,Rel); + Parser.LoadReleaseInfo(File,Rel,Section); } return true; diff --git a/apt-pkg/deb/deblistparser.cc b/apt-pkg/deb/deblistparser.cc index fcc31ec2c..97553ab82 100644 --- a/apt-pkg/deb/deblistparser.cc +++ b/apt-pkg/deb/deblistparser.cc @@ -607,13 +607,20 @@ bool debListParser::Step() // --------------------------------------------------------------------- /* */ bool debListParser::LoadReleaseInfo(pkgCache::PkgFileIterator FileI, - FileFd &File) + FileFd &File, string component) { pkgTagFile Tags(&File, File.Size() + 256); // XXX pkgTagSection Section; 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); + + // apt-secure does no longer download individual (per-section) Release + // file. to provide Component pinning we use the section name now + FileI->Component = WriteUniqString(component); + const char *Start; const char *Stop; if (Section.Find("Suite",Start,Stop) == true) @@ -632,7 +639,7 @@ bool debListParser::LoadReleaseInfo(pkgCache::PkgFileIterator FileI, if (Section.FindFlag("NotAutomatic",FileI->Flags, pkgCache::Flag::NotAutomatic) == false) _error->Warning("Bad NotAutomatic flag"); - + return !_error->PendingError(); } /*}}}*/ diff --git a/apt-pkg/deb/deblistparser.h b/apt-pkg/deb/deblistparser.h index 3a8aec3a5..34bb29c72 100644 --- a/apt-pkg/deb/deblistparser.h +++ b/apt-pkg/deb/deblistparser.h @@ -59,7 +59,8 @@ class debListParser : public pkgCacheGenerator::ListParser 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, diff --git a/apt-pkg/deb/dpkgpm.cc b/apt-pkg/deb/dpkgpm.cc index 61c48dcbb..fe8fbca74 100644 --- a/apt-pkg/deb/dpkgpm.cc +++ b/apt-pkg/deb/dpkgpm.cc @@ -25,7 +25,11 @@ #include #include #include -#include +#include +#include + +#include +#include /*}}}*/ using namespace std; @@ -325,8 +329,14 @@ bool pkgDPkgPM::RunScriptsWithPkgs(const char *Cnf) /*}}}*/ // DPkgPM::Go - Run the sequence /*{{{*/ // --------------------------------------------------------------------- -/* This globs the operations and calls dpkg */ -bool pkgDPkgPM::Go(int status_fd) +/* This globs the operations and calls dpkg + * + * If it is called with "OutStatusFd" set to a valid file descriptor + * apt will report the install progress over this fd. It maps the + * dpkg states a package goes through to human readable (and i10n-able) + * names and calculates a percentage for each step. +*/ +bool pkgDPkgPM::Go(int OutStatusFd) { unsigned int MaxArgs = _config->FindI("Dpkg::MaxArgs",8*1024); unsigned int MaxArgBytes = _config->FindI("Dpkg::MaxArgBytes",32*1024); @@ -336,7 +346,66 @@ bool pkgDPkgPM::Go(int status_fd) if (RunScriptsWithPkgs("DPkg::Pre-Install-Pkgs") == false) return false; + + // prepare the progress reporting + int Done = 0; + int Total = 0; + // map the dpkg states to the operations that are performed + // (this is sorted in the same way as Item::Ops) + static const struct DpkgState DpkgStatesOpMap[][5] = { + // Install operation + { + {"half-installed", _("Preparing %s")}, + {"unpacked", _("Unpacking %s") }, + {NULL, NULL} + }, + // Configure operation + { + {"unpacked",_("Preparing to configure %s") }, + {"half-configured", _("Configuring %s") }, + { "installed", _("Installed %s")}, + {NULL, NULL} + }, + // Remove operation + { + {"half-configured", _("Preparing for removal of %s")}, + {"half-installed", _("Removing %s")}, + {"config-files", _("Removed %s")}, + {NULL, NULL} + }, + // Purge operation + { + {"config-files", _("Preparing for remove with config %s")}, + {"not-installed", _("Removed with config %s")}, + {NULL, NULL} + }, + }; + // the dpkg states that the pkg will run through, the string is + // the package, the vector contains the dpkg states that the package + // will go through + map > PackageOps; + // the dpkg states that are already done; the string is the package + // 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 PackageOpsDone; + + // init the PackageOps map, go over the list of packages that + // that will be [installed|configured|removed|purged] and add + // them to the PackageOps map (the dpkg states it goes through) + // and the PackageOpsTranslations (human readable strings) + for (vector::iterator I = List.begin(); I != List.end();I++) + { + string name = (*I).Pkg.Name(); + PackageOpsDone[name] = 0; + for(int i=0; (DpkgStatesOpMap[(*I).Op][i]).state != NULL; i++) + { + PackageOps[name].push_back(DpkgStatesOpMap[(*I).Op][i]); + Total++; + } + } + + // this loop is runs once per operation for (vector::iterator I = List.begin(); I != List.end();) { vector::iterator J = I; @@ -367,16 +436,15 @@ bool pkgDPkgPM::Go(int status_fd) } } - // if we got a status_fd argument, we pass it to apt char status_fd_buf[20]; - if(status_fd > 0) - { - Args[n++] = "--status-fd"; - Size += strlen(Args[n-1]); - snprintf(status_fd_buf,20,"%i",status_fd); - Args[n++] = status_fd_buf; - Size += strlen(Args[n-1]); - } + int fd[2]; + pipe(fd); + + Args[n++] = "--status-fd"; + Size += strlen(Args[n-1]); + snprintf(status_fd_buf,sizeof(status_fd_buf),"%i", fd[1]); + Args[n++] = status_fd_buf; + Size += strlen(Args[n-1]); switch (I->Op) { @@ -449,17 +517,17 @@ bool pkgDPkgPM::Go(int status_fd) it doesn't die but we do! So we must also ignore it */ sighandler_t old_SIGQUIT = signal(SIGQUIT,SIG_IGN); sighandler_t old_SIGINT = signal(SIGINT,SIG_IGN); - - // Fork dpkg + + // Fork dpkg pid_t Child; - if(status_fd > 0) - Child = ExecFork(status_fd); - else - Child = ExecFork(); + _config->Set("APT::Keep-Fds::",fd[1]); + Child = ExecFork(); // This is the child if (Child == 0) { + close(fd[0]); // close the read end of the pipe + if (chdir(_config->FindDir("DPkg::Run-Directory","/").c_str()) != 0) _exit(100); @@ -487,19 +555,141 @@ bool pkgDPkgPM::Go(int status_fd) _exit(100); } + // clear the Keep-Fd again + _config->Clear("APT::Keep-Fds",fd[1]); + // Wait for dpkg int Status = 0; - while (waitpid(Child,&Status,0) != Child) - { - if (errno == EINTR) + + // we read from dpkg here + int _dpkgin = fd[0]; + fcntl(_dpkgin, F_SETFL, O_NONBLOCK); + close(fd[1]); // close the write end of the pipe + + // the read buffers for the communication with dpkg + char line[1024] = {0,}; + char buf[2] = {0,0}; + + // the result of the waitpid call + int res; + + while ((res=waitpid(Child,&Status, WNOHANG)) != Child) { + if(res < 0) { + // FIXME: move this to a function or something, looks ugly here + // error handling, waitpid returned -1 + if (errno == EINTR) + continue; + RunScripts("DPkg::Post-Invoke"); + + // Restore sig int/quit + signal(SIGQUIT,old_SIGQUIT); + signal(SIGINT,old_SIGINT); + return _error->Errno("waitpid","Couldn't wait for subprocess"); + } + + // read a single char, make sure that the read can't block + // (otherwise we may leave zombies) + int len = read(_dpkgin, buf, 1); + + // nothing to read, wait a bit for more + if(len <= 0) + { + usleep(1000); continue; - RunScripts("DPkg::Post-Invoke"); + } + + // sanity check (should never happen) + if(strlen(line) >= sizeof(line)-10) + { + _error->Error("got a overlong line from dpkg: '%s'",line); + line[0]=0; + } + // append to line, check if we got a complete line + strcat(line, buf); + if(buf[0] != '\n') + continue; + + if (_config->FindB("Debug::pkgDPkgProgressReporting",false) == true) + std::clog << "got from dpkg '" << line << "'" << std::endl; + + // the status we output + ostringstream status; + + /* dpkg sends strings like this: + 'status: : ' + errors look like this: + 'status: /var/cache/apt/archives/krecipes_0.8.1-0ubuntu1_i386.deb : error : trying to overwrite `/usr/share/doc/kde/HTML/en/krecipes/krectip.png', which is also in package krecipes-data + and conffile-prompt like this + 'status: conffile-prompt: conffile : 'current-conffile' 'new-conffile' useredited distedited + + */ + char* list[4]; + TokSplitString(':', line, list, 5); + char *pkg = list[1]; + char *action = _strstrip(list[2]); + + if(strncmp(action,"error",strlen("error")) == 0) + { + status << "pmerror:" << list[1] + << ":" << (Done/float(Total)*100.0) + << ":" << list[3] + << endl; + if(OutStatusFd > 0) + write(OutStatusFd, status.str().c_str(), status.str().size()); + line[0]=0; + if (_config->FindB("Debug::pkgDPkgProgressReporting",false) == true) + std::clog << "send: '" << status.str() << "'" << endl; + continue; + } + if(strncmp(action,"conffile",strlen("conffile")) == 0) + { + status << "pmconffile:" << list[1] + << ":" << (Done/float(Total)*100.0) + << ":" << list[3] + << endl; + if(OutStatusFd > 0) + write(OutStatusFd, status.str().c_str(), status.str().size()); + line[0]=0; + if (_config->FindB("Debug::pkgDPkgProgressReporting",false) == true) + std::clog << "send: '" << status.str() << "'" << endl; + continue; + } + + vector &states = PackageOps[pkg]; + const char *next_action = NULL; + if(PackageOpsDone[pkg] < states.size()) + next_action = states[PackageOpsDone[pkg]].state; + // check if the package moved to the next dpkg state + if(next_action && (strcmp(action, next_action) == 0)) + { + // only read the translation if there is actually a next + // action + const char *translation = states[PackageOpsDone[pkg]].str; + char s[200]; + snprintf(s, sizeof(s), translation, pkg); + + // we moved from one dpkg state to a new one, report that + PackageOpsDone[pkg]++; + Done++; + // build the status str + status << "pmstatus:" << pkg + << ":" << (Done/float(Total)*100.0) + << ":" << s + << endl; + if(OutStatusFd > 0) + write(OutStatusFd, status.str().c_str(), status.str().size()); + if (_config->FindB("Debug::pkgDPkgProgressReporting",false) == true) + std::clog << "send: '" << status.str() << "'" << endl; + + } + if (_config->FindB("Debug::pkgDPkgProgressReporting",false) == true) + std::clog << "(parsed from dpkg) pkg: " << pkg + << " action: " << action << endl; - // Restore sig int/quit - signal(SIGQUIT,old_SIGQUIT); - signal(SIGINT,old_SIGINT); - return _error->Errno("waitpid","Couldn't wait for subprocess"); + // reset the line buffer + line[0]=0; } + close(_dpkgin); // Restore sig int/quit signal(SIGQUIT,old_SIGQUIT); diff --git a/apt-pkg/deb/dpkgpm.h b/apt-pkg/deb/dpkgpm.h index b59b9dc93..2ff8a9ac7 100644 --- a/apt-pkg/deb/dpkgpm.h +++ b/apt-pkg/deb/dpkgpm.h @@ -23,6 +23,13 @@ using std::vector; class pkgDPkgPM : public pkgPackageManager { protected: + + // used for progress reporting + struct DpkgState + { + const char *state; // the dpkg state (e.g. "unpack") + const char *str; // the human readable translation of the state + }; struct Item { @@ -45,7 +52,7 @@ class pkgDPkgPM : public pkgPackageManager virtual bool Install(PkgIterator Pkg,string File); virtual bool Configure(PkgIterator Pkg); virtual bool Remove(PkgIterator Pkg,bool Purge = false); - virtual bool Go(int status_fd=-1); + virtual bool Go(int StatusFd=-1); virtual void Reset(); public: -- cgit v1.2.3 From 29998d34c434ba03fbe8e2dca0fd2f54b15da480 Mon Sep 17 00:00:00 2001 From: Michael Vogt Date: Tue, 27 Sep 2005 22:52:45 +0000 Subject: * added DDTP::URL-Remap. KILL THIS FEATURE once ddtp support is offical --- apt-pkg/deb/debindexfile.cc | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) (limited to 'apt-pkg/deb') diff --git a/apt-pkg/deb/debindexfile.cc b/apt-pkg/deb/debindexfile.cc index 38ecdd16a..e2ed86890 100644 --- a/apt-pkg/deb/debindexfile.cc +++ b/apt-pkg/deb/debindexfile.cc @@ -338,15 +338,23 @@ inline string debTranslationsIndex::IndexFile(const char *Type) const string debTranslationsIndex::IndexURI(const char *Type) const { string Res; + + string theURI = URI; + // FIXME: EVIL! Remove as soon as pdiff support is offical + string remap = _config->Find("DDTP::URL-Remap::"+URI,""); + if(!remap.empty()) + theURI = remap; + + if (Dist[Dist.size() - 1] == '/') { if (Dist != "/") - Res = URI + Dist; + Res = theURI + Dist; else - Res = URI; + Res = theURI; } else - Res = URI + "dists/" + Dist + '/' + Section + + Res = theURI + "dists/" + Dist + '/' + Section + "/i18n/Translation-"; Res += Type; -- cgit v1.2.3 From 422eeaaadf17904bf2f08cdf9e8998bec645097c Mon Sep 17 00:00:00 2001 From: Michael Vogt Date: Tue, 27 Sep 2005 23:47:01 +0000 Subject: * remvoed the remap feature again, dosn't work anyway --- apt-pkg/deb/debindexfile.cc | 14 +++----------- 1 file changed, 3 insertions(+), 11 deletions(-) (limited to 'apt-pkg/deb') diff --git a/apt-pkg/deb/debindexfile.cc b/apt-pkg/deb/debindexfile.cc index e2ed86890..38ecdd16a 100644 --- a/apt-pkg/deb/debindexfile.cc +++ b/apt-pkg/deb/debindexfile.cc @@ -338,23 +338,15 @@ inline string debTranslationsIndex::IndexFile(const char *Type) const string debTranslationsIndex::IndexURI(const char *Type) const { string Res; - - string theURI = URI; - // FIXME: EVIL! Remove as soon as pdiff support is offical - string remap = _config->Find("DDTP::URL-Remap::"+URI,""); - if(!remap.empty()) - theURI = remap; - - if (Dist[Dist.size() - 1] == '/') { if (Dist != "/") - Res = theURI + Dist; + Res = URI + Dist; else - Res = theURI; + Res = URI; } else - Res = theURI + "dists/" + Dist + '/' + Section + + Res = URI + "dists/" + Dist + '/' + Section + "/i18n/Translation-"; Res += Type; -- cgit v1.2.3