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/cacheiterators.h | 81 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 81 insertions(+) (limited to 'apt-pkg/cacheiterators.h') diff --git a/apt-pkg/cacheiterators.h b/apt-pkg/cacheiterators.h index 62d2695dd..797e854b6 100644 --- a/apt-pkg/cacheiterators.h +++ b/apt-pkg/cacheiterators.h @@ -128,6 +128,7 @@ class pkgCache::VerIterator inline const char *Section() const {return Ver->Section == 0?0:Owner->StrP + Ver->Section;}; inline const char *Arch() const {return Ver->Arch == 0?0:Owner->StrP + Ver->Arch;}; inline PkgIterator ParentPkg() const {return PkgIterator(*Owner,Owner->PkgP + Ver->ParentPkg);}; + inline DescIterator DescriptionList() const; inline DepIterator DependsList() const; inline PrvIterator ProvidesList() const; inline VerFileIterator FileList() const; @@ -148,6 +149,50 @@ class pkgCache::VerIterator }; }; +// Description Iterator +class pkgCache::DescIterator +{ + Description *Desc; + pkgCache *Owner; + + void _dummy(); + + public: + + // Iteration + void operator ++(int) {if (Desc != Owner->DescP) Desc = Owner->DescP + Desc->NextDesc;}; + inline void operator ++() {operator ++(0);}; + inline bool end() const {return Desc == Owner->DescP?true:false;}; + inline void operator =(const DescIterator &B) {Desc = B.Desc; Owner = B.Owner;}; + + // Comparison + inline bool operator ==(const DescIterator &B) const {return Desc == B.Desc;}; + inline bool operator !=(const DescIterator &B) const {return Desc != B.Desc;}; + int CompareDesc(const DescIterator &B) const; + + // Accessors + inline Description *operator ->() {return Desc;}; + inline Description const *operator ->() const {return Desc;}; + inline Description &operator *() {return *Desc;}; + inline Description const &operator *() const {return *Desc;}; + inline operator Description *() {return Desc == Owner->DescP?0:Desc;}; + inline operator Description const *() const {return Desc == Owner->DescP?0:Desc;}; + inline pkgCache *Cache() {return Owner;}; + + inline const char *LanguageCode() const {return Owner->StrP + Desc->language_code;}; + inline const char *md5() const {return Owner->StrP + Desc->md5sum;}; + inline DescFileIterator FileList() const; + inline unsigned long Index() const {return Desc - Owner->DescP;}; + + inline DescIterator() : Desc(0), Owner(0) {}; + inline DescIterator(pkgCache &Owner,Description *Trg = 0) : Desc(Trg), + Owner(&Owner) + { + if (Desc == 0) + Desc = Owner.DescP; + }; +}; + // Dependency iterator class pkgCache::DepIterator { @@ -336,6 +381,38 @@ class pkgCache::VerFileIterator inline VerFileIterator(pkgCache &Owner,VerFile *Trg) : Owner(&Owner), FileP(Trg) {}; }; +// Description File +class pkgCache::DescFileIterator +{ + pkgCache *Owner; + DescFile *FileP; + + public: + + // Iteration + void operator ++(int) {if (FileP != Owner->DescFileP) FileP = Owner->DescFileP + FileP->NextFile;}; + inline void operator ++() {operator ++(0);}; + inline bool end() const {return FileP == Owner->DescFileP?true:false;}; + + // Comparison + inline bool operator ==(const DescFileIterator &B) const {return FileP == B.FileP;}; + inline bool operator !=(const DescFileIterator &B) const {return FileP != B.FileP;}; + + // Accessors + inline DescFile *operator ->() {return FileP;}; + inline DescFile const *operator ->() const {return FileP;}; + inline DescFile const &operator *() const {return *FileP;}; + inline operator DescFile *() {return FileP == Owner->DescFileP?0:FileP;}; + inline operator DescFile const *() const {return FileP == Owner->DescFileP?0:FileP;}; + inline pkgCache *Cache() {return Owner;}; + + inline PkgFileIterator File() const {return PkgFileIterator(*Owner,FileP->File + Owner->PkgFileP);}; + inline unsigned long Index() const {return FileP - Owner->DescFileP;}; + + inline DescFileIterator() : Owner(0), FileP(0) {}; + inline DescFileIterator(pkgCache &Owner,DescFile *Trg) : Owner(&Owner), FileP(Trg) {}; +}; + // Inlined Begin functions cant be in the class because of order problems inline pkgCache::VerIterator pkgCache::PkgIterator::VersionList() const {return VerIterator(*Owner,Owner->VerP + Pkg->VersionList);}; @@ -345,11 +422,15 @@ inline pkgCache::DepIterator pkgCache::PkgIterator::RevDependsList() const {return DepIterator(*Owner,Owner->DepP + Pkg->RevDepends,Pkg);}; inline pkgCache::PrvIterator pkgCache::PkgIterator::ProvidesList() const {return PrvIterator(*Owner,Owner->ProvideP + Pkg->ProvidesList,Pkg);}; +inline pkgCache::DescIterator pkgCache::VerIterator::DescriptionList() const + {return DescIterator(*Owner,Owner->DescP + Ver->DescriptionList);}; inline pkgCache::PrvIterator pkgCache::VerIterator::ProvidesList() const {return PrvIterator(*Owner,Owner->ProvideP + Ver->ProvidesList,Ver);}; inline pkgCache::DepIterator pkgCache::VerIterator::DependsList() const {return DepIterator(*Owner,Owner->DepP + Ver->DependsList,Ver);}; inline pkgCache::VerFileIterator pkgCache::VerIterator::FileList() const {return VerFileIterator(*Owner,Owner->VerFileP + Ver->FileList);}; +inline pkgCache::DescFileIterator pkgCache::DescIterator::FileList() const + {return DescFileIterator(*Owner,Owner->DescFileP + Desc->FileList);}; #endif -- cgit v1.2.3-70-g09d2 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/acquire-item.h | 4 ++-- apt-pkg/cacheiterators.h | 2 +- apt-pkg/deb/debindexfile.cc | 6 +++--- apt-pkg/deb/deblistparser.cc | 10 ++++++---- apt-pkg/deb/debmetaindex.cc | 4 +++- apt-pkg/indexfile.cc | 16 +++++++++++----- apt-pkg/indexfile.h | 2 +- apt-pkg/init.cc | 6 +++--- apt-pkg/pkgcache.cc | 2 +- apt-pkg/pkgcachegen.cc | 29 +++++++++++++++++++---------- 10 files changed, 50 insertions(+), 31 deletions(-) (limited to 'apt-pkg/cacheiterators.h') diff --git a/apt-pkg/acquire-item.h b/apt-pkg/acquire-item.h index 0000f366c..2f7c71a81 100644 --- a/apt-pkg/acquire-item.h +++ b/apt-pkg/acquire-item.h @@ -9,7 +9,7 @@ the Owner Acquire class. Derived classes will then call QueueURI to register all the URI's they wish to fetch at the initial moment. - Tree item classes are provided to provide functionality for + Three item classes are provided to provide functionality for downloading of Index, Translation and Packages files. A Archive class is provided for downloading .deb files. It does Md5 @@ -106,7 +106,7 @@ class pkgAcqIndex : public pkgAcquire::Item string ShortDesct, string ExpectedMD5, string compressExt=""); }; -// Item class for index files +// Item class for translated package index files class pkgAcqIndexTrans : public pkgAcqIndex { public: diff --git a/apt-pkg/cacheiterators.h b/apt-pkg/cacheiterators.h index 797e854b6..e34920032 100644 --- a/apt-pkg/cacheiterators.h +++ b/apt-pkg/cacheiterators.h @@ -99,7 +99,7 @@ class pkgCache::VerIterator { Version *Ver; pkgCache *Owner; - + void _dummy(); public: 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; diff --git a/apt-pkg/indexfile.cc b/apt-pkg/indexfile.cc index 0f1f48af4..496e68b8b 100644 --- a/apt-pkg/indexfile.cc +++ b/apt-pkg/indexfile.cc @@ -70,10 +70,10 @@ string pkgIndexFile::SourceInfo(pkgSrcRecords::Parser const &Record, return string(); } /*}}}*/ -// IndexFile::UseTranslation - Check if will use Translation /*{{{*/ +// IndexFile::TranslationsAvailable - Check if will use Translation /*{{{*/ // --------------------------------------------------------------------- /* */ -bool pkgIndexFile::UseTranslation() +bool pkgIndexFile::TranslationsAvailable() { const string Translation = _config->Find("APT::Acquire::Translation"); @@ -89,7 +89,6 @@ bool pkgIndexFile::UseTranslation() /* common cases: de_DE, de_DE@euro, de_DE.UTF-8, de_DE.UTF-8@euro, de_DE.ISO8859-1, tig_ER more in /etc/gdm/locale.conf - approach: just get the first letter before the underscore?!? */ bool pkgIndexFile::CheckLanguageCode(const char *Lang) @@ -105,13 +104,20 @@ bool pkgIndexFile::CheckLanguageCode(const char *Lang) /*}}}*/ // IndexFile::LanguageCode - Return the Language Code /*{{{*/ // --------------------------------------------------------------------- -/* */ +/* return the language code */ string pkgIndexFile::LanguageCode() { const string Translation = _config->Find("APT::Acquire::Translation"); - if (Translation.compare("environment") == 0) { + if (Translation.compare("environment") == 0) + { string lang = std::setlocale(LC_MESSAGES,NULL); + + // FIXME: this needs to be added + // we have a mapping of the language codes that contains all the language + // codes that need the country code as well + // (like pt_BR, pt_PT, sv_SE, zh_*, en_*) + if(lang.size() > 2) return lang.substr(0,2); else diff --git a/apt-pkg/indexfile.h b/apt-pkg/indexfile.h index 405f67a94..d5d1cf57a 100644 --- a/apt-pkg/indexfile.h +++ b/apt-pkg/indexfile.h @@ -81,7 +81,7 @@ class pkgIndexFile virtual bool MergeFileProvides(pkgCacheGenerator &/*Gen*/,OpProgress &/*Prog*/) const {return true;}; virtual pkgCache::PkgFileIterator FindInCache(pkgCache &Cache) const; - static bool UseTranslation(); + static bool TranslationsAvailable(); static bool CheckLanguageCode(const char *Lang); static string LanguageCode(); diff --git a/apt-pkg/init.cc b/apt-pkg/init.cc index 3e4c17289..6118845e8 100644 --- a/apt-pkg/init.cc +++ b/apt-pkg/init.cc @@ -33,9 +33,6 @@ const char *pkgOS = COMMON_OS; is prepended, this allows a fair degree of flexability. */ bool pkgInitConfig(Configuration &Cnf) { - // Translation - Cnf.Set("APT::Acquire::Translation", "environment"); - // General APT things if (strcmp(COMMON_OS,"linux") == 0 || strcmp(COMMON_OS,"unknown") == 0) @@ -104,6 +101,9 @@ bool pkgInitConfig(Configuration &Cnf) bindtextdomain(textdomain(0),Cnf.FindDir("Dir::Locale").c_str()); } #endif + + // Translation + Cnf.Set("APT::Acquire::Translation", "environment"); return true; } diff --git a/apt-pkg/pkgcache.cc b/apt-pkg/pkgcache.cc index 2189d5111..f76afb935 100644 --- a/apt-pkg/pkgcache.cc +++ b/apt-pkg/pkgcache.cc @@ -244,11 +244,11 @@ const char *pkgCache::Priority(unsigned char Prio) return 0; } /*}}}*/ - // Bases for iterator classes /*{{{*/ void pkgCache::VerIterator::_dummy() {} void pkgCache::DepIterator::_dummy() {} void pkgCache::PrvIterator::_dummy() {} +void pkgCache::DescIterator::_dummy() {} /*}}}*/ // PkgIterator::operator ++ - Postfix incr /*{{{*/ // --------------------------------------------------------------------- diff --git a/apt-pkg/pkgcachegen.cc b/apt-pkg/pkgcachegen.cc index a23e965fa..1ba791b45 100644 --- a/apt-pkg/pkgcachegen.cc +++ b/apt-pkg/pkgcachegen.cc @@ -125,31 +125,39 @@ bool pkgCacheGenerator::MergeList(ListParser &List, string Version = List.Version(); if (Version.empty() == true) { + // we first process the package, then the descriptions + // (this has the bonus that we get MMap error when we run out + // of MMap space) + if (List.UsePackage(Pkg,pkgCache::VerIterator(Cache)) == false) + return _error->Error(_("Error occurred while processing %s (UsePackage1)"), + PackageName.c_str()); + // Find the right version to write the description MD5SumValue CurMd5 = List.Description_md5(); pkgCache::VerIterator Ver = Pkg.VersionList(); map_ptrloc *LastVer = &Pkg->VersionList; - + for (; Ver.end() == false; LastVer = &Ver->NextVer, Ver++) { pkgCache::DescIterator Desc = Ver.DescriptionList(); map_ptrloc *LastDesc = &Ver->DescriptionList; - + for (; Desc.end() == false; LastDesc = &Desc->NextDesc, Desc++) - if (MD5SumValue(Desc.md5()) == CurMd5) { + { + + if (MD5SumValue(Desc.md5()) == CurMd5) + { // Add new description *LastDesc = NewDescription(Desc, List.DescriptionLanguage(), CurMd5, *LastDesc); Desc->ParentPkg = Pkg.Index(); - + if (NewFileDesc(Desc,List) == false) return _error->Error(_("Error occured while processing %s (NewFileDesc1)"),PackageName.c_str()); break; } + } } - - if (List.UsePackage(Pkg,pkgCache::VerIterator(Cache)) == false) - return _error->Error(_("Error occurred while processing %s (UsePackage1)"), - PackageName.c_str()); + continue; } @@ -403,14 +411,15 @@ bool pkgCacheGenerator::NewFileDesc(pkgCache::DescIterator &Desc, unsigned long DescFile = Map.Allocate(sizeof(pkgCache::DescFile)); if (DescFile == 0) return 0; - + pkgCache::DescFileIterator DF(Cache,Cache.DescFileP + DescFile); DF->File = CurrentFile - Cache.PkgFileP; - + // Link it to the end of the list map_ptrloc *Last = &Desc->FileList; for (pkgCache::DescFileIterator D = Desc.FileList(); D.end() == false; D++) Last = &D->NextFile; + DF->NextFile = *Last; *Last = DF.Index(); -- cgit v1.2.3-70-g09d2