Add a Acquire::CompressionTypes config variable from there the
authorDavid Kalnischkies <kalnischkies@gmail.com>
Tue, 11 Aug 2009 22:52:26 +0000 (00:52 +0200)
committerDavid Kalnischkies <kalnischkies@gmail.com>
Tue, 11 Aug 2009 22:52:26 +0000 (00:52 +0200)
acquire-items choose which compression file they should (try first to)
download to easily add new or change the order of the compression types.
And because it is easy now we directly add builtin lzma support.

The compression ratio is better than bzip2 but we prefer the later for now
as no (official) mirror uses lzma, so this would only generate useless
hits on the servers. Maybe sometime in the future lzma will be the default...

[apt-pkg/acquire-item.cc]
- use configsettings for dynamic compression type use and order.
  Based on a patch by Jyrki Muukkonen, thanks! (LP: #71746)
[apt-pkg/init.cc]
- add default configuration for compression types and add lzma
  support. Order is now bzip2, lzma, gzip, none (Closes: #510526)
[ftparchive/writer.cc]
- add lzma support also here, patch for this (and inspiration for
  the one above) by Robert Millan, thanks!

apt-pkg/acquire-item.cc
apt-pkg/acquire-item.h
apt-pkg/init.cc
debian/changelog
doc/apt.conf.5.xml
ftparchive/writer.cc
po/apt-all.pot

index 39ae327..ffbe66d 100644 (file)
@@ -551,13 +551,24 @@ pkgAcqIndex::pkgAcqIndex(pkgAcquire *Owner,
    if(comprExt.empty()) 
    {
       // autoselect the compression method
-      if(FileExists("/bin/bzip2")) 
-        CompressionExtension = ".bz2";
-      else 
-        CompressionExtension = ".gz";
-   } else {
-      CompressionExtension = (comprExt == "plain" ? "" : comprExt);
+      Configuration::Item const *Opts = _config->Tree("Acquire::CompressionTypes");
+      if (Opts != 0)
+        Opts = Opts->Child;
+
+      const char dirBin[] = "Dir::Bin::";
+      for (; Opts != 0; Opts = Opts->Next)
+      {
+        if (Opts->Tag.empty() == true || Opts->Value.empty() == true)
+           continue;
+        const string bin = _config->FindFile(string(dirBin).append(Opts->Value).c_str(),"");
+        if (bin != "" && !FileExists(bin))
+           continue;
+        comprExt = '.' + Opts->Tag;
+        break;
+      }
    }
+   CompressionExtension = ((comprExt == "plain" || comprExt == ".") ? "" : comprExt);
+
    Desc.URI = URI + CompressionExtension;
 
    Desc.Description = URIDesc;
@@ -584,24 +595,32 @@ string pkgAcqIndex::Custom600Headers()
                                                                        /*}}}*/
 void pkgAcqIndex::Failed(string Message,pkgAcquire::MethodConfig *Cnf) /*{{{*/
 {
-   bool descChanged = false;
-   // no .bz2 found, retry with .gz
-   if(Desc.URI.substr(Desc.URI.size()-3) == "bz2") {
-      Desc.URI = Desc.URI.substr(0,Desc.URI.size()-3) + "gz";
-
-      new pkgAcqIndex(Owner, RealURI, Desc.Description,Desc.ShortDesc,
-                     ExpectedHash, string(".gz"));
-         descChanged = true;
-   }
-   // no .gz found, retry with uncompressed
-   else if(Desc.URI.substr(Desc.URI.size()-2) == "gz") {
-      Desc.URI = Desc.URI.substr(0,Desc.URI.size()-2);
+   Configuration::Item const *Opts = _config->Tree("Acquire::CompressionTypes");
+   if (Opts != 0)
+      Opts = Opts->Child;
+
+   const char dirBin[] = "Dir::Bin::";
+   for (; Opts != 0; Opts = Opts->Next)
+   {
+      if (Opts->Tag.empty() == true || Opts->Value.empty() == true)
+        continue;
+
+      // jump over all already checked compression types
+      const unsigned int nameLen = Desc.URI.size() - Opts->Tag.size();
+      if(Desc.URI.substr(nameLen) != Opts->Tag || Opts->Next == 0)
+        continue;
+
+      // check if we need an external binary for this compression type
+      const string bin = _config->FindFile(string(dirBin).append(Opts->Next->Value).c_str(),"");
+      if (bin != "" && !FileExists(bin))
+        continue;
+
+      // retry with the next extension
+      Desc.URI = Desc.URI.substr(0, nameLen) + Opts->Next->Tag;
+
+      new pkgAcqIndex(Owner, RealURI, Desc.Description, Desc.ShortDesc,
+                       ExpectedHash, string(".").append(Opts->Next->Tag));
 
-      new pkgAcqIndex(Owner, RealURI, Desc.Description,Desc.ShortDesc,
-                     ExpectedHash, string("plain"));
-         descChanged = true;
-   }
-   if (descChanged) {
       Status = StatDone;
       Complete = false;
       Dequeue();
@@ -698,11 +717,11 @@ void pkgAcqIndex::Done(string Message,unsigned long Size,string Hash,
       Local = true;
    
    string compExt = flExtension(flNotDir(URI(Desc.URI).Path));
-   const char *decompProg;
-   if(compExt == "bz2") 
-      decompProg = "bzip2";
-   else if(compExt == "gz") 
-      decompProg = "gzip";
+   string decompProg;
+
+   // get the binary name for your used compression type
+   decompProg = _config->Find(string("Acquire::CompressionTypes::").append(compExt),"");
+   if(decompProg.empty() == false);
    // flExtensions returns the full name if no extension is found
    // this is why we have this complicated compare operation here
    // FIMXE: add a new flJustExtension() that return "" if no
@@ -717,9 +736,9 @@ void pkgAcqIndex::Done(string Message,unsigned long Size,string Hash,
 
    Decompression = true;
    DestFile += ".decomp";
-   Desc.URI = string(decompProg) + ":" + FileName;
+   Desc.URI = decompProg + ":" + FileName;
    QueueURI(Desc);
-   Mode = decompProg;
+   Mode = decompProg.c_str();
 }
                                                                        /*}}}*/
 // AcqIndexTrans::pkgAcqIndexTrans - Constructor                       /*{{{*/
index 36a926a..3f073de 100644 (file)
@@ -540,7 +540,9 @@ class pkgAcqIndex : public pkgAcquire::Item
     *
     *  \param compressExt The compression-related extension with which
     *  this index file should be downloaded, or "" to autodetect
-    *  (".bz2" is used if bzip2 is installed, ".gz" otherwise).
+    *  Compression types can be set with config Acquire::CompressionTypes,
+    *  default is ".lzma" or ".bz2" (if the needed binaries are present)
+    *  fallback is ".gz" or none.
     */
    pkgAcqIndex(pkgAcquire *Owner,string URI,string URIDesc,
               string ShortDesc, HashString ExpectedHash, string compressExt="");
@@ -569,12 +571,6 @@ class pkgAcqIndexTrans : public pkgAcqIndex
     *  \param URIDesc A "URI-style" description of this index file.
     *
     *  \param ShortDesc A brief description of this index file.
-    *
-    *  \param ExpectedHash The expected hashsum of this index file.
-    *
-    *  \param compressExt The compression-related extension with which
-    *  this index file should be downloaded, or "" to autodetect
-    *  (".bz2" is used if bzip2 is installed, ".gz" otherwise).
     */
    pkgAcqIndexTrans(pkgAcquire *Owner,string URI,string URIDesc,
                    string ShortDesc);
index 63caade..46017bf 100644 (file)
@@ -103,7 +103,29 @@ bool pkgInitConfig(Configuration &Cnf)
 
    if (Res == false)
       return false;
-   
+
+   // we load all config files, now check the configs and setup post-defaults:
+   // * check for CompressionTypes setup
+   {
+      Configuration::Item const *Opts = _config->Tree("Acquire::CompressionTypes");
+      if (Opts != 0)
+        Opts = Opts->Child;
+      bool foundLzma=false, foundBzip2=false, foundGzip=false;
+      for (; Opts != 0; Opts = Opts->Next)
+      {
+        if (Opts->Value == "lzma") foundLzma = true;
+        else if (Opts->Value == "bz2") foundBzip2 = true;
+        else if (Opts->Value == "gz") foundGzip = true;
+      }
+      if (!foundBzip2) Cnf.Set("Acquire::CompressionTypes::bz2","bzip2");
+      if (!foundLzma) Cnf.Set("Acquire::CompressionTypes::lzma","lzma");
+      if (!foundGzip) Cnf.Set("Acquire::CompressionTypes::gz","gzip");
+      Cnf.CndSet("Dir::Bin::lzma", "/usr/bin/lzma");
+      Cnf.CndSet("Dir::Bin::bzip2", "/bin/bzip2");
+   }
+
+
+
    if (Cnf.FindB("Debug::pkgInitConfig",false) == true)
       Cnf.Dump();
    
index fa2a3f6..16394b0 100644 (file)
@@ -16,6 +16,15 @@ apt (0.7.22.3) unstable; urgency=low
     - use sizeof instead strlen (by Marius Vollmer, Closes: #504325)
   * doc/apt-mark.8.xml:
     - improve manpage based on patch by Carl Chenet (Closes: #510286)
+  * apt-pkg/acquire-item.cc:
+    - use configsettings for dynamic compression type use and order.
+      Based on a patch by Jyrki Muukkonen, thanks! (LP: #71746)
+  * apt-pkg/init.cc:
+    - add default configuration for compression types and add lzma
+      support. Order is now bzip2, lzma, gzip, none (Closes: #510526)
+  * ftparchive/writer.cc:
+    - add lzma support also here, patch for this (and inspiration for
+      the one above) by Robert Millan, thanks!
 
   [ George Danchev ]
   * cmdline/apt-cache.cc:
index 85a7d96..d347bda 100644 (file)
@@ -303,6 +303,20 @@ DPkg::Pre-Install-Pkgs {"/usr/sbin/dpkg-preconfigure --apt";};
      </para></listitem>
      </varlistentry>
 
+     <varlistentry><term>CompressionTypes</term>
+     <listitem><para>List of compression types which are understood by the acquire methods.
+     Files like <filename>Packages</filename> can be available in various compression formats.
+     This list defines in which order the acquire methods will try to download these files.
+     Per default <command>bzip2</command> compressed files will be prefered over
+     <command>lzma</command>, <command>gzip</command> and uncompressed files. The syntax for
+     the configuration fileentry (this option can't be set at runtime with the -o option) is
+     <synopsis>Acquire::CompressionTypes::<replaceable>FileExtension</replaceable> "<replaceable>Methodname</replaceable>";</synopsis>
+     e.g. <synopsis>Acquire::CompressionTypes::bz2 "bzip2";</synopsis>
+     Note that at runtime the <literal>Dir::Bin::<replaceable>Methodname</replaceable></literal> will
+     be checked: If this setting exists the method will only be used if this file exists, e.g. for
+     the bzip2 method above (the inbuilt) setting is <literallayout>Dir::Bin::bzip2 "/bin/bzip2";</literallayout>
+     </para></listitem>
+     </varlistentry>
    </variablelist>
   </para>
  </refsect1>
@@ -337,6 +351,7 @@ DPkg::Pre-Install-Pkgs {"/usr/sbin/dpkg-preconfigure --apt";};
 
    <para>Binary programs are pointed to by <literal>Dir::Bin</literal>. <literal>Dir::Bin::Methods</literal> 
    specifies the location of the method handlers and <literal>gzip</literal>, 
+   <literal>bzip2</literal>, <literal>lzma</literal>,
    <literal>dpkg</literal>, <literal>apt-get</literal> <literal>dpkg-source</literal> 
    <literal>dpkg-buildpackage</literal> and <literal>apt-cache</literal> specify the location
    of the respective programs.</para>
index 9d248ab..293e851 100644 (file)
@@ -815,9 +815,11 @@ ReleaseWriter::ReleaseWriter(string DB)
    AddPattern("Packages");
    AddPattern("Packages.gz");
    AddPattern("Packages.bz2");
+   AddPattern("Packages.lzma");
    AddPattern("Sources");
    AddPattern("Sources.gz");
    AddPattern("Sources.bz2");
+   AddPattern("Sources.lzma");
    AddPattern("Release");
    AddPattern("md5sum.txt");
 
index 3ec999f..8f3d4cf 100644 (file)
@@ -7,7 +7,7 @@ msgid ""
 msgstr ""
 "Project-Id-Version: PACKAGE VERSION\n"
 "Report-Msgid-Bugs-To: \n"
-"POT-Creation-Date: 2009-08-09 10:20+0200\n"
+"POT-Creation-Date: 2009-08-10 23:54+0200\n"
 "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
 "Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
 "Language-Team: LANGUAGE <LL@li.org>\n"
@@ -2364,12 +2364,12 @@ msgstr ""
 msgid "Please insert the disc labeled: '%s' in the drive '%s' and press enter."
 msgstr ""
 
-#: apt-pkg/init.cc:132
+#: apt-pkg/init.cc:154
 #, c-format
 msgid "Packaging system '%s' is not supported"
 msgstr ""
 
-#: apt-pkg/init.cc:148
+#: apt-pkg/init.cc:170
 msgid "Unable to determine a suitable packaging system type"
 msgstr ""
 
@@ -2506,35 +2506,35 @@ msgstr ""
 msgid "MD5Sum mismatch"
 msgstr ""
 
-#: apt-pkg/acquire-item.cc:644 apt-pkg/acquire-item.cc:1406
+#: apt-pkg/acquire-item.cc:663 apt-pkg/acquire-item.cc:1425
 msgid "Hash Sum mismatch"
 msgstr ""
 
-#: apt-pkg/acquire-item.cc:1101
+#: apt-pkg/acquire-item.cc:1120
 msgid "There is no public key available for the following key IDs:\n"
 msgstr ""
 
-#: apt-pkg/acquire-item.cc:1211
+#: apt-pkg/acquire-item.cc:1230
 #, c-format
 msgid ""
 "I wasn't able to locate a file for the %s package. This might mean you need "
 "to manually fix this package. (due to missing arch)"
 msgstr ""
 
-#: apt-pkg/acquire-item.cc:1270
+#: apt-pkg/acquire-item.cc:1289
 #, c-format
 msgid ""
 "I wasn't able to locate file for the %s package. This might mean you need to "
 "manually fix this package."
 msgstr ""
 
-#: apt-pkg/acquire-item.cc:1311
+#: apt-pkg/acquire-item.cc:1330
 #, c-format
 msgid ""
 "The package index files are corrupted. No Filename: field for package %s."
 msgstr ""
 
-#: apt-pkg/acquire-item.cc:1398
+#: apt-pkg/acquire-item.cc:1417
 msgid "Size mismatch"
 msgstr ""