]> git.saurik.com Git - apt.git/commitdiff
* ftparchive/writer.cc:
authorDavid Kalnischkies <kalnischkies@gmail.com>
Mon, 22 Mar 2010 17:25:37 +0000 (18:25 +0100)
committerDavid Kalnischkies <kalnischkies@gmail.com>
Mon, 22 Mar 2010 17:25:37 +0000 (18:25 +0100)
  - write LongDescriptions if they shouldn't be included in Packages
    file into i18n/Translation-en by default.

It is ensured that each package+description is listed only ones in the
Translation file even if we generate multiple Packages file in one run.

The file is only generated in "generate" - the simple file commands
can't create it by now. Also, the LongDescription is currently a
global setting, so generating archives with and without LongDescriptions
in the Packages file in the same run are currently not possible.

debian/changelog
ftparchive/apt-ftparchive.cc
ftparchive/writer.cc
ftparchive/writer.h

index d08bfb20c6d0016c3664af53767633f64845c119..d8b8244bfc77d1b3e1bb93d6d50c6ee9dc7c9a67 100644 (file)
@@ -51,6 +51,9 @@ apt (0.7.26) UNRELEASED; urgency=low
     - merge versions correctly even if multiple different versions
       with the same version number are available.
       Thanks to Magnus Holmgren for the patch! (Closes: #351056)
+  * ftparchive/writer.cc:
+    - write LongDescriptions if they shouldn't be included in Packages
+      file into i18n/Translation-en by default.
 
   [ Julian Andres Klode ]
   * cmdline/apt-mark:
index f1a182e523451c43df0daaa3375f5e276d5af126..e69c88ddd5c2b8d11fd8132ef8ea2719995795e9 100644 (file)
@@ -62,6 +62,9 @@ struct PackageMap
    string SrcOverride;
    string SrcExtraOverride;
 
+   // Translation master file
+   TranslationWriter *TransWriter;
+
    // Contents 
    string Contents;
    string ContentsHead;
@@ -100,8 +103,9 @@ struct PackageMap
                    vector<PackageMap>::iterator End,
                    unsigned long &Left);
    
-   PackageMap() : DeLinkLimit(0), Permissions(1), ContentsDone(false), 
-        PkgDone(false), SrcDone(false), ContentsMTime(0) {};
+   PackageMap() : TransWriter(NULL), DeLinkLimit(0), Permissions(1),
+                 ContentsDone(false), PkgDone(false), SrcDone(false),
+                 ContentsMTime(0) {};
 };
                                                                        /*}}}*/
 
@@ -169,6 +173,8 @@ bool PackageMap::GenPackages(Configuration &Setup,struct CacheDB::Stats &Stats)
    Packages.DirStrip = ArchiveDir;
    Packages.InternalPrefix = flCombine(ArchiveDir,InternalPrefix);
 
+   Packages.TransWriter = TransWriter;
+
    Packages.Stats.DeLinkBytes = Stats.DeLinkBytes;
    Packages.DeLinkLimit = DeLinkLimit;
 
@@ -436,6 +442,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",
@@ -461,15 +469,25 @@ 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},
+                                        {}};
+        TranslationWriter *TransWriter;
+        if (DTrans.empty() == false)
+        {
+           string const TranslationFile = flCombine(Setup.FindDir("Dir::ArchiveDir"),
+                       SubstVar(Block.Find("Translation", DTrans.c_str()), Vars));
+           TransWriter = new TranslationWriter(TranslationFile);
+        }
+        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.BinOverride = SubstVar(Block.Find("BinOverride"),Vars);
@@ -491,6 +509,11 @@ 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;
+              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);
@@ -500,6 +523,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;
@@ -788,7 +814,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;
    
index 9e5b7d4f3358c55b6ea009812049b6eeb99c5159..b395903b793acce5ae7e19a4076b81039e4da186 100644 (file)
@@ -300,7 +300,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 +317,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 +448,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 +496,51 @@ bool PackagesWriter::DoPackage(string FileName)
 }
                                                                        /*}}}*/
 
+// TranslationWriter::TranslationWriter - Constructor                  /*{{{*/
+// ---------------------------------------------------------------------
+/* Create a Translation-Master file for this Packages file */
+TranslationWriter::TranslationWriter(string const &File) : Output(NULL),
+                                                       RefCounter(0)
+{
+   if (File.empty() == true)
+      return;
+
+   Output = fopen(File.c_str(), "w");
+}
+                                                                       /*}}}*/
+// 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 (Output != NULL)
+      fclose(Output);
+}
+                                                                       /*}}}*/
+
 // SourcesWriter::SourcesWriter - Constructor                          /*{{{*/
 // ---------------------------------------------------------------------
 /* */
index af7ba4edd5ceda709ee96ebc7143839970e2cd12..2afd1af1f5a3e9176006a24f6f4cd660918660c8 100644 (file)
@@ -19,6 +19,7 @@
 #include <iostream>
 #include <vector>
 #include <map>
+#include <set>
 
 #include "cachedb.h"
 #include "override.h"
@@ -72,6 +73,23 @@ class FTWScanner
    FTWScanner(string const &Arch = string());
 };
 
+class TranslationWriter
+{
+   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);
+   TranslationWriter() : Output(NULL), RefCounter(0) {};
+   ~TranslationWriter();
+};
+
 class PackagesWriter : public FTWScanner
 {
    Override Over;
@@ -93,6 +111,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)