diff options
Diffstat (limited to 'ftparchive')
-rw-r--r-- | ftparchive/apt-ftparchive.cc | 63 | ||||
-rw-r--r-- | ftparchive/writer.cc | 95 | ||||
-rw-r--r-- | ftparchive/writer.h | 21 |
3 files changed, 145 insertions, 34 deletions
diff --git a/ftparchive/apt-ftparchive.cc b/ftparchive/apt-ftparchive.cc index 4c26f79b8..6f9fa7ab3 100644 --- a/ftparchive/apt-ftparchive.cc +++ b/ftparchive/apt-ftparchive.cc @@ -63,6 +63,10 @@ struct PackageMap string SrcOverride; string SrcExtraOverride; + // Translation master file + bool LongDesc; + TranslationWriter *TransWriter; + // Contents string Contents; string ContentsHead; @@ -101,8 +105,9 @@ struct PackageMap vector<PackageMap>::iterator End, unsigned long &Left); - PackageMap() : DeLinkLimit(0), Permissions(1), ContentsDone(false), - PkgDone(false), SrcDone(false), ContentsMTime(0) {}; + PackageMap() : LongDesc(true), TransWriter(NULL), DeLinkLimit(0), Permissions(1), + ContentsDone(false), PkgDone(false), SrcDone(false), + ContentsMTime(0) {}; }; /*}}}*/ @@ -130,8 +135,6 @@ void PackageMap::GetGeneral(Configuration &Setup,Configuration &Block) PkgExt = Block.Find("Packages::Extensions", Setup.Find("Default::Packages::Extensions",".deb").c_str()); - Permissions = Setup.FindI("Default::FileMode",0644); - if (FLFile.empty() == false) FLFile = flCombine(Setup.Find("Dir::FileListDir"),FLFile); @@ -170,6 +173,9 @@ bool PackageMap::GenPackages(Configuration &Setup,struct CacheDB::Stats &Stats) Packages.DirStrip = ArchiveDir; Packages.InternalPrefix = flCombine(ArchiveDir,InternalPrefix); + Packages.TransWriter = TransWriter; + Packages.LongDescription = LongDesc; + Packages.Stats.DeLinkBytes = Stats.DeLinkBytes; Packages.DeLinkLimit = DeLinkLimit; @@ -437,6 +443,8 @@ void LoadTree(vector<PackageMap> &PkgList,Configuration &Setup) "$(DIST)/$(SECTION)/source/"); string DPkg = Setup.Find("TreeDefault::Packages", "$(DIST)/$(SECTION)/binary-$(ARCH)/Packages"); + string DTrans = Setup.Find("TreeDefault::Translation", + "$(DIST)/$(SECTION)/i18n/Translation-en"); string DIPrfx = Setup.Find("TreeDefault::InternalPrefix", "$(DIST)/$(SECTION)/"); string DContents = Setup.Find("TreeDefault::Contents", @@ -449,6 +457,12 @@ void LoadTree(vector<PackageMap> &PkgList,Configuration &Setup) string DFLFile = Setup.Find("TreeDefault::FileList", ""); string DSFLFile = Setup.Find("TreeDefault::SourceFileList", ""); + int const Permissions = Setup.FindI("Default::FileMode",0644); + + bool const LongDescription = Setup.FindB("Default::LongDescription", + _config->FindB("APT::FTPArchive::LongDescription", true)); + string const TranslationCompress = Setup.Find("Default::Translation::Compress",". gzip").c_str(); + // Process 'tree' type sections const Configuration::Item *Top = Setup.Tree("tree"); for (Top = (Top == 0?0:Top->Child); Top != 0;) @@ -462,17 +476,30 @@ void LoadTree(vector<PackageMap> &PkgList,Configuration &Setup) string Section; while (ParseQuoteWord(Sections,Section) == true) { - string Tmp2 = Block.Find("Architectures"); string Arch; + struct SubstVar const Vars[] = {{"$(DIST)",&Dist}, + {"$(SECTION)",&Section}, + {"$(ARCH)",&Arch}, + {}}; + mode_t const Perms = Block.FindI("FileMode", Permissions); + bool const LongDesc = Block.FindB("LongDescription", LongDescription); + TranslationWriter *TransWriter; + if (DTrans.empty() == false && LongDesc == false) + { + string const TranslationFile = flCombine(Setup.FindDir("Dir::ArchiveDir"), + SubstVar(Block.Find("Translation", DTrans.c_str()), Vars)); + string const TransCompress = Block.Find("Translation::Compress", TranslationCompress); + TransWriter = new TranslationWriter(TranslationFile, TransCompress, Perms); + } + else + TransWriter = NULL; + + string const Tmp2 = Block.Find("Architectures"); const char *Archs = Tmp2.c_str(); while (ParseQuoteWord(Archs,Arch) == true) { - struct SubstVar Vars[] = {{"$(DIST)",&Dist}, - {"$(SECTION)",&Section}, - {"$(ARCH)",&Arch}, - {}}; PackageMap Itm; - + Itm.Permissions = Perms; Itm.BinOverride = SubstVar(Block.Find("BinOverride"),Vars); Itm.InternalPrefix = SubstVar(Block.Find("InternalPrefix",DIPrfx.c_str()),Vars); @@ -492,6 +519,12 @@ void LoadTree(vector<PackageMap> &PkgList,Configuration &Setup) Itm.PkgFile = SubstVar(Block.Find("Packages",DPkg.c_str()),Vars); Itm.Tag = SubstVar("$(DIST)/$(SECTION)/$(ARCH)",Vars); Itm.Arch = Arch; + Itm.LongDesc = LongDesc; + if (TransWriter != NULL) + { + TransWriter->IncreaseRefCounter(); + Itm.TransWriter = TransWriter; + } Itm.Contents = SubstVar(Block.Find("Contents",DContents.c_str()),Vars); Itm.ContentsHead = SubstVar(Block.Find("Contents::Header",DContentsH.c_str()),Vars); Itm.FLFile = SubstVar(Block.Find("FileList",DFLFile.c_str()),Vars); @@ -501,6 +534,9 @@ void LoadTree(vector<PackageMap> &PkgList,Configuration &Setup) Itm.GetGeneral(Setup,Block); PkgList.push_back(Itm); } + // we didn't use this TransWriter, so we can release it + if (TransWriter != NULL && TransWriter->GetRefCounter() == 0) + delete TransWriter; } Top = Top->Next; @@ -789,7 +825,12 @@ bool Generate(CommandLine &CmdL) delete [] List; } - + + // close the Translation master files + for (vector<PackageMap>::iterator I = PkgList.begin(); I != PkgList.end(); I++) + if (I->TransWriter != NULL && I->TransWriter->DecreaseRefCounter() == 0) + delete I->TransWriter; + if (_config->FindB("APT::FTPArchive::Contents",true) == false) return true; diff --git a/ftparchive/writer.cc b/ftparchive/writer.cc index 9e5b7d4f3..6cda29b21 100644 --- a/ftparchive/writer.cc +++ b/ftparchive/writer.cc @@ -28,6 +28,7 @@ #include <ftw.h> #include <fnmatch.h> #include <iostream> +#include <sstream> #include <memory> #include "cachedb.h" @@ -300,7 +301,7 @@ bool FTWScanner::Delink(string &FileName,const char *OriginalPath, /* */ PackagesWriter::PackagesWriter(string const &DB,string const &Overrides,string const &ExtOverrides, string const &Arch) : - FTWScanner(Arch), Db(DB), Stats(Db.Stats) + FTWScanner(Arch), Db(DB), Stats(Db.Stats), TransWriter(NULL) { Output = stdout; SetExts(".deb .udeb"); @@ -317,7 +318,7 @@ PackagesWriter::PackagesWriter(string const &DB,string const &Overrides,string c if (Db.Loaded() == false) DoContents = false; - + // Read the override file if (Overrides.empty() == false && Over.ReadOverride(Overrides) == false) return; @@ -448,6 +449,8 @@ bool PackagesWriter::DoPackage(string FileName) descmd5.Add(desc.c_str()); DescriptionMd5 = descmd5.Result().Value(); SetTFRewriteData(Changes[End++], "Description-md5", DescriptionMd5.c_str()); + if (TransWriter != NULL) + TransWriter->DoPackage(Package, desc, DescriptionMd5); } // Rewrite the maintainer field if necessary @@ -494,6 +497,55 @@ bool PackagesWriter::DoPackage(string FileName) } /*}}}*/ +// TranslationWriter::TranslationWriter - Constructor /*{{{*/ +// --------------------------------------------------------------------- +/* Create a Translation-Master file for this Packages file */ +TranslationWriter::TranslationWriter(string const &File, string const &TransCompress, + mode_t const &Permissions) : Output(NULL), + RefCounter(0) +{ + if (File.empty() == true) + return; + + Comp = new MultiCompress(File, TransCompress, Permissions); + Output = Comp->Input; +} + /*}}}*/ +// TranslationWriter::DoPackage - Process a single package /*{{{*/ +// --------------------------------------------------------------------- +/* Create a Translation-Master file for this Packages file */ +bool TranslationWriter::DoPackage(string const &Pkg, string const &Desc, + string const &MD5) +{ + if (Output == NULL) + return true; + + // Different archs can include different versions and therefore + // different descriptions - so we need to check for both name and md5. + string const Record = Pkg + ":" + MD5; + + if (Included.find(Record) != Included.end()) + return true; + + fprintf(Output, "Package: %s\nDescription-md5: %s\nDescription-en: %s\n", + Pkg.c_str(), MD5.c_str(), Desc.c_str()); + + Included.insert(Record); + return true; +} + /*}}}*/ +// TranslationWriter::~TranslationWriter - Destructor /*{{{*/ +// --------------------------------------------------------------------- +/* */ +TranslationWriter::~TranslationWriter() +{ + if (Comp == NULL) + return; + + delete Comp; +} + /*}}}*/ + // SourcesWriter::SourcesWriter - Constructor /*{{{*/ // --------------------------------------------------------------------- /* */ @@ -655,23 +707,20 @@ bool SourcesWriter::DoPackage(string FileName) // Add the dsc to the files hash list string const strippedName = flNotDir(FileName); - char Files[1000]; - snprintf(Files,sizeof(Files),"\n %s %lu %s\n %s", - string(MD5.Result()).c_str(),St.st_size, - strippedName.c_str(), - Tags.FindS("Files").c_str()); - - char ChecksumsSha1[1000]; - snprintf(ChecksumsSha1,sizeof(ChecksumsSha1),"\n %s %lu %s\n %s", - string(SHA1.Result()).c_str(),St.st_size, - strippedName.c_str(), - Tags.FindS("Checksums-Sha1").c_str()); - - char ChecksumsSha256[1000]; - snprintf(ChecksumsSha256,sizeof(ChecksumsSha256),"\n %s %lu %s\n %s", - string(SHA256.Result()).c_str(),St.st_size, - strippedName.c_str(), - Tags.FindS("Checksums-Sha256").c_str()); + std::ostringstream ostreamFiles; + ostreamFiles << "\n " << string(MD5.Result()) << " " << St.st_size << " " + << strippedName << "\n " << Tags.FindS("Files"); + string const Files = ostreamFiles.str(); + + std::ostringstream ostreamSha1; + ostreamSha1 << "\n " << string(SHA1.Result()) << " " << St.st_size << " " + << strippedName << "\n " << Tags.FindS("Checksums-Sha1"); + string const ChecksumsSha1 = ostreamSha1.str(); + + std::ostringstream ostreamSha256; + ostreamSha256 << "\n " << string(SHA256.Result()) << " " << St.st_size << " " + << strippedName << "\n " << Tags.FindS("Checksums-Sha256"); + string const ChecksumsSha256 = ostreamSha256.str(); // Strip the DirStrip prefix from the FileName and add the PathPrefix string NewFileName; @@ -689,7 +738,7 @@ bool SourcesWriter::DoPackage(string FileName) // Perform the delinking operation over all of the files string ParseJnk; - const char *C = Files; + const char *C = Files.c_str(); char *RealPath = NULL; for (;isspace(*C); C++); while (*C != 0) @@ -722,9 +771,9 @@ bool SourcesWriter::DoPackage(string FileName) unsigned int End = 0; SetTFRewriteData(Changes[End++],"Source",Package.c_str(),"Package"); - SetTFRewriteData(Changes[End++],"Files",Files); - SetTFRewriteData(Changes[End++],"Checksums-Sha1",ChecksumsSha1); - SetTFRewriteData(Changes[End++],"Checksums-Sha256",ChecksumsSha256); + SetTFRewriteData(Changes[End++],"Files",Files.c_str()); + SetTFRewriteData(Changes[End++],"Checksums-Sha1",ChecksumsSha1.c_str()); + SetTFRewriteData(Changes[End++],"Checksums-Sha256",ChecksumsSha256.c_str()); if (Directory != "./") SetTFRewriteData(Changes[End++],"Directory",Directory.c_str()); SetTFRewriteData(Changes[End++],"Priority",BestPrio.c_str()); diff --git a/ftparchive/writer.h b/ftparchive/writer.h index af7ba4edd..3123a7f46 100644 --- a/ftparchive/writer.h +++ b/ftparchive/writer.h @@ -19,8 +19,10 @@ #include <iostream> #include <vector> #include <map> +#include <set> #include "cachedb.h" +#include "multicompress.h" #include "override.h" #include "apt-ftparchive.h" @@ -72,6 +74,24 @@ class FTWScanner FTWScanner(string const &Arch = string()); }; +class TranslationWriter +{ + MultiCompress *Comp; + FILE *Output; + std::set<string> Included; + unsigned short RefCounter; + + public: + void IncreaseRefCounter() { ++RefCounter; }; + unsigned short DecreaseRefCounter() { return (RefCounter == 0) ? 0 : --RefCounter; }; + unsigned short GetRefCounter() const { return RefCounter; }; + bool DoPackage(string const &Pkg, string const &Desc, string const &MD5); + + TranslationWriter(string const &File, string const &TransCompress, mode_t const &Permissions); + TranslationWriter() : Comp(NULL), Output(NULL), RefCounter(0) {}; + ~TranslationWriter(); +}; + class PackagesWriter : public FTWScanner { Override Over; @@ -93,6 +113,7 @@ class PackagesWriter : public FTWScanner string DirStrip; FILE *Output; struct CacheDB::Stats &Stats; + TranslationWriter *TransWriter; inline bool ReadOverride(string const &File) {return Over.ReadOverride(File);}; inline bool ReadExtraOverride(string const &File) |