Italian translation update (Milo Casagrande). Closes: #614395
authorDavid Kalnischkies <kalnischkies@gmail.com>
Mon, 7 Mar 2011 21:43:37 +0000 (22:43 +0100)
committerDavid Kalnischkies <kalnischkies@gmail.com>
Mon, 7 Mar 2011 21:43:37 +0000 (22:43 +0100)
17 files changed:
apt-inst/deb/debfile.cc
apt-pkg/aptconfiguration.cc
apt-pkg/aptconfiguration.h
apt-pkg/contrib/configuration.h
apt-pkg/deb/debsrcrecords.cc
cmdline/apt-get.cc
debian/changelog
doc/apt-ftparchive.1.xml
ftparchive/apt-ftparchive.cc
ftparchive/contents.cc
ftparchive/multicompress.cc
ftparchive/multicompress.h
ftparchive/writer.cc
ftparchive/writer.h
methods/makefile
test/integration/framework
test/integration/test-bug-595691-empty-and-broken-archive-files

index cd7a888..a40cd1a 100644 (file)
@@ -20,6 +20,7 @@
 #include <apt-pkg/extracttar.h>
 #include <apt-pkg/error.h>
 #include <apt-pkg/deblistparser.h>
+#include <apt-pkg/aptconfiguration.h>
 
 #include <sys/stat.h>
 #include <unistd.h>
@@ -46,7 +47,9 @@ debDebFile::debDebFile(FileFd &File) : File(File), AR(File)
 
    if (!CheckMember("data.tar.gz") &&
        !CheckMember("data.tar.bz2") &&
-       !CheckMember("data.tar.lzma")) {
+       !CheckMember("data.tar.lzma") &&
+       !CheckMember("data.tar.xz")) {
+      // FIXME: add data.tar.xz here - adding it now would require a Translation round for a very small gain
       _error->Error(_("This is not a valid DEB archive, it has no '%s', '%s' or '%s' member"), "data.tar.gz", "data.tar.bz2", "data.tar.lzma");
       return;
    }
@@ -125,22 +128,35 @@ bool debDebFile::ExtractControl(pkgDataBase &DB)
 /* Simple wrapper around tar.. */
 bool debDebFile::ExtractArchive(pkgDirStream &Stream)
 {
-   // Get the archive member and positition the file 
-   const ARArchive::Member *Member = AR.FindMember("data.tar.gz");
-   const char *Compressor = "gzip";
-   if (Member == 0) {
-      Member = AR.FindMember("data.tar.bz2");
-      Compressor = "bzip2";
+   // Get the archive member
+   const ARArchive::Member *Member = NULL;
+   std::string Compressor;
+
+   std::string const data = "data.tar";
+   std::vector<APT::Configuration::Compressor> compressor = APT::Configuration::getCompressors();
+   for (std::vector<APT::Configuration::Compressor>::const_iterator c = compressor.begin();
+       c != compressor.end(); ++c)
+   {
+      Member = AR.FindMember(std::string(data).append(c->Extension).c_str());
+      if (Member == NULL)
+        continue;
+      Compressor = c->Binary;
+      break;
    }
-   if (Member == 0) {
-      Member = AR.FindMember("data.tar.lzma");
-      Compressor = "lzma";
+
+   if (Member == NULL)
+   {
+      std::string ext = "data.tar.{";
+      for (std::vector<APT::Configuration::Compressor>::const_iterator c = compressor.begin();
+          c != compressor.end(); ++c)
+        ext.append(c->Extension.substr(1));
+      ext.append("}");
+      return _error->Error(_("Internal error, could not locate member %s"), ext.c_str());
    }
-   if (Member == 0)
-      return _error->Error(_("Internal error, could not locate member"));   
+
    if (File.Seek(Member->Start) == false)
       return false;
-      
+
    // Prepare Tar
    ExtractTar Tar(File,Member->Size,Compressor);
    if (_error->PendingError() == true)
index 3cf4d24..b23e12a 100644 (file)
@@ -38,12 +38,11 @@ const Configuration::getCompressionTypes(bool const &Cached) {
 
        // setup the defaults for the compressiontypes => method mapping
        _config->CndSet("Acquire::CompressionTypes::bz2","bzip2");
+       _config->CndSet("Acquire::CompressionTypes::xz","xz");
        _config->CndSet("Acquire::CompressionTypes::lzma","lzma");
        _config->CndSet("Acquire::CompressionTypes::gz","gzip");
 
-       // Set default application paths to check for optional compression types
-       _config->CndSet("Dir::Bin::lzma", "/usr/bin/lzma");
-       _config->CndSet("Dir::Bin::bzip2", "/bin/bzip2");
+       setDefaultConfigurationForCompressors();
 
        // accept non-list order as override setting for config settings on commandline
        std::string const overrideOrder = _config->Find("Acquire::CompressionTypes::Order","");
@@ -344,4 +343,86 @@ bool const Configuration::checkArchitecture(std::string const &Arch) {
        return (std::find(archs.begin(), archs.end(), Arch) != archs.end());
 }
                                                                        /*}}}*/
+// setDefaultConfigurationForCompressors                               /*{{{*/
+void Configuration::setDefaultConfigurationForCompressors() {
+       // Set default application paths to check for optional compression types
+       _config->CndSet("Dir::Bin::lzma", "/usr/bin/lzma");
+       _config->CndSet("Dir::Bin::xz", "/usr/bin/xz");
+       _config->CndSet("Dir::Bin::bzip2", "/bin/bzip2");
+}
+                                                                       /*}}}*/
+// getCompressors - Return Vector of usbale compressors                        /*{{{*/
+// ---------------------------------------------------------------------
+/* return a vector of compressors used by apt-ftparchive in the
+   multicompress functionality or to detect data.tar files */
+std::vector<APT::Configuration::Compressor>
+const Configuration::getCompressors(bool const Cached) {
+       static std::vector<APT::Configuration::Compressor> compressors;
+       if (compressors.empty() == false) {
+               if (Cached == true)
+                       return compressors;
+               else
+                       compressors.clear();
+       }
+
+       setDefaultConfigurationForCompressors();
+
+       compressors.push_back(Compressor(".", "", "", "", "", 1));
+       if (_config->Exists("Dir::Bin::gzip") == false || FileExists(_config->FindFile("Dir::Bin::gzip")) == true)
+               compressors.push_back(Compressor("gzip",".gz","gzip","-9n","-d",2));
+       if (_config->Exists("Dir::Bin::bzip2") == false || FileExists(_config->FindFile("Dir::Bin::bzip2")) == true)
+               compressors.push_back(Compressor("bzip2",".bz2","bzip2","-9","-d",3));
+       if (_config->Exists("Dir::Bin::lzma") == false || FileExists(_config->FindFile("Dir::Bin::lzma")) == true)
+               compressors.push_back(Compressor("lzma",".lzma","lzma","-9","-d",4));
+       if (_config->Exists("Dir::Bin::xz") == false || FileExists(_config->FindFile("Dir::Bin::xz")) == true)
+               compressors.push_back(Compressor("xz",".xz","xz","-6","-d",5));
+
+       std::vector<std::string> const comp = _config->FindVector("APT::Compressor");
+       for (std::vector<std::string>::const_iterator c = comp.begin();
+            c != comp.end(); ++c) {
+               if (*c == "." || *c == "gzip" || *c == "bzip2" || *c == "lzma" || *c == "xz")
+                       continue;
+               compressors.push_back(Compressor(c->c_str(), std::string(".").append(*c).c_str(), c->c_str(), "-9", "-d", 100));
+       }
+
+       return compressors;
+}
+                                                                       /*}}}*/
+// getCompressorExtensions - supported data.tar extensions             /*{{{*/
+// ---------------------------------------------------------------------
+/* */
+std::vector<std::string> const Configuration::getCompressorExtensions() {
+       std::vector<APT::Configuration::Compressor> const compressors = getCompressors();
+       std::vector<std::string> ext;
+       for (std::vector<APT::Configuration::Compressor>::const_iterator c = compressors.begin();
+            c != compressors.end(); ++c)
+               if (c->Extension.empty() == false && c->Extension != ".")
+                       ext.push_back(c->Extension);
+       return ext;
+}
+                                                                       /*}}}*/
+// Compressor constructor                                              /*{{{*/
+// ---------------------------------------------------------------------
+/* */
+Configuration::Compressor::Compressor(char const *name, char const *extension,
+                                     char const *binary,
+                                     char const *compressArg, char const *uncompressArg,
+                                     unsigned short const cost) {
+       std::string const config = string("APT:Compressor::").append(name).append("::");
+       Name = _config->Find(std::string(config).append("Name"), name);
+       Extension = _config->Find(std::string(config).append("Extension"), extension);
+       Binary = _config->Find(std::string(config).append("Binary"), binary);
+       Cost = _config->FindI(std::string(config).append("Cost"), cost);
+       std::string const compConf = std::string(config).append("CompressArg");
+       if (_config->Exists(compConf) == true)
+               CompressArgs = _config->FindVector(compConf);
+       else if (compressArg != NULL)
+               CompressArgs.push_back(compressArg);
+       std::string const uncompConf = std::string(config).append("UncompressArg");
+       if (_config->Exists(uncompConf) == true)
+               UncompressArgs = _config->FindVector(uncompConf);
+       else if (uncompressArg != NULL)
+               UncompressArgs.push_back(uncompressArg);
+}
+                                                                       /*}}}*/
 }
index dd339d8..815db6c 100644 (file)
@@ -82,6 +82,35 @@ public:                                                                      /*{{{*/
         */
        bool static const checkArchitecture(std::string const &Arch);
 
+       /** \brief Representation of supported compressors */
+       struct Compressor {
+               std::string Name;
+               std::string Extension;
+               std::string Binary;
+               std::vector<std::string> CompressArgs;
+               std::vector<std::string> UncompressArgs;
+               unsigned short Cost;
+
+               Compressor(char const *name, char const *extension, char const *binary,
+                          char const *compressArg, char const *uncompressArg,
+                          unsigned short const cost);
+               Compressor() {};
+       };
+
+       /** \brief Return a vector of Compressors supported for data.tar's
+        *
+        *  \param Cached saves the result so we need to calculated it only once
+        *                this parameter should ony be used for testing purposes.
+        *
+        *  \return a vector of Compressors
+        */
+       std::vector<Compressor> static const getCompressors(bool const Cached = true);
+
+       /** \brief Return a vector of extensions supported for data.tar's */
+       std::vector<std::string> static const getCompressorExtensions();
+                                                                       /*}}}*/
+       private:                                                        /*{{{*/
+       void static setDefaultConfigurationForCompressors();
                                                                        /*}}}*/
 };
                                                                        /*}}}*/
index 175c1be..71e5a0e 100644 (file)
@@ -72,8 +72,8 @@ class Configuration
    string Find(string const &Name, string const &Default) const {return Find(Name.c_str(),Default.c_str());};
    string FindFile(const char *Name,const char *Default = 0) const;
    string FindDir(const char *Name,const char *Default = 0) const;
-   std::vector<string> FindVector(string const &Name) const;
    std::vector<string> FindVector(const char *Name) const;
+   std::vector<string> FindVector(string const &Name) const { return FindVector(Name.c_str()); };
    int FindI(const char *Name,int const &Default = 0) const;
    int FindI(string const &Name,int const &Default = 0) const {return FindI(Name.c_str(),Default);};
    bool FindB(const char *Name,bool const &Default = false) const;
index 21336e1..7493050 100644 (file)
@@ -14,6 +14,7 @@
 #include <apt-pkg/error.h>
 #include <apt-pkg/strutl.h>
 #include <apt-pkg/configuration.h>
+#include <apt-pkg/aptconfiguration.h>
 
 using std::max;
                                                                        /*}}}*/
@@ -111,7 +112,9 @@ bool debSrcRecordParser::Files(vector<pkgSrcRecords::File> &List)
    string Base = Sect.FindS("Directory");
    if (Base.empty() == false && Base[Base.length()-1] != '/')
       Base += '/';
-   
+
+   std::vector<std::string> const compExts = APT::Configuration::getCompressorExtensions();
+
    // Iterate over the entire list grabbing each triplet
    const char *C = Files.c_str();
    while (*C != 0)
@@ -144,7 +147,8 @@ bool debSrcRecordParser::Files(vector<pkgSrcRecords::File> &List)
         }
         F.Type = string(F.Path,Tmp+1,Pos-Tmp);
         
-        if (F.Type == "gz" || F.Type == "bz2" || F.Type == "lzma" || F.Type == "tar")
+        if (std::find(compExts.begin(), compExts.end(), std::string(".").append(F.Type)) != compExts.end() ||
+            F.Type == "tar")
         {
            Pos = Tmp-1;
            continue;
index bc2f71c..c0983b0 100644 (file)
@@ -1718,7 +1718,7 @@ bool DoAutomaticRemove(CacheFile &Cache)
                   R->Type != pkgCache::Dep::PreDepends)
                  continue;
               pkgCache::PkgIterator N = R.ParentPkg();
-              if (N.end() == true || N->CurrentVer == 0)
+              if (N.end() == true || (N->CurrentVer == 0 && (*Cache)[N].Install() == false))
                  continue;
               if (Debug == true)
                  std::clog << "Save " << P << " as another installed garbage package depends on it" << std::endl;
index 779bcad..971e967 100644 (file)
@@ -1,11 +1,34 @@
 apt (0.8.11.6) UNRELEASED; urgency=low
 
+  [ Christian Perrier ]
   * Fix error in French translation of manpages (apt_preferences(5)).
     Merci, RĂ©mi Vanicat. Closes: #613689
   * Complete French manpage translation
   * Italian translation update (Milo Casagrande). Closes: #614395
 
- -- Christian Perrier <bubulle@debian.org>  Fri, 18 Feb 2011 05:53:49 +0100
+  [ David Kalnischkies ]
+  * ftparchive/multicompress.cc, apt-inst/deb/debfile.cc:
+    - support xz compressor to create xz-compressed Indexes and be able
+      to open data.tar.xz files
+    - load the supported compressors from configuration
+  * ftparchive/writer.cc:
+    - ensure that Date and Valid-Until time strings are not localised
+    - add options to disable specific checksums for Indexes
+    - include xz-compressed Packages and Sources files in Release file
+  * apt-pkg/aptconfiguration.cc:
+    - support download of xz-compressed indexes files
+    - support adding new compressors by configuration
+  * apt-pkg/deb/debsrcrecords.cc:
+    - support xz-compressed source v3 debian.tar files
+    - support every compression we have a compressor configured
+  * ftparchive/contents.cc:
+    - remove ExtractArchive codecopy from apt-inst/deb/debfile.cc
+  * apt-inst/deb/debfile.cc:
+    - support data.tar's compressed with any configured compressor
+  * cmdline/apt-get.cc:
+    - reinstall dependencies of reinstalled "garbage" (Closes: #617257)
+
+ -- David Kalnischkies <kalnischkies@gmail.com>  Mon, 07 Mar 2011 22:43:15 +0100
 
 apt (0.8.11.5) unstable; urgency=low
 
index 0090d21..8e5df1f 100644 (file)
@@ -526,11 +526,14 @@ for i in Sections do
    &apt-cmdblurb;
    
    <variablelist>
-     <varlistentry><term><option>--md5</option></term>
+     <varlistentry><term><option>--md5</option>, <option>--sha1</option>, <option>--sha256</option></term>
      <listitem><para>
-     Generate MD5 sums. This defaults to on, when turned off the generated 
-     index files will not have MD5Sum fields where possible.
-     Configuration Item: <literal>APT::FTPArchive::MD5</literal></para></listitem>
+     Generate the given checksum. These options default to on, when turned off the generated
+     index files will not have the checksum fields where possible.
+     Configuration Items: <literal>APT::FTPArchive::<replaceable>Checksum</replaceable></literal> and
+     <literal>APT::FTPArchive::<replaceable>Index</replaceable>::<replaceable>Checksum</replaceable></literal> where
+     <literal>Index</literal> can be <literal>Packages</literal>, <literal>Sources</literal> or <literal>Release</literal> and
+     <literal>Checksum</literal> can be <literal>MD5</literal>, <literal>SHA1</literal> or <literal>SHA256</literal>.</para></listitem>
      </varlistentry>
 
      <varlistentry><term><option>-d</option></term><term><option>--db</option></term>
index 0c29002..0762a2b 100644 (file)
@@ -949,6 +949,8 @@ int main(int argc, const char *argv[])
    CommandLine::Args Args[] = {
       {'h',"help","help",0},
       {0,"md5","APT::FTPArchive::MD5",0},
+      {0,"sha1","APT::FTPArchive::SHA1",0},
+      {0,"sha256","APT::FTPArchive::SHA256",0},
       {'v',"version","version",0},
       {'d',"db","APT::FTPArchive::DB",CommandLine::HasArg},
       {'s',"source-override","APT::FTPArchive::SourceOverride",CommandLine::HasArg},
index b761d92..eadced6 100644 (file)
 #include "contents.h"
 
 #include <apti18n.h>
+#include <apt-pkg/debfile.h>
 #include <apt-pkg/extracttar.h>
 #include <apt-pkg/error.h>
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
-#include <malloc.h>    
+#include <malloc.h>
                                                                        /*}}}*/
 
 // GenContents::~GenContents - Free allocated memory                   /*{{{*/
@@ -305,29 +306,7 @@ void GenContents::DoPrint(FILE *Out,GenContents::Node *Top, char *Buf)
 bool ContentsExtract::Read(debDebFile &Deb)
 {
    Reset();
-   
-   // Get the archive member and positition the file 
-   const ARArchive::Member *Member = Deb.GotoMember("data.tar.gz");
-   const char *Compressor = "gzip";
-   if (Member == 0) {
-      Member = Deb.GotoMember("data.tar.bz2");
-      Compressor = "bzip2";
-   }
-   if (Member == 0) {
-      Member = Deb.GotoMember("data.tar.lzma");
-      Compressor = "lzma";
-   }
-   if (Member == 0) {
-      _error->Error(_("Internal error, could not locate member %s"),
-                   "data.tar.{gz,bz2,lzma}");
-      return false;
-   }
-      
-   // Extract it.
-   ExtractTar Tar(Deb.GetFile(),Member->Size,Compressor);
-   if (Tar.Go(*this) == false)
-      return false;   
-   return true;   
+   return Deb.ExtractArchive(*this);
 }
                                                                        /*}}}*/
 // ContentsExtract::DoItem - Extract an item                           /*{{{*/
index bb4beed..f828790 100644 (file)
 
 using namespace std;
 
-const MultiCompress::CompType MultiCompress::Compressors[] =
-      {{".","",0,0,0,1},
-       {"gzip",".gz","gzip","-9n","-d",2},
-       {"bzip2",".bz2","bzip2","-9","-d",3},
-       {"lzma",".lzma","lzma","-9","-d",4},
-       {}};
 
 // MultiCompress::MultiCompress - Constructor                          /*{{{*/
 // ---------------------------------------------------------------------
@@ -48,7 +42,7 @@ MultiCompress::MultiCompress(string const &Output,string const &Compress,
    Outputter = -1;
    Input = 0;
    UpdateMTime = 0;
-   
+
    /* Parse the compression string, a space separated lists of compresison
       types */
    string::const_iterator I = Compress.begin();
@@ -61,13 +55,14 @@ MultiCompress::MultiCompress(string const &Output,string const &Compress,
       for (; I != Compress.end() && !isspace(*I); I++);
 
       // Find the matching compressor
-      const CompType *Comp = Compressors;
-      for (; Comp->Name != 0; Comp++)
-        if (stringcmp(Start,I,Comp->Name) == 0)
+      std::vector<APT::Configuration::Compressor> Compressors = APT::Configuration::getCompressors();
+      std::vector<APT::Configuration::Compressor>::const_iterator Comp = Compressors.begin();
+      for (; Comp != Compressors.end(); ++Comp)
+        if (stringcmp(Start,I,Comp->Name.c_str()) == 0)
            break;
 
       // Hmm.. unknown.
-      if (Comp->Name == 0)
+      if (Comp == Compressors.end())
       {
         _error->Warning(_("Unknown compression algorithm '%s'"),string(Start,I).c_str());
         continue;
@@ -77,7 +72,7 @@ MultiCompress::MultiCompress(string const &Output,string const &Compress,
       Files *NewOut = new Files;
       NewOut->Next = Outputs;
       Outputs = NewOut;
-      NewOut->CompressProg = Comp;
+      NewOut->CompressProg = *Comp;
       NewOut->Output = Output+Comp->Extension;
       
       struct stat St;
@@ -141,13 +136,14 @@ bool MultiCompress::GetStat(string const &Output,string const &Compress,struct s
       for (; I != Compress.end() && !isspace(*I); I++);
 
       // Find the matching compressor
-      const CompType *Comp = Compressors;
-      for (; Comp->Name != 0; Comp++)
-        if (stringcmp(Start,I,Comp->Name) == 0)
+      std::vector<APT::Configuration::Compressor> Compressors = APT::Configuration::getCompressors();
+      std::vector<APT::Configuration::Compressor>::const_iterator Comp = Compressors.begin();
+      for (; Comp != Compressors.end(); ++Comp)
+        if (stringcmp(Start,I,Comp->Name.c_str()) == 0)
            break;
 
       // Hmm.. unknown.
-      if (Comp->Name == 0)
+      if (Comp == Compressors.end())
         continue;
 
       string Name = Output+Comp->Extension;
@@ -268,13 +264,13 @@ bool MultiCompress::Finalize(unsigned long &OutSize)
 /* This opens the compressor, either in compress mode or decompress 
    mode. FileFd is always the compressor input/output file, 
    OutFd is the created pipe, Input for Compress, Output for Decompress. */
-bool MultiCompress::OpenCompress(const CompType *Prog,pid_t &Pid,int const &FileFd,
-                                int &OutFd,bool const &Comp)
+bool MultiCompress::OpenCompress(APT::Configuration::Compressor const &Prog,
+                                pid_t &Pid,int const &FileFd,int &OutFd,bool const &Comp)
 {
    Pid = -1;
    
    // No compression
-   if (Prog->Binary == 0)
+   if (Prog.Binary.empty() == true)
    {
       OutFd = dup(FileFd);
       return true;
@@ -309,15 +305,17 @@ bool MultiCompress::OpenCompress(const CompType *Prog,pid_t &Pid,int const &File
       
       SetCloseExec(STDOUT_FILENO,false);
       SetCloseExec(STDIN_FILENO,false);
-      
-      const char *Args[3];
-      Args[0] = Prog->Binary;
-      if (Comp == true)
-        Args[1] = Prog->CompArgs;
-      else
-        Args[1] = Prog->UnCompArgs;
-      Args[2] = 0;
-      execvp(Args[0],(char **)Args);
+
+      std::vector<char const*> Args;
+      Args.push_back(Prog.Binary.c_str());
+      std::vector<std::string> const * const addArgs =
+               (Comp == true) ? &(Prog.CompressArgs) : &(Prog.UncompressArgs);
+      for (std::vector<std::string>::const_iterator a = addArgs->begin();
+          a != addArgs->end(); ++a)
+        Args.push_back(a->c_str());
+      Args.push_back(NULL);
+
+      execvp(Args[0],(char **)&Args[0]);
       cerr << _("Failed to exec compressor ") << Args[0] << endl;
       _exit(100);
    };      
@@ -335,7 +333,7 @@ bool MultiCompress::OpenOld(int &Fd,pid_t &Proc)
 {
    Files *Best = Outputs;
    for (Files *I = Outputs; I != 0; I = I->Next)
-      if (Best->CompressProg->Cost > I->CompressProg->Cost)
+      if (Best->CompressProg.Cost > I->CompressProg.Cost)
         Best = I;
 
    // Open the file
@@ -414,7 +412,7 @@ bool MultiCompress::Child(int const &FD)
    for (Files *I = Outputs; I != 0; I = I->Next)
    {
       if (I->CompressProc != -1)
-        ExecWait(I->CompressProc,I->CompressProg->Binary,false);
+        ExecWait(I->CompressProc, I->CompressProg.Binary.c_str(), false);
    }
    
    if (_error->PendingError() == true)
index 3ac3b8f..19dede1 100644 (file)
 
 #include <string>
 #include <apt-pkg/fileutl.h>
+#include <apt-pkg/aptconfiguration.h>
 #include <stdio.h>
 #include <sys/types.h>
     
 class MultiCompress
 {
-   // Enumeration of all supported compressors
-   struct CompType
-   {
-      const char *Name;
-      const char *Extension;
-      const char *Binary;
-      const char *CompArgs;
-      const char *UnCompArgs;
-      unsigned char Cost;
-   };
-
    // An output file
    struct Files
    {
       string Output;
-      const CompType *CompressProg;
-      Files *Next;      
+      APT::Configuration::Compressor CompressProg;
+      Files *Next;
       FileFd TmpFile;
       pid_t CompressProc;
       time_t OldMTime;
@@ -51,10 +41,9 @@ class MultiCompress
    Files *Outputs;
    pid_t Outputter;
    mode_t Permissions;
-   static const CompType Compressors[];
 
-   bool OpenCompress(const CompType *Prog,pid_t &Pid,int const &FileFd,
-                    int &OutFd,bool const &Comp);
+   bool OpenCompress(APT::Configuration::Compressor const &Prog,
+                    pid_t &Pid,int const &FileFd, int &OutFd,bool const &Comp);
    bool Child(int const &Fd);
    bool Start();
    bool Die();
index 9cdca8d..9f12cbf 100644 (file)
@@ -17,6 +17,7 @@
 #include <apt-pkg/strutl.h>
 #include <apt-pkg/error.h>
 #include <apt-pkg/configuration.h>
+#include <apt-pkg/aptconfiguration.h>
 #include <apt-pkg/md5.h>
 #include <apt-pkg/sha1.h>
 #include <apt-pkg/sha256.h>
@@ -59,6 +60,10 @@ FTWScanner::FTWScanner(string const &Arch): Arch(Arch)
 {
    ErrorPrinted = false;
    NoLinkAct = !_config->FindB("APT::FTPArchive::DeLinkAct",true);
+
+   DoMD5 = _config->FindB("APT::FTPArchive::MD5",true);
+   DoSHA1 = _config->FindB("APT::FTPArchive::SHA1",true);
+   DoSHA256 = _config->FindB("APT::FTPArchive::SHA256",true);
 }
                                                                        /*}}}*/
 // FTWScanner::Scanner - FTW Scanner                                   /*{{{*/
@@ -308,9 +313,9 @@ PackagesWriter::PackagesWriter(string const &DB,string const &Overrides,string c
    DeLinkLimit = 0;
 
    // Process the command line options
-   DoMD5 = _config->FindB("APT::FTPArchive::MD5",true);
-   DoSHA1 = _config->FindB("APT::FTPArchive::SHA1",true);
-   DoSHA256 = _config->FindB("APT::FTPArchive::SHA256",true);
+   DoMD5 = _config->FindB("APT::FTPArchive::Packages::MD5",DoMD5);
+   DoSHA1 = _config->FindB("APT::FTPArchive::Packages::SHA1",DoSHA1);
+   DoSHA256 = _config->FindB("APT::FTPArchive::Packages::SHA256",DoSHA256);
    DoAlwaysStat = _config->FindB("APT::FTPArchive::AlwaysStat", false);
    DoContents = _config->FindB("APT::FTPArchive::Contents",true);
    NoOverride = _config->FindB("APT::FTPArchive::NoOverrideMsg",false);
@@ -435,9 +440,12 @@ bool PackagesWriter::DoPackage(string FileName)
 
    unsigned int End = 0;
    SetTFRewriteData(Changes[End++], "Size", Size);
-   SetTFRewriteData(Changes[End++], "MD5sum", Db.MD5Res.c_str());
-   SetTFRewriteData(Changes[End++], "SHA1", Db.SHA1Res.c_str());
-   SetTFRewriteData(Changes[End++], "SHA256", Db.SHA256Res.c_str());
+   if (DoMD5 == true)
+      SetTFRewriteData(Changes[End++], "MD5sum", Db.MD5Res.c_str());
+   if (DoSHA1 == true)
+      SetTFRewriteData(Changes[End++], "SHA1", Db.SHA1Res.c_str());
+   if (DoSHA256 == true)
+      SetTFRewriteData(Changes[End++], "SHA256", Db.SHA256Res.c_str());
    SetTFRewriteData(Changes[End++], "Filename", NewFileName.c_str());
    SetTFRewriteData(Changes[End++], "Priority", OverItem->Priority.c_str());
    SetTFRewriteData(Changes[End++], "Status", 0);
@@ -559,6 +567,9 @@ SourcesWriter::SourcesWriter(string const &BOverrides,string const &SOverrides,
    BufSize = 0;
    
    // Process the command line options
+   DoMD5 = _config->FindB("APT::FTPArchive::Sources::MD5",DoMD5);
+   DoSHA1 = _config->FindB("APT::FTPArchive::Sources::SHA1",DoSHA1);
+   DoSHA256 = _config->FindB("APT::FTPArchive::Sources::SHA256",DoSHA256);
    NoOverride = _config->FindB("APT::FTPArchive::NoOverrideMsg",false);
 
    // Read the override file
@@ -608,13 +619,17 @@ bool SourcesWriter::DoPackage(string FileName)
    // Hash the file
    char *Start = Buffer;
    char *BlkEnd = Buffer + St.st_size;
-   MD5Summation MD5;
-   MD5.Add((unsigned char *)Start,BlkEnd - Start);
 
+   MD5Summation MD5;
    SHA1Summation SHA1;
    SHA256Summation SHA256;
-   SHA1.Add((unsigned char *)Start,BlkEnd - Start);
-   SHA256.Add((unsigned char *)Start,BlkEnd - Start);
+
+   if (DoMD5 == true)
+      MD5.Add((unsigned char *)Start,BlkEnd - Start);
+   if (DoSHA1 == true)
+      SHA1.Add((unsigned char *)Start,BlkEnd - Start);
+   if (DoSHA256 == true)
+      SHA256.Add((unsigned char *)Start,BlkEnd - Start);
 
    // Add an extra \n to the end, just in case
    *BlkEnd++ = '\n';
@@ -708,19 +723,19 @@ bool SourcesWriter::DoPackage(string FileName)
    // Add the dsc to the files hash list
    string const strippedName = flNotDir(FileName);
    std::ostringstream ostreamFiles;
-   if (Tags.Exists("Files"))
+   if (DoMD5 == true && Tags.Exists("Files"))
       ostreamFiles << "\n " << string(MD5.Result()) << " " << St.st_size << " "
                   << strippedName << "\n " << Tags.FindS("Files");
    string const Files = ostreamFiles.str();
 
    std::ostringstream ostreamSha1;
-   if (Tags.Exists("Checksums-Sha1"))
+   if (DoSHA1 == true && Tags.Exists("Checksums-Sha1"))
       ostreamSha1 << "\n " << string(SHA1.Result()) << " " << St.st_size << " "
                   << strippedName << "\n " << Tags.FindS("Checksums-Sha1");
    string const ChecksumsSha1 = ostreamSha1.str();
 
    std::ostringstream ostreamSha256;
-   if (Tags.Exists("Checksums-Sha256"))
+   if (DoSHA256 == true && Tags.Exists("Checksums-Sha256"))
       ostreamSha256 << "\n " << string(SHA256.Result()) << " " << St.st_size << " "
                   << strippedName << "\n " << Tags.FindS("Checksums-Sha256");
    string const ChecksumsSha256 = ostreamSha256.str();
@@ -774,9 +789,12 @@ bool SourcesWriter::DoPackage(string FileName)
 
    unsigned int End = 0;
    SetTFRewriteData(Changes[End++],"Source",Package.c_str(),"Package");
-   SetTFRewriteData(Changes[End++],"Files",Files.c_str());
-   SetTFRewriteData(Changes[End++],"Checksums-Sha1",ChecksumsSha1.c_str());
-   SetTFRewriteData(Changes[End++],"Checksums-Sha256",ChecksumsSha256.c_str());
+   if (Files.empty() == false)
+      SetTFRewriteData(Changes[End++],"Files",Files.c_str());
+   if (ChecksumsSha1.empty() == false)
+      SetTFRewriteData(Changes[End++],"Checksums-Sha1",ChecksumsSha1.c_str());
+   if (ChecksumsSha256.empty() == false)
+      SetTFRewriteData(Changes[End++],"Checksums-Sha256",ChecksumsSha256.c_str());
    if (Directory != "./")
       SetTFRewriteData(Changes[End++],"Directory",Directory.c_str());
    SetTFRewriteData(Changes[End++],"Priority",BestPrio.c_str());
@@ -913,10 +931,12 @@ ReleaseWriter::ReleaseWriter(string const &DB)
       AddPattern("Packages.gz");
       AddPattern("Packages.bz2");
       AddPattern("Packages.lzma");
+      AddPattern("Packages.xz");
       AddPattern("Sources");
       AddPattern("Sources.gz");
       AddPattern("Sources.bz2");
       AddPattern("Sources.lzma");
+      AddPattern("Sources.xz");
       AddPattern("Release");
       AddPattern("Index");
       AddPattern("md5sum.txt");
@@ -925,6 +945,9 @@ ReleaseWriter::ReleaseWriter(string const &DB)
 
    Output = stdout;
    time_t const now = time(NULL);
+
+   setlocale(LC_TIME, "C");
+
    char datestr[128];
    if (strftime(datestr, sizeof(datestr), "%a, %d %b %Y %H:%M:%S UTC",
                 gmtime(&now)) == 0)
@@ -941,6 +964,8 @@ ReleaseWriter::ReleaseWriter(string const &DB)
       validstr[0] = '\0';
    }
 
+   setlocale(LC_TIME, "");
+
    map<string,string> Fields;
    Fields["Origin"] = "";
    Fields["Label"] = "";
@@ -964,6 +989,10 @@ ReleaseWriter::ReleaseWriter(string const &DB)
 
       fprintf(Output, "%s: %s\n", (*I).first.c_str(), Value.c_str());
    }
+
+   DoMD5 = _config->FindB("APT::FTPArchive::Release::MD5",DoMD5);
+   DoSHA1 = _config->FindB("APT::FTPArchive::Release::SHA1",DoSHA1);
+   DoSHA256 = _config->FindB("APT::FTPArchive::Release::SHA256",DoSHA256);
 }
                                                                        /*}}}*/
 // ReleaseWriter::DoPackage - Process a single package                 /*{{{*/
@@ -996,19 +1025,26 @@ bool ReleaseWriter::DoPackage(string FileName)
 
    CheckSums[NewFileName].size = fd.Size();
 
-   MD5Summation MD5;
-   MD5.AddFD(fd.Fd(), fd.Size());
-   CheckSums[NewFileName].MD5 = MD5.Result();
-
-   fd.Seek(0);
-   SHA1Summation SHA1;
-   SHA1.AddFD(fd.Fd(), fd.Size());
-   CheckSums[NewFileName].SHA1 = SHA1.Result();
-
-   fd.Seek(0);
-   SHA256Summation SHA256;
-   SHA256.AddFD(fd.Fd(), fd.Size());
-   CheckSums[NewFileName].SHA256 = SHA256.Result();
+   if (DoMD5 == true)
+   {
+      MD5Summation MD5;
+      MD5.AddFD(fd.Fd(), fd.Size());
+      CheckSums[NewFileName].MD5 = MD5.Result();
+      fd.Seek(0);
+   }
+   if (DoSHA1 == true)
+   {
+      SHA1Summation SHA1;
+      SHA1.AddFD(fd.Fd(), fd.Size());
+      CheckSums[NewFileName].SHA1 = SHA1.Result();
+      fd.Seek(0);
+   }
+   if (DoSHA256 == true)
+   {
+      SHA256Summation SHA256;
+      SHA256.AddFD(fd.Fd(), fd.Size());
+      CheckSums[NewFileName].SHA256 = SHA256.Result();
+   }
 
    fd.Close();
    
@@ -1020,37 +1056,40 @@ bool ReleaseWriter::DoPackage(string FileName)
 // ---------------------------------------------------------------------
 void ReleaseWriter::Finish()
 {
-   fprintf(Output, "MD5Sum:\n");
-   for(map<string,struct CheckSum>::const_iterator I = CheckSums.begin();
-       I != CheckSums.end();
-       ++I)
+   if (DoMD5 == true)
    {
-      fprintf(Output, " %s %16ld %s\n",
-              (*I).second.MD5.c_str(),
-              (*I).second.size,
-              (*I).first.c_str());
+      fprintf(Output, "MD5Sum:\n");
+      for(map<string,struct CheckSum>::const_iterator I = CheckSums.begin();
+         I != CheckSums.end(); ++I)
+      {
+        fprintf(Output, " %s %16ld %s\n",
+                (*I).second.MD5.c_str(),
+                (*I).second.size,
+                (*I).first.c_str());
+      }
    }
-
-   fprintf(Output, "SHA1:\n");
-   for(map<string,struct CheckSum>::const_iterator I = CheckSums.begin();
-       I != CheckSums.end();
-       ++I)
+   if (DoSHA1 == true)
    {
-      fprintf(Output, " %s %16ld %s\n",
-              (*I).second.SHA1.c_str(),
-              (*I).second.size,
-              (*I).first.c_str());
+      fprintf(Output, "SHA1:\n");
+      for(map<string,struct CheckSum>::const_iterator I = CheckSums.begin();
+         I != CheckSums.end(); ++I)
+      {
+        fprintf(Output, " %s %16ld %s\n",
+                (*I).second.SHA1.c_str(),
+                (*I).second.size,
+                (*I).first.c_str());
+      }
    }
-
-   fprintf(Output, "SHA256:\n");
-   for(map<string,struct CheckSum>::const_iterator I = CheckSums.begin();
-       I != CheckSums.end();
-       ++I)
+   if (DoSHA256 == true)
    {
-      fprintf(Output, " %s %16ld %s\n",
-              (*I).second.SHA256.c_str(),
-              (*I).second.size,
-              (*I).first.c_str());
+      fprintf(Output, "SHA256:\n");
+      for(map<string,struct CheckSum>::const_iterator I = CheckSums.begin();
+         I != CheckSums.end(); ++I)
+      {
+        fprintf(Output, " %s %16ld %s\n",
+                (*I).second.SHA256.c_str(),
+                (*I).second.size,
+                (*I).first.c_str());
+      }
    }
 }
-
index 3796f79..ce0eab7 100644 (file)
@@ -60,6 +60,9 @@ class FTWScanner
    }
    
    public:
+   bool DoMD5;
+   bool DoSHA1;
+   bool DoSHA256;
 
    unsigned long DeLinkLimit;
    string InternalPrefix;
@@ -103,9 +106,6 @@ class PackagesWriter : public FTWScanner
    public:
 
    // Some flags
-   bool DoMD5;
-   bool DoSHA1;
-   bool DoSHA256;
    bool DoAlwaysStat;
    bool NoOverride;
    bool DoContents;
index 4ee356c..6ba5105 100644 (file)
@@ -94,8 +94,8 @@ SOURCE = bzip2.cc
 include $(PROGRAM_H)
 
 # SSH and lzma method symlink
-binary: $(BIN)/ssh $(BIN)/lzma
-veryclean: clean-$(BIN)/ssh clean-$(BIN)/lzma
+binary: $(BIN)/ssh $(BIN)/lzma $(BIN)/xz
+veryclean: clean-$(BIN)/ssh clean-$(BIN)/lzma clean-$(BIN)/xz
 
 $(BIN)/ssh:
        echo "Installing ssh method link"
@@ -108,3 +108,9 @@ $(BIN)/lzma:
        ln -fs bzip2 $(BIN)/lzma
 clean-$(BIN)/lzma:
        -rm $(BIN)/lzma
+
+$(BIN)/xz:
+       echo "Installing xz method link"
+       ln -fs bzip2 $(BIN)/xz
+clean-$(BIN)/xz:
+       -rm $(BIN)/xz
index 7e1d25e..71e7e47 100644 (file)
@@ -328,10 +328,10 @@ createaptftparchiveconfig() {
        echo -n '";
 };
 Default {
-       Packages::Compress ". gzip bzip2 lzma";
-       Sources::Compress ". gzip bzip2 lzma";
-       Contents::Compress ". gzip bzip2 lzma";
-       Translation::Compress ". gzip bzip2 lzma";
+       Packages::Compress ". gzip bzip2 lzma xz";
+       Sources::Compress ". gzip bzip2 lzma xz";
+       Contents::Compress ". gzip bzip2 lzma xz";
+       Translation::Compress ". gzip bzip2 lzma xz";
        LongDescription "false";
 };
 TreeDefault {
@@ -438,6 +438,7 @@ buildaptarchivefromfiles() {
                cat ${line} | gzip > ${line}.gz
                cat ${line} | bzip2 > ${line}.bz2
                cat ${line} | lzma > ${line}.lzma
+               cat ${line} | xz > ${line}.xz
                msgdone "info"
        done
        generatereleasefiles
index 2179ba0..11dee06 100755 (executable)
@@ -54,12 +54,14 @@ setupcompressor() {
        gzip) COMPRESS="gz";;
        bzip2) COMPRESS="bz2";;
        lzma) COMPRESS="lzma";;
+       xz) COMPRESS="xz";;
        esac
        echo "Acquire::CompressionTypes::Order { \"${COMPRESS}\"; };
 Dir::Bin::uncompressed \"/does/not/exist\";
 Dir::Bin::gzip \"/does/not/exist\";
 Dir::Bin::bzip2 \"/does/not/exist\";
-Dir::Bin::lzma \"/does/not/exist\";" > rootdir/etc/apt/apt.conf.d/00compressor
+Dir::Bin::lzma \"/does/not/exist\";
+Dir::Bin::xz \"/does/not/exist\";" > rootdir/etc/apt/apt.conf.d/00compressor
        if [ -e "/bin/${COMPRESSOR}" ]; then
                echo "Dir::Bin::${COMPRESSOR} \"/bin/${COMPRESSOR}\";" >> rootdir/etc/apt/apt.conf.d/00compressor
        elif [ -e "/usr/bin/${COMPRESSOR}" ]; then
@@ -134,9 +136,9 @@ W: Failed to fetch ${COMPRESSOR}:$(readlink -f rootdir/var/lib/apt/lists/partial
 E: Some index files failed to download. They have been ignored, or old ones used instead." "empty file Packages.$COMPRESS over http"
 }
 
-for COMPRESSOR in 'gzip' 'bzip2' 'lzma'; do testoverfile $COMPRESSOR; done
+for COMPRESSOR in 'gzip' 'bzip2' 'lzma' 'xz'; do testoverfile $COMPRESSOR; done
 
 # do the same again with http instead of file
 changetowebserver
 
-for COMPRESSOR in 'gzip' 'bzip2' 'lzma'; do testoverhttp $COMPRESSOR; done
+for COMPRESSOR in 'gzip' 'bzip2' 'lzma' 'xz'; do testoverhttp $COMPRESSOR; done