Browse Source

Merge remote-tracking branch 'upstream/debian/sid' into feature/apt-manpage

Conflicts:
	cmdline/apt.cc
Michael Vogt 12 years ago
parent
commit
be20eef52d
100 changed files with 2464 additions and 1395 deletions
  1. 4 2
      .gitignore
  2. 1 1
      COMPILING
  3. 2 2
      README.ddtp
  4. 1 1
      README.make
  5. 1 1
      README.progress-reporting
  6. 4 2
      apt-inst/contrib/arfile.cc
  7. 14 6
      apt-inst/contrib/extracttar.cc
  8. 36 22
      apt-inst/deb/debfile.cc
  9. 6 1
      apt-inst/deb/debfile.h
  10. 11 13
      apt-inst/dirstream.cc
  11. 2 2
      apt-inst/dirstream.h
  12. 12 5
      apt-inst/extract.cc
  13. 3 2
      apt-inst/extract.h
  14. 5 7
      apt-inst/filelist.cc
  15. 76 76
      apt-inst/filelist.h
  16. 207 51
      apt-pkg/acquire-item.cc
  17. 111 8
      apt-pkg/acquire-item.h
  18. 10 2
      apt-pkg/acquire-method.cc
  19. 4 1
      apt-pkg/acquire-method.h
  20. 12 4
      apt-pkg/acquire-worker.cc
  21. 5 2
      apt-pkg/acquire-worker.h
  22. 13 7
      apt-pkg/acquire.cc
  23. 10 5
      apt-pkg/acquire.h
  24. 47 32
      apt-pkg/algorithms.cc
  25. 7 4
      apt-pkg/algorithms.h
  26. 59 72
      apt-pkg/aptconfiguration.cc
  27. 12 7
      apt-pkg/aptconfiguration.h
  28. 10 3
      apt-pkg/cachefile.cc
  29. 7 2
      apt-pkg/cachefile.h
  30. 3 1
      apt-pkg/cachefilter.cc
  31. 2 1
      apt-pkg/cachefilter.h
  32. 139 134
      apt-pkg/cacheiterators.h
  33. 54 21
      apt-pkg/cacheset.cc
  34. 105 91
      apt-pkg/cacheset.h
  35. 94 116
      apt-pkg/cdrom.cc
  36. 9 1
      apt-pkg/cdrom.h
  37. 5 1
      apt-pkg/clean.cc
  38. 6 1
      apt-pkg/clean.h
  39. 56 38
      apt-pkg/contrib/cdromutl.cc
  40. 6 1
      apt-pkg/contrib/cmndline.cc
  41. 5 3
      apt-pkg/contrib/cmndline.h
  42. 22 6
      apt-pkg/contrib/configuration.cc
  43. 15 1
      apt-pkg/contrib/configuration.h
  44. 1 1
      apt-pkg/contrib/crc-16.cc
  45. 3 1
      apt-pkg/contrib/crc-16.h
  46. 4 2
      apt-pkg/contrib/error.cc
  47. 20 19
      apt-pkg/contrib/error.h
  48. 391 193
      apt-pkg/contrib/fileutl.cc
  49. 8 6
      apt-pkg/contrib/fileutl.h
  50. 15 14
      apt-pkg/contrib/gpgv.cc
  51. 9 11
      apt-pkg/contrib/gpgv.h
  52. 8 5
      apt-pkg/contrib/hashes.cc
  53. 11 6
      apt-pkg/contrib/hashes.h
  54. 6 4
      apt-pkg/contrib/hashsum.cc
  55. 28 24
      apt-pkg/contrib/hashsum_template.h
  56. 72 18
      apt-pkg/contrib/macros.h
  57. 1 5
      apt-pkg/contrib/md5.cc
  58. 6 5
      apt-pkg/contrib/md5.h
  59. 10 4
      apt-pkg/contrib/mmap.cc
  60. 2 2
      apt-pkg/contrib/mmap.h
  61. 2 3
      apt-pkg/contrib/netrc.cc
  62. 4 2
      apt-pkg/contrib/netrc.h
  63. 8 6
      apt-pkg/contrib/progress.cc
  64. 1 1
      apt-pkg/contrib/progress.h
  65. 1 4
      apt-pkg/contrib/sha1.cc
  66. 4 3
      apt-pkg/contrib/sha1.h
  67. 7 3
      apt-pkg/contrib/sha2.h
  68. 2 1
      apt-pkg/contrib/sha2_internal.cc
  69. 1 0
      apt-pkg/contrib/sha2_internal.h
  70. 17 10
      apt-pkg/contrib/strutl.cc
  71. 39 36
      apt-pkg/contrib/strutl.h
  72. 13 3
      apt-pkg/deb/debindexfile.cc
  73. 14 6
      apt-pkg/deb/debindexfile.h
  74. 148 30
      apt-pkg/deb/deblistparser.cc
  75. 27 4
      apt-pkg/deb/deblistparser.h
  76. 9 2
      apt-pkg/deb/debmetaindex.cc
  77. 7 1
      apt-pkg/deb/debmetaindex.h
  78. 7 1
      apt-pkg/deb/debrecords.cc
  79. 3 0
      apt-pkg/deb/debrecords.h
  80. 11 4
      apt-pkg/deb/debsrcrecords.cc
  81. 9 4
      apt-pkg/deb/debsrcrecords.h
  82. 10 3
      apt-pkg/deb/debsystem.cc
  83. 9 1
      apt-pkg/deb/debsystem.h
  84. 4 2
      apt-pkg/deb/debversion.cc
  85. 10 10
      apt-pkg/deb/debversion.h
  86. 58 57
      apt-pkg/deb/dpkgpm.cc
  87. 13 4
      apt-pkg/deb/dpkgpm.h
  88. 92 34
      apt-pkg/depcache.cc
  89. 19 8
      apt-pkg/depcache.h
  90. 17 10
      apt-pkg/edsp.cc
  91. 13 11
      apt-pkg/edsp.h
  92. 12 7
      apt-pkg/edsp/edspindexfile.cc
  93. 5 1
      apt-pkg/edsp/edspindexfile.h
  94. 8 6
      apt-pkg/edsp/edsplistparser.cc
  95. 4 0
      apt-pkg/edsp/edsplistparser.h
  96. 11 10
      apt-pkg/edsp/edspsystem.cc
  97. 13 4
      apt-pkg/edsp/edspsystem.h
  98. 18 20
      apt-pkg/indexcopy.cc
  99. 6 4
      apt-pkg/indexcopy.h
  100. 0 0
      apt-pkg/indexfile.cc

+ 4 - 2
.gitignore

@@ -1,3 +1,4 @@
+*~
 # build artifacts
 /aclocal.m4
 /autom4te.cache/
@@ -34,9 +35,10 @@
 /cmdline/apt-key
 /doc/apt-vendor.ent
 /doc/examples/sources.list
+/debian/apt.install
 /debian/libapt-pkg*.install
 /debian/libapt-inst*.install
 /debian/libapt-pkg-dev.install
 /vendor/current
-/vendor/debian/sources.list
-/vendor/ubuntu/sources.list
+/vendor/*/sources.list
+/vendor/*/makefile.auto

+ 1 - 1
COMPILING

@@ -27,7 +27,7 @@ I am not interested in making 'ultra portable code'. I will accept patches
 to make the code that already exists conform more to SUS or POSIX, but
 I don't really care if your not-SUS OS doesn't work. It is simply too
 much work to maintain patches for dysfunctional OSs. I highly suggest you
-contact your vendor and express intrest in a conforming C library.
+contact your vendor and express interest in a conforming C library.
 
 That said, there are lots of finicky problems that must be dealt with even
 between the supported OS's. Primarily the path I choose to take is to put

+ 2 - 2
README.ddtp

@@ -52,7 +52,7 @@ is md5("XXX\n YYY\n .\n ZZZ\n") (perl-syntax).
 A future APT version will download one or some 'Translate-$lang'
 file(s) at 'update'-time. After this download it show a translated
 description instead of the english form, if it found a translated
-description of the package with the right md5 chechsum. The enviroment
+description of the package with the right md5 chechsum. The environment
 of the user will controlled this process (LANG, LANGUAGE, LC_MESSAGES,
 etc). With this the package system will never show a outdated
 translation.
@@ -60,7 +60,7 @@ translation.
 The translations come all from the DDTP. A daily process on
 ddtp.debian.org make new 'Translated-$lang' files and a script on
 ftp-master request this files and move this to the debian archive.
-Now the first files are accessable at 
+Now the first files are accessible at
 	<a  href="http://ddtp.debian.org/pdesc/translatefiles/">http://ddtp.debian.org/pdesc/translatefiles/</a>
 
 If you found wrong translations, please read the guides on

+ 1 - 1
README.make

@@ -25,7 +25,7 @@ of these parameters will have an immediate effect. The use of makefile.in
 and configure substitutions across build makefiles is not used at all.
 
 Furthermore, the make system runs with a current directory equal to the
-source directory irregardless of the destination directory. This means
+source directory regardless of the destination directory. This means
 #include "" and #include <> work as expected and more importantly
 running 'make' in the source directory will work as expected. The
 environment variable or make parameter 'BUILD' sets the build directory.

+ 1 - 1
README.progress-reporting

@@ -2,7 +2,7 @@ Install-progress reporting
 --------------------------
 
 If the apt options: "APT::Status-Fd" is set, apt will send status
-reports to that fd. The status information is seperated with a ':', 
+reports to that fd. The status information is separated with a ':',
 there are the following status conditions:
 
 status = {"pmstatus", "dlstatus", "conffile-prompt", "error", "media-change" } 

+ 4 - 2
apt-inst/contrib/arfile.cc

@@ -6,7 +6,7 @@
    AR File - Handle an 'AR' archive
    
    AR Archives have plain text headers at the start of each file
-   section. The headers are aligned on a 2 byte boundry.
+   section. The headers are aligned on a 2 byte boundary.
    
    Information about the structure of AR files can be found in ar(5)
    on a BSD system, or in the binutils source.
@@ -21,7 +21,9 @@
 #include <apt-pkg/fileutl.h>
 #include <apt-pkg/error.h>
 
-#include <stdlib.h>
+#include <string.h>
+#include <sys/types.h>
+#include <string>
 
 #include <apti18n.h>
 									/*}}}*/

+ 14 - 6
apt-inst/contrib/extracttar.cc

@@ -6,7 +6,7 @@
    Extract a Tar - Tar Extractor
 
    Some performance measurements showed that zlib performed quite poorly
-   in comparision to a forked gzip process. This tar extractor makes use
+   in comparison to a forked gzip process. This tar extractor makes use
    of the fact that dup'd file descriptors have the same seek pointer
    and that gzip will not read past the end of a compressed stream, 
    even if there is more data. We use the dup property to track extraction
@@ -23,9 +23,11 @@
 #include <apt-pkg/error.h>
 #include <apt-pkg/strutl.h>
 #include <apt-pkg/configuration.h>
-#include <apt-pkg/macros.h>
+#include <apt-pkg/fileutl.h>
 
-#include <stdlib.h>
+#include <string.h>
+#include <algorithm>
+#include <string>
 #include <unistd.h>
 #include <signal.h>
 #include <fcntl.h>
@@ -111,10 +113,16 @@ bool ExtractTar::Done(bool Force)
    gzip will efficiently ignore the extra bits. */
 bool ExtractTar::StartGzip()
 {
+   if (DecompressProg.empty())
+   {
+      InFd.OpenDescriptor(File.Fd(), FileFd::ReadOnly, FileFd::None, false);
+      return true;
+   }
+
    int Pipes[2];
    if (pipe(Pipes) != 0)
       return _error->Errno("pipe",_("Failed to create pipes"));
-   
+
    // Fork off the process
    GZPid = ExecFork();
 
@@ -130,9 +138,9 @@ bool ExtractTar::StartGzip()
       dup2(Fd,STDERR_FILENO);
       close(Fd);
       SetCloseExec(STDOUT_FILENO,false);
-      SetCloseExec(STDIN_FILENO,false);      
+      SetCloseExec(STDIN_FILENO,false);
       SetCloseExec(STDERR_FILENO,false);
-      
+
       const char *Args[3];
       string confvar = string("dir::bin::") + DecompressProg;
       string argv0 = _config->Find(confvar.c_str(),DecompressProg.c_str());

+ 36 - 22
apt-inst/deb/debfile.cc

@@ -21,11 +21,17 @@
 #include <apt-pkg/debfile.h>
 #include <apt-pkg/extracttar.h>
 #include <apt-pkg/error.h>
-#include <apt-pkg/deblistparser.h>
 #include <apt-pkg/aptconfiguration.h>
-
+#include <apt-pkg/arfile.h>
+#include <apt-pkg/dirstream.h>
+#include <apt-pkg/fileutl.h>
+#include <apt-pkg/tagfile.h>
+
+#include <string.h>
+#include <string>
+#include <vector>
 #include <sys/stat.h>
-#include <unistd.h>
+
 #include <apti18n.h>
 									/*}}}*/
 
@@ -42,12 +48,15 @@ debDebFile::debDebFile(FileFd &File) : File(File), AR(File)
       return;
    }
 
-   if (!CheckMember("control.tar.gz")) {
-      _error->Error(_("This is not a valid DEB archive, missing '%s' member"), "control.tar.gz");
+   if (!CheckMember("control.tar") &&
+       !CheckMember("control.tar.gz") &&
+       !CheckMember("control.tar.xz")) {
+      _error->Error(_("This is not a valid DEB archive, missing '%s' member"), "control.tar");
       return;
    }
 
-   if (!CheckMember("data.tar.gz") &&
+   if (!CheckMember("data.tar") &&
+       !CheckMember("data.tar.gz") &&
        !CheckMember("data.tar.bz2") &&
        !CheckMember("data.tar.lzma") &&
        !CheckMember("data.tar.xz")) {
@@ -88,33 +97,37 @@ const ARArchive::Member *debDebFile::GotoMember(const char *Name)
    return Member;
 }
 									/*}}}*/
-// DebFile::ExtractArchive - Extract the archive data itself		/*{{{*/
+// DebFile::ExtractTarMember - Extract the contents of a tar member	/*{{{*/
 // ---------------------------------------------------------------------
 /* Simple wrapper around tar.. */
-bool debDebFile::ExtractArchive(pkgDirStream &Stream)
+bool debDebFile::ExtractTarMember(pkgDirStream &Stream,const char *Name)
 {
    // 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());
+      Member = AR.FindMember(std::string(Name).append(c->Extension).c_str());
       if (Member == NULL)
 	 continue;
       Compressor = c->Binary;
       break;
    }
 
+   if (Member == NULL)
+      Member = AR.FindMember(std::string(Name).c_str());
+
    if (Member == NULL)
    {
-      std::string ext = "data.tar.{";
+      std::string ext = std::string(Name) + ".{";
       for (std::vector<APT::Configuration::Compressor>::const_iterator c = compressor.begin();
-	   c != compressor.end(); ++c)
-	 ext.append(c->Extension.substr(1));
+	   c != compressor.end(); ++c) {
+	 if (!c->Extension.empty())
+	    ext.append(c->Extension.substr(1));
+      }
       ext.append("}");
       return _error->Error(_("Internal error, could not locate member %s"), ext.c_str());
    }
@@ -129,6 +142,14 @@ bool debDebFile::ExtractArchive(pkgDirStream &Stream)
    return Tar.Go(Stream);
 }
 									/*}}}*/
+// DebFile::ExtractArchive - Extract the archive data itself		/*{{{*/
+// ---------------------------------------------------------------------
+/* Simple wrapper around DebFile::ExtractTarMember. */
+bool debDebFile::ExtractArchive(pkgDirStream &Stream)
+{
+   return ExtractTarMember(Stream, "data.tar");
+}
+									/*}}}*/
 
 // DebFile::ControlExtract::DoItem - Control Tar Extraction		/*{{{*/
 // ---------------------------------------------------------------------
@@ -181,7 +202,7 @@ bool debDebFile::MemControlExtract::DoItem(Item &Itm,int &Fd)
 // ---------------------------------------------------------------------
 /* Just memcopy the block from the tar extractor and put it in the right
    place in the pre-allocated memory block. */
-bool debDebFile::MemControlExtract::Process(Item &Itm,const unsigned char *Data,
+bool debDebFile::MemControlExtract::Process(Item &/*Itm*/,const unsigned char *Data,
 			     unsigned long Size,unsigned long Pos)
 {
    memcpy(Control + Pos, Data,Size);
@@ -194,14 +215,7 @@ bool debDebFile::MemControlExtract::Process(Item &Itm,const unsigned char *Data,
    it parses it into a tag section parser. */
 bool debDebFile::MemControlExtract::Read(debDebFile &Deb)
 {
-   // Get the archive member and positition the file 
-   const ARArchive::Member *Member = Deb.GotoMember("control.tar.gz");
-   if (Member == 0)
-      return false;
-
-   // Extract it.
-   ExtractTar Tar(Deb.GetFile(),Member->Size,"gzip");
-   if (Tar.Go(*this) == false)
+   if (Deb.ExtractTarMember(*this, "control.tar") == false)
       return false;
 
    if (Control == 0)

+ 6 - 1
apt-inst/deb/debfile.h

@@ -27,11 +27,15 @@
 #include <apt-pkg/arfile.h>
 #include <apt-pkg/dirstream.h>
 #include <apt-pkg/tagfile.h>
-#include <apt-pkg/pkgcache.h>
+
+#include <string>
 
 #ifndef APT_8_CLEANER_HEADERS
 #include <apt-pkg/md5.h>
 #endif
+#ifndef APT_10_CLEANER_HEADERS
+#include <apt-pkg/pkgcache.h>
+#endif
 
 class FileFd;
 
@@ -48,6 +52,7 @@ class debDebFile
    class ControlExtract;
    class MemControlExtract;
 
+   bool ExtractTarMember(pkgDirStream &Stream, const char *Name);
    bool ExtractArchive(pkgDirStream &Stream);
    const ARArchive::Member *GotoMember(const char *Name);
    inline FileFd &GetFile() {return File;};

+ 11 - 13
apt-inst/dirstream.cc

@@ -18,9 +18,8 @@
 
 #include <fcntl.h>
 #include <sys/stat.h>
-#include <sys/types.h>
+#include <sys/time.h>
 #include <errno.h>
-#include <utime.h>
 #include <unistd.h>
 #include <apti18n.h>
 									/*}}}*/
@@ -93,25 +92,24 @@ bool pkgDirStream::FinishedFile(Item &Itm,int Fd)
 {
    if (Fd < 0)
       return true;
-   
-   if (close(Fd) != 0)
-      return _error->Errno("close",_("Failed to close file %s"),Itm.Name);
 
    /* Set the modification times. The only way it can fail is if someone
       has futzed with our file, which is intolerable :> */
-   struct utimbuf Time;
-   Time.actime = Itm.MTime;
-   Time.modtime = Itm.MTime;
-   if (utime(Itm.Name,&Time) != 0)
-      _error->Errno("utime",_("Failed to close file %s"),Itm.Name);
-   
-   return true;   
+   struct timeval times[2];
+   times[0].tv_sec = times[1].tv_sec = Itm.MTime;
+   times[0].tv_usec = times[1].tv_usec = 0;
+   if (utimes(Itm.Name, times) != 0)
+      _error->Errno("utimes", "Failed to set modification time for %s",Itm.Name);
+
+   if (close(Fd) != 0)
+      return _error->Errno("close",_("Failed to close file %s"),Itm.Name);
+   return true;
 }
 									/*}}}*/
 // DirStream::Fail - Failed processing a file				/*{{{*/
 // ---------------------------------------------------------------------
 /* */
-bool pkgDirStream::Fail(Item &Itm,int Fd)
+bool pkgDirStream::Fail(Item &/*Itm*/, int Fd)
 {
    if (Fd < 0)
       return true;

+ 2 - 2
apt-inst/dirstream.h

@@ -49,8 +49,8 @@ class pkgDirStream
    virtual bool DoItem(Item &Itm,int &Fd);
    virtual bool Fail(Item &Itm,int Fd);
    virtual bool FinishedFile(Item &Itm,int Fd);
-   virtual bool Process(Item &Itm,const unsigned char *Data,
-			unsigned long Size,unsigned long Pos) {return true;};
+   virtual bool Process(Item &/*Itm*/,const unsigned char * /*Data*/,
+			unsigned long /*Size*/,unsigned long /*Pos*/) {return true;};
       
    virtual ~pkgDirStream() {};   
 };

+ 12 - 5
apt-inst/extract.cc

@@ -10,7 +10,7 @@
    object is unpacked to '.dpkg.new' then the original is hardlinked to
    '.dpkg.tmp' and finally the new object is renamed to overwrite the old
    one. From an external perspective the file never ceased to exist.
-   After the archive has been sucessfully unpacked the .dpkg.tmp files 
+   After the archive has been successfully unpacked the .dpkg.tmp files
    are erased. A failure causes all the .dpkg.tmp files to be restored.
    
    Decisions about unpacking go like this:
@@ -22,7 +22,7 @@
         [Note, this is reduced to only check if a file was expected to be
          there]
       - If the existing link/file is not a directory then it is replaced
-        irregardless
+        regardless
       - If the existing link/directory is being replaced by a directory then
         absolutely nothing happens.
       - If the existing link/directory is being replaced by a link then
@@ -50,13 +50,20 @@
 #include <apt-pkg/error.h>
 #include <apt-pkg/debversion.h>
 #include <apt-pkg/fileutl.h>
+#include <apt-pkg/dirstream.h>
+#include <apt-pkg/filelist.h>
+#include <apt-pkg/mmap.h>
+#include <apt-pkg/pkgcache.h>
+#include <apt-pkg/cacheiterators.h>
 
+#include <string.h>
+#include <string>
 #include <sys/stat.h>
 #include <stdio.h>
-#include <unistd.h>
 #include <errno.h>
 #include <dirent.h>
 #include <iostream>
+
 #include <apti18n.h>
 									/*}}}*/
 using namespace std;
@@ -79,7 +86,7 @@ pkgExtract::pkgExtract(pkgFLCache &FLCache,pkgCache::VerIterator Ver) :
 // Extract::DoItem - Handle a single item from the stream		/*{{{*/
 // ---------------------------------------------------------------------
 /* This performs the setup for the extraction.. */
-bool pkgExtract::DoItem(Item &Itm,int &Fd)
+bool pkgExtract::DoItem(Item &Itm, int &/*Fd*/)
 {
    /* Strip any leading/trailing /s from the filename, then copy it to the
       temp buffer and re-apply the leading / We use a class variable
@@ -253,7 +260,7 @@ bool pkgExtract::DoItem(Item &Itm,int &Fd)
 // Extract::Finished - Sequence finished, erase the temp files		/*{{{*/
 // ---------------------------------------------------------------------
 /* */
-bool pkgExtract::Finished()
+APT_CONST bool pkgExtract::Finished()
 {
    return true;
 }

+ 3 - 2
apt-inst/extract.h

@@ -17,11 +17,12 @@
 #ifndef PKGLIB_EXTRACT_H
 #define PKGLIB_EXTRACT_H
 
-
-
 #include <apt-pkg/dirstream.h>
 #include <apt-pkg/filelist.h>
 #include <apt-pkg/pkgcache.h>
+#include <apt-pkg/cacheiterators.h>
+
+#include <string>
 
 class pkgExtract : public pkgDirStream
 {

+ 5 - 7
apt-inst/filelist.cc

@@ -5,14 +5,14 @@
 
    File Listing - Manages a Cache of File -> Package names.
 
-   Diversions add some signficant complexity to the system. To keep 
+   Diversions add some significant complexity to the system. To keep
    storage space down in the very special case of a diverted file no
    extra bytes are allocated in the Node structure. Instead a diversion
    is inserted directly into the hash table and its flag bit set. Every
    lookup for that filename will always return the diversion.
    
    The hash buckets are stored in sorted form, with diversions having 
-   the higest sort order. Identical files are assigned the same file
+   the highest sort order. Identical files are assigned the same file
    pointer, thus after a search all of the nodes owning that file can be
    found by iterating down the bucket.
    
@@ -39,8 +39,6 @@
 #include <apt-pkg/error.h>
 #include <apt-pkg/strutl.h>
 
-#include <stdio.h>
-#include <stdlib.h>
 #include <string.h>
 #include <iostream>
 #include <apti18n.h>
@@ -87,7 +85,7 @@ pkgFLCache::Header::Header()
 // FLCache::Header::CheckSizes - Check if the two headers have same *sz	/*{{{*/
 // ---------------------------------------------------------------------
 /* Compare to make sure we are matching versions */
-bool pkgFLCache::Header::CheckSizes(Header &Against) const
+APT_PURE bool pkgFLCache::Header::CheckSizes(Header &Against) const
 {
    if (HeaderSz == Against.HeaderSz &&
        NodeSz == Against.NodeSz &&
@@ -355,7 +353,7 @@ pkgFLCache::NodeIterator pkgFLCache::GetNode(const char *Name,
 // ---------------------------------------------------------------------
 /* This is one of two hashing functions. The other is inlined into the
    GetNode routine. */
-pkgFLCache::Node *pkgFLCache::HashNode(NodeIterator const &Nde)
+APT_PURE pkgFLCache::Node *pkgFLCache::HashNode(NodeIterator const &Nde)
 {
    // Hash the node
    unsigned long HashPos = 0;
@@ -572,7 +570,7 @@ bool pkgFLCache::AddConfFile(const char *Name,const char *NameEnd,
 // ---------------------------------------------------------------------
 /* Since the package pointer is indirected in all sorts of interesting ways
    this is used to get a pointer to the owning package */
-pkgFLCache::Package *pkgFLCache::NodeIterator::RealPackage() const
+APT_PURE pkgFLCache::Package *pkgFLCache::NodeIterator::RealPackage() const
 {
    if (Nde->Pointer == 0)
       return 0;

+ 76 - 76
apt-inst/filelist.h

@@ -42,25 +42,25 @@ class pkgFLCache
    struct Package;
    struct Diversion;
    struct ConfFile;
-   
+
    class NodeIterator;
    class DirIterator;
    class PkgIterator;
    class DiverIterator;
-   
+
    protected:
    std::string CacheFile;
    DynamicMMap &Map;
    map_ptrloc LastTreeLookup;
    unsigned long LastLookupSize;
-   
+
    // Helpers for the addition algorithms
    map_ptrloc TreeLookup(map_ptrloc *Base,const char *Text,const char *TextEnd,
 			 unsigned long Size,unsigned int *Count = 0,
 			 bool Insert = false);
-   
+
    public:
-   
+
    // Pointers to the arrays of items
    Header *HeaderP;
    Node *NodeP;
@@ -70,10 +70,10 @@ class pkgFLCache
    ConfFile *ConfP;
    char *StrP;
    unsigned char *AnyP;
-   
+
    // Quick accessors
    Node *FileHash;
-   
+
    // Accessors
    Header &Head() {return *HeaderP;};
    void PrintTree(map_ptrloc Base,unsigned long Size);
@@ -89,7 +89,7 @@ class pkgFLCache
    void DropNode(map_ptrloc Node);
 
    inline DiverIterator DiverBegin();
-   
+
    // Diversion control
    void BeginDiverLoad();
    void FinishDiverLoad();
@@ -97,7 +97,7 @@ class pkgFLCache
 		     const char *To);
    bool AddConfFile(const char *Name,const char *NameEnd,
 		    PkgIterator const &Owner,const unsigned char *Sum);
-			     
+
    pkgFLCache(DynamicMMap &Map);
 //   ~pkgFLCache();
 };
@@ -109,7 +109,7 @@ struct pkgFLCache::Header
    short MajorVersion;
    short MinorVersion;
    bool Dirty;
-   
+
    // Size of structure values
    unsigned HeaderSz;
    unsigned NodeSz;
@@ -117,7 +117,7 @@ struct pkgFLCache::Header
    unsigned PackageSz;
    unsigned DiversionSz;
    unsigned ConfFileSz;
-   
+
    // Structure Counts;
    unsigned int NodeCount;
    unsigned int DirCount;
@@ -126,13 +126,13 @@ struct pkgFLCache::Header
    unsigned int ConfFileCount;
    unsigned int HashSize;
    unsigned long UniqNodes;
-      
+
    // Offsets
    map_ptrloc FileHash;
    map_ptrloc DirTree;
    map_ptrloc Packages;
    map_ptrloc Diversions;
-      
+
    /* Allocation pools, there should be one of these for each structure
       excluding the header */
    DynamicMMap::Pool Pools[5];
@@ -177,7 +177,7 @@ struct pkgFLCache::Diversion
    map_ptrloc OwnerPkg;       // Package
    map_ptrloc DivertFrom;     // Node
    map_ptrloc DivertTo;       // String
-   
+
    map_ptrloc Next;           // Diversion
    unsigned long Flags;
 
@@ -194,120 +194,120 @@ class pkgFLCache::PkgIterator
 {
    Package *Pkg;
    pkgFLCache *Owner;
-   
+
    public:
-   
+
    inline bool end() const {return Owner == 0 || Pkg == Owner->PkgP?true:false;}
-   
+
    // Accessors
-   inline Package *operator ->() {return Pkg;};
-   inline Package const *operator ->() const {return Pkg;};
-   inline Package const &operator *() const {return *Pkg;};
-   inline operator Package *() {return Pkg == Owner->PkgP?0:Pkg;};
-   inline operator Package const *() const {return Pkg == Owner->PkgP?0:Pkg;};
-
-   inline unsigned long Offset() const {return Pkg - Owner->PkgP;};
-   inline const char *Name() const {return Pkg->Name == 0?0:Owner->StrP + Pkg->Name;};
+   inline Package *operator ->() {return Pkg;}
+   inline Package const *operator ->() const {return Pkg;}
+   inline Package const &operator *() const {return *Pkg;}
+   inline operator Package *() {return Pkg == Owner->PkgP?0:Pkg;}
+   inline operator Package const *() const {return Pkg == Owner->PkgP?0:Pkg;}
+
+   inline unsigned long Offset() const {return Pkg - Owner->PkgP;}
+   inline const char *Name() const {return Pkg->Name == 0?0:Owner->StrP + Pkg->Name;}
    inline pkgFLCache::NodeIterator Files() const;
 
-   PkgIterator() : Pkg(0), Owner(0) {};
-   PkgIterator(pkgFLCache &Owner,Package *Trg) : Pkg(Trg), Owner(&Owner) {};
+   PkgIterator() : Pkg(0), Owner(0) {}
+   PkgIterator(pkgFLCache &Owner,Package *Trg) : Pkg(Trg), Owner(&Owner) {}
 };
 
 class pkgFLCache::DirIterator
 {
    Directory *Dir;
    pkgFLCache *Owner;
-   
+
    public:
-   
+
    // Accessors
-   inline Directory *operator ->() {return Dir;};
-   inline Directory const *operator ->() const {return Dir;};
-   inline Directory const &operator *() const {return *Dir;};
-   inline operator Directory *() {return Dir == Owner->DirP?0:Dir;};
-   inline operator Directory const *() const {return Dir == Owner->DirP?0:Dir;};
+   inline Directory *operator ->() {return Dir;}
+   inline Directory const *operator ->() const {return Dir;}
+   inline Directory const &operator *() const {return *Dir;}
+   inline operator Directory *() {return Dir == Owner->DirP?0:Dir;}
+   inline operator Directory const *() const {return Dir == Owner->DirP?0:Dir;}
 
-   inline const char *Name() const {return Dir->Name == 0?0:Owner->StrP + Dir->Name;};
+   inline const char *Name() const {return Dir->Name == 0?0:Owner->StrP + Dir->Name;}
 
-   DirIterator() : Dir(0), Owner(0) {};
-   DirIterator(pkgFLCache &Owner,Directory *Trg) : Dir(Trg), Owner(&Owner) {};
+   DirIterator() : Dir(0), Owner(0) {}
+   DirIterator(pkgFLCache &Owner,Directory *Trg) : Dir(Trg), Owner(&Owner) {}
 };
 
 class pkgFLCache::DiverIterator
 {
    Diversion *Diver;
    pkgFLCache *Owner;
-   
+
    public:
 
    // Iteration
-   void operator ++(int) {if (Diver != Owner->DiverP) Diver = Owner->DiverP + Diver->Next;};
-   inline void operator ++() {operator ++(0);};
-   inline bool end() const {return Owner == 0 || Diver == Owner->DiverP;};
+   void operator ++(int) {if (Diver != Owner->DiverP) Diver = Owner->DiverP + Diver->Next;}
+   inline void operator ++() {operator ++(0);}
+   inline bool end() const {return Owner == 0 || Diver == Owner->DiverP;}
 
    // Accessors
-   inline Diversion *operator ->() {return Diver;};
-   inline Diversion const *operator ->() const {return Diver;};
-   inline Diversion const &operator *() const {return *Diver;};
-   inline operator Diversion *() {return Diver == Owner->DiverP?0:Diver;};
-   inline operator Diversion const *() const {return Diver == Owner->DiverP?0:Diver;};
+   inline Diversion *operator ->() {return Diver;}
+   inline Diversion const *operator ->() const {return Diver;}
+   inline Diversion const &operator *() const {return *Diver;}
+   inline operator Diversion *() {return Diver == Owner->DiverP?0:Diver;}
+   inline operator Diversion const *() const {return Diver == Owner->DiverP?0:Diver;}
 
-   inline PkgIterator OwnerPkg() const {return PkgIterator(*Owner,Owner->PkgP + Diver->OwnerPkg);};
+   inline PkgIterator OwnerPkg() const {return PkgIterator(*Owner,Owner->PkgP + Diver->OwnerPkg);}
    inline NodeIterator DivertFrom() const;
    inline NodeIterator DivertTo() const;
 
    DiverIterator() : Diver(0), Owner(0) {};
-   DiverIterator(pkgFLCache &Owner,Diversion *Trg) : Diver(Trg), Owner(&Owner) {};
+   DiverIterator(pkgFLCache &Owner,Diversion *Trg) : Diver(Trg), Owner(&Owner) {}
 };
 
 class pkgFLCache::NodeIterator
 {
    Node *Nde;
-   enum {NdePkg, NdeHash} Type;   
+   enum {NdePkg, NdeHash} Type;
    pkgFLCache *Owner;
-   
+
    public:
-   
+
    // Iteration
-   void operator ++(int) {if (Nde != Owner->NodeP) Nde = Owner->NodeP + 
-	 (Type == NdePkg?Nde->NextPkg:Nde->Next);};
-   inline void operator ++() {operator ++(0);};
-   inline bool end() const {return Owner == 0 || Nde == Owner->NodeP;};
+   void operator ++(int) {if (Nde != Owner->NodeP) Nde = Owner->NodeP +
+	 (Type == NdePkg?Nde->NextPkg:Nde->Next);}
+   inline void operator ++() {operator ++(0);}
+   inline bool end() const {return Owner == 0 || Nde == Owner->NodeP;}
 
    // Accessors
-   inline Node *operator ->() {return Nde;};
-   inline Node const *operator ->() const {return Nde;};
-   inline Node const &operator *() const {return *Nde;};
-   inline operator Node *() {return Nde == Owner->NodeP?0:Nde;};
-   inline operator Node const *() const {return Nde == Owner->NodeP?0:Nde;};
-   inline unsigned long Offset() const {return Nde - Owner->NodeP;};
-   inline DirIterator Dir() const {return DirIterator(*Owner,Owner->DirP + Nde->Dir);};
-   inline DiverIterator Diversion() const {return DiverIterator(*Owner,Owner->DiverP + Nde->Pointer);};
-   inline const char *File() const {return Nde->File == 0?0:Owner->StrP + Nde->File;};
-   inline const char *DirN() const {return Owner->StrP + Owner->DirP[Nde->Dir].Name;};
+   inline Node *operator ->() {return Nde;}
+   inline Node const *operator ->() const {return Nde;}
+   inline Node const &operator *() const {return *Nde;}
+   inline operator Node *() {return Nde == Owner->NodeP?0:Nde;}
+   inline operator Node const *() const {return Nde == Owner->NodeP?0:Nde;}
+   inline unsigned long Offset() const {return Nde - Owner->NodeP;}
+   inline DirIterator Dir() const {return DirIterator(*Owner,Owner->DirP + Nde->Dir);}
+   inline DiverIterator Diversion() const {return DiverIterator(*Owner,Owner->DiverP + Nde->Pointer);}
+   inline const char *File() const {return Nde->File == 0?0:Owner->StrP + Nde->File;}
+   inline const char *DirN() const {return Owner->StrP + Owner->DirP[Nde->Dir].Name;}
    Package *RealPackage() const;
-   
+
    NodeIterator() : Nde(0), Type(NdeHash), Owner(0) {};
-   NodeIterator(pkgFLCache &Owner) : Nde(Owner.NodeP), Type(NdeHash), Owner(&Owner) {};
-   NodeIterator(pkgFLCache &Owner,Node *Trg) : Nde(Trg), Type(NdeHash), Owner(&Owner) {};
-   NodeIterator(pkgFLCache &Owner,Node *Trg,Package *) : Nde(Trg), Type(NdePkg), Owner(&Owner) {};
+   NodeIterator(pkgFLCache &Owner) : Nde(Owner.NodeP), Type(NdeHash), Owner(&Owner) {}
+   NodeIterator(pkgFLCache &Owner,Node *Trg) : Nde(Trg), Type(NdeHash), Owner(&Owner) {}
+   NodeIterator(pkgFLCache &Owner,Node *Trg,Package *) : Nde(Trg), Type(NdePkg), Owner(&Owner) {}
 };
 
 /* Inlines with forward references that cannot be included directly in their
    respsective classes */
-inline pkgFLCache::NodeIterator pkgFLCache::DiverIterator::DivertFrom() const 
-   {return NodeIterator(*Owner,Owner->NodeP + Diver->DivertFrom);};
+inline pkgFLCache::NodeIterator pkgFLCache::DiverIterator::DivertFrom() const
+   {return NodeIterator(*Owner,Owner->NodeP + Diver->DivertFrom);}
 inline pkgFLCache::NodeIterator pkgFLCache::DiverIterator::DivertTo() const
-   {return NodeIterator(*Owner,Owner->NodeP + Diver->DivertTo);};
+   {return NodeIterator(*Owner,Owner->NodeP + Diver->DivertTo);}
 
 inline pkgFLCache::NodeIterator pkgFLCache::PkgIterator::Files() const
-   {return NodeIterator(*Owner,Owner->NodeP + Pkg->Files,Pkg);};
+   {return NodeIterator(*Owner,Owner->NodeP + Pkg->Files,Pkg);}
 
 inline pkgFLCache::DiverIterator pkgFLCache::DiverBegin()
-   {return DiverIterator(*this,DiverP + HeaderP->Diversions);};
+   {return DiverIterator(*this,DiverP + HeaderP->Diversions);}
 
-inline pkgFLCache::PkgIterator pkgFLCache::GetPkg(const char *Name,bool Insert) 
-   {return GetPkg(Name,Name+strlen(Name),Insert);};
+inline pkgFLCache::PkgIterator pkgFLCache::GetPkg(const char *Name,bool Insert)
+   {return GetPkg(Name,Name+strlen(Name),Insert);}
 
 #endif

+ 207 - 51
apt-pkg/acquire-item.cc

@@ -22,12 +22,21 @@
 #include <apt-pkg/error.h>
 #include <apt-pkg/strutl.h>
 #include <apt-pkg/fileutl.h>
-#include <apt-pkg/md5.h>
 #include <apt-pkg/sha1.h>
 #include <apt-pkg/tagfile.h>
 #include <apt-pkg/indexrecords.h>
-#include <apt-pkg/metaindex.h>
-
+#include <apt-pkg/acquire.h>
+#include <apt-pkg/hashes.h>
+#include <apt-pkg/indexfile.h>
+#include <apt-pkg/pkgcache.h>
+#include <apt-pkg/cacheiterators.h>
+#include <apt-pkg/pkgrecords.h>
+
+#include <stddef.h>
+#include <stdlib.h>
+#include <string.h>
+#include <iostream>
+#include <vector>
 #include <sys/stat.h>
 #include <unistd.h>
 #include <errno.h>
@@ -108,8 +117,8 @@ void pkgAcquire::Item::Start(string /*Message*/,unsigned long long Size)
 // Acquire::Item::Done - Item downloaded OK				/*{{{*/
 // ---------------------------------------------------------------------
 /* */
-void pkgAcquire::Item::Done(string Message,unsigned long long Size,string Hash,
-			    pkgAcquire::MethodConfig *Cnf)
+void pkgAcquire::Item::Done(string Message,unsigned long long Size,string /*Hash*/,
+			    pkgAcquire::MethodConfig * /*Cnf*/)
 {
    // We just downloaded something..
    string FileName = LookupTag(Message,"Filename");
@@ -129,7 +138,7 @@ void pkgAcquire::Item::Done(string Message,unsigned long long Size,string Hash,
 									/*}}}*/
 // Acquire::Item::Rename - Rename a file				/*{{{*/
 // ---------------------------------------------------------------------
-/* This helper function is used by alot of item methods as thier final
+/* This helper function is used by a lot of item methods as their final
    step */
 void pkgAcquire::Item::Rename(string From,string To)
 {
@@ -253,10 +262,10 @@ string pkgAcqSubIndex::Custom600Headers()
    return "\nIndex-File: true\nFail-Ignore: true\nLast-Modified: " + TimeRFC1123(Buf.st_mtime);
 }
 									/*}}}*/
-void pkgAcqSubIndex::Failed(string Message,pkgAcquire::MethodConfig *Cnf)	/*{{{*/
+void pkgAcqSubIndex::Failed(string Message,pkgAcquire::MethodConfig * /*Cnf*/)/*{{{*/
 {
    if(Debug)
-      std::clog << "pkgAcqSubIndex failed: " << Desc.URI << std::endl;
+      std::clog << "pkgAcqSubIndex failed: " << Desc.URI << " with " << Message << std::endl;
 
    Complete = false;
    Status = StatDone;
@@ -299,7 +308,7 @@ void pkgAcqSubIndex::Done(string Message,unsigned long long Size,string Md5Hash,
       return;
    }
 
-   // sucess in downloading the index
+   // success in downloading the index
    // rename the index
    if(Debug)
       std::clog << "Renaming: " << DestFile << " -> " << FinalFile << std::endl;
@@ -327,7 +336,7 @@ bool pkgAcqSubIndex::ParseIndex(string const &IndexFile)		/*{{{*/
 									/*}}}*/
 // AcqDiffIndex::AcqDiffIndex - Constructor				/*{{{*/
 // ---------------------------------------------------------------------
-/* Get the DiffIndex file first and see if there are patches availabe 
+/* Get the DiffIndex file first and see if there are patches available
  * If so, create a pkgAcqIndexDiffs fetcher that will get and apply the
  * patches. If anything goes wrong in that process, it will fall back to
  * the original packages file
@@ -369,10 +378,10 @@ pkgAcqDiffIndex::pkgAcqDiffIndex(pkgAcquire *Owner,
       return;
    }
 
-   if(Debug) 
-      std::clog << "pkgAcqIndexDiffs::pkgAcqIndexDiffs(): " 
-		<< CurrentPackagesFile << std::endl;
-   
+   if(Debug)
+      std::clog << "pkgAcqDiffIndex::pkgAcqDiffIndex(): "
+	 << CurrentPackagesFile << std::endl;
+
    QueueURI(Desc);
 
 }
@@ -398,8 +407,8 @@ string pkgAcqDiffIndex::Custom600Headers()
 bool pkgAcqDiffIndex::ParseDiffIndex(string IndexDiffFile)		/*{{{*/
 {
    if(Debug)
-      std::clog << "pkgAcqIndexDiffs::ParseIndexDiff() " << IndexDiffFile 
-		<< std::endl;
+      std::clog << "pkgAcqDiffIndex::ParseIndexDiff() " << IndexDiffFile
+	 << std::endl;
 
    pkgTagSection Tags;
    string ServerSha1;
@@ -426,16 +435,18 @@ bool pkgAcqDiffIndex::ParseDiffIndex(string IndexDiffFile)		/*{{{*/
       SHA1.AddFD(fd);
       string const local_sha1 = SHA1.Result();
 
-      if(local_sha1 == ServerSha1) 
+      if(local_sha1 == ServerSha1)
       {
-	 // we have the same sha1 as the server
+	 // we have the same sha1 as the server so we are done here
 	 if(Debug)
 	    std::clog << "Package file is up-to-date" << std::endl;
-	 // set found to true, this will queue a pkgAcqIndexDiffs with
-	 // a empty availabe_patches
-	 found = true;
-      } 
-      else 
+	 // list cleanup needs to know that this file as well as the already
+	 // present index is ours, so we create an empty diff to save it for us
+	 new pkgAcqIndexDiffs(Owner, RealURI, Description, Desc.ShortDesc,
+	       ExpectedHash, ServerSha1, available_patches);
+	 return true;
+      }
+      else
       {
 	 if(Debug)
 	    std::clog << "SHA1-Current: " << ServerSha1 << " and we start at "<< fd.Name() << " " << fd.Size() << " " << local_sha1 << std::endl;
@@ -460,7 +471,7 @@ bool pkgAcqDiffIndex::ParseDiffIndex(string IndexDiffFile)		/*{{{*/
 	 if (available_patches.empty() == false)
 	 {
 	    // patching with too many files is rather slow compared to a fast download
-	    unsigned long const fileLimit = _config->FindI("Acquire::PDiffs::FileLimit", 20);
+	    unsigned long const fileLimit = _config->FindI("Acquire::PDiffs::FileLimit", 0);
 	    if (fileLimit != 0 && fileLimit < available_patches.size())
 	    {
 	       if (Debug)
@@ -496,14 +507,37 @@ bool pkgAcqDiffIndex::ParseDiffIndex(string IndexDiffFile)		/*{{{*/
       }
 
       // we have something, queue the next diff
-      if(found) 
+      if(found)
       {
 	 // queue the diffs
 	 string::size_type const last_space = Description.rfind(" ");
 	 if(last_space != string::npos)
 	    Description.erase(last_space, Description.size()-last_space);
-	 new pkgAcqIndexDiffs(Owner, RealURI, Description, Desc.ShortDesc,
-			      ExpectedHash, ServerSha1, available_patches);
+
+	 /* decide if we should download patches one by one or in one go:
+	    The first is good if the server merges patches, but many don't so client
+	    based merging can be attempt in which case the second is better.
+	    "bad things" will happen if patches are merged on the server,
+	    but client side merging is attempt as well */
+	 bool pdiff_merge = _config->FindB("Acquire::PDiffs::Merge", true);
+	 if (pdiff_merge == true)
+	 {
+	    // reprepro adds this flag if it has merged patches on the server
+	    std::string const precedence = Tags.FindS("X-Patch-Precedence");
+	    pdiff_merge = (precedence != "merged");
+	 }
+
+	 if (pdiff_merge == false)
+	    new pkgAcqIndexDiffs(Owner, RealURI, Description, Desc.ShortDesc,
+		  ExpectedHash, ServerSha1, available_patches);
+	 else
+	 {
+	    std::vector<pkgAcqIndexMergeDiffs*> *diffs = new std::vector<pkgAcqIndexMergeDiffs*>(available_patches.size());
+	    for(size_t i = 0; i < available_patches.size(); ++i)
+	       (*diffs)[i] = new pkgAcqIndexMergeDiffs(Owner, RealURI, Description, Desc.ShortDesc, ExpectedHash,
+		     available_patches[i], diffs);
+	 }
+
 	 Complete = false;
 	 Status = StatDone;
 	 Dequeue();
@@ -519,11 +553,11 @@ bool pkgAcqDiffIndex::ParseDiffIndex(string IndexDiffFile)		/*{{{*/
    return false;
 }
 									/*}}}*/
-void pkgAcqDiffIndex::Failed(string Message,pkgAcquire::MethodConfig *Cnf)	/*{{{*/
+void pkgAcqDiffIndex::Failed(string Message,pkgAcquire::MethodConfig * /*Cnf*/)/*{{{*/
 {
    if(Debug)
-      std::clog << "pkgAcqDiffIndex failed: " << Desc.URI << std::endl
-		<< "Falling back to normal index file aquire" << std::endl;
+      std::clog << "pkgAcqDiffIndex failed: " << Desc.URI << " with " << Message << std::endl
+		<< "Falling back to normal index file acquire" << std::endl;
 
    new pkgAcqIndex(Owner, RealURI, Description, Desc.ShortDesc, 
 		   ExpectedHash);
@@ -544,7 +578,7 @@ void pkgAcqDiffIndex::Done(string Message,unsigned long long Size,string Md5Hash
    string FinalFile;
    FinalFile = _config->FindDir("Dir::State::lists")+URItoFileName(RealURI);
 
-   // sucess in downloading the index
+   // success in downloading the index
    // rename the index
    FinalFile += string(".IndexDiff");
    if(Debug)
@@ -599,11 +633,11 @@ pkgAcqIndexDiffs::pkgAcqIndexDiffs(pkgAcquire *Owner,
    }
 }
 									/*}}}*/
-void pkgAcqIndexDiffs::Failed(string Message,pkgAcquire::MethodConfig *Cnf)	/*{{{*/
+void pkgAcqIndexDiffs::Failed(string Message,pkgAcquire::MethodConfig * /*Cnf*/)/*{{{*/
 {
    if(Debug)
-      std::clog << "pkgAcqIndexDiffs failed: " << Desc.URI << std::endl
-		<< "Falling back to normal index file aquire" << std::endl;
+      std::clog << "pkgAcqIndexDiffs failed: " << Desc.URI << " with " << Message << std::endl
+		<< "Falling back to normal index file acquire" << std::endl;
    new pkgAcqIndex(Owner, RealURI, Description,Desc.ShortDesc, 
 		   ExpectedHash);
    Finish();
@@ -684,7 +718,7 @@ bool pkgAcqIndexDiffs::QueueNextDiff()					/*{{{*/
    }
 
    // queue the right diff
-   Desc.URI = string(RealURI) + ".diff/" + available_patches[0].file + ".gz";
+   Desc.URI = RealURI + ".diff/" + available_patches[0].file + ".gz";
    Desc.Description = Description + " " + available_patches[0].file + string(".pdiff");
    DestFile = _config->FindDir("Dir::State::lists") + "partial/";
    DestFile += URItoFileName(RealURI + ".diff/" + available_patches[0].file);
@@ -708,7 +742,7 @@ void pkgAcqIndexDiffs::Done(string Message,unsigned long long Size,string Md5Has
    string FinalFile;
    FinalFile = _config->FindDir("Dir::State::lists")+URItoFileName(RealURI);
 
-   // sucess in downloading a diff, enter ApplyDiff state
+   // success in downloading a diff, enter ApplyDiff state
    if(State == StateFetchDiff)
    {
 
@@ -732,6 +766,7 @@ void pkgAcqIndexDiffs::Done(string Message,unsigned long long Size,string Md5Has
    {
       // remove the just applied patch
       available_patches.erase(available_patches.begin());
+      unlink((FinalFile + ".ed").c_str());
 
       // move into place
       if(Debug) 
@@ -752,6 +787,131 @@ void pkgAcqIndexDiffs::Done(string Message,unsigned long long Size,string Md5Has
    }
 }
 									/*}}}*/
+// AcqIndexMergeDiffs::AcqIndexMergeDiffs - Constructor			/*{{{*/
+pkgAcqIndexMergeDiffs::pkgAcqIndexMergeDiffs(pkgAcquire *Owner,
+				   string const &URI, string const &URIDesc,
+				   string const &ShortDesc, HashString const &ExpectedHash,
+				   DiffInfo const &patch,
+				   std::vector<pkgAcqIndexMergeDiffs*> const * const allPatches)
+   : Item(Owner), RealURI(URI), ExpectedHash(ExpectedHash),
+     patch(patch),allPatches(allPatches), State(StateFetchDiff)
+{
+
+   DestFile = _config->FindDir("Dir::State::lists") + "partial/";
+   DestFile += URItoFileName(URI);
+
+   Debug = _config->FindB("Debug::pkgAcquire::Diffs",false);
+
+   Description = URIDesc;
+   Desc.Owner = this;
+   Desc.ShortDesc = ShortDesc;
+
+   Desc.URI = RealURI + ".diff/" + patch.file + ".gz";
+   Desc.Description = Description + " " + patch.file + string(".pdiff");
+   DestFile = _config->FindDir("Dir::State::lists") + "partial/";
+   DestFile += URItoFileName(RealURI + ".diff/" + patch.file);
+
+   if(Debug)
+      std::clog << "pkgAcqIndexMergeDiffs: " << Desc.URI << std::endl;
+
+   QueueURI(Desc);
+}
+									/*}}}*/
+void pkgAcqIndexMergeDiffs::Failed(string Message,pkgAcquire::MethodConfig * /*Cnf*/)/*{{{*/
+{
+   if(Debug)
+      std::clog << "pkgAcqIndexMergeDiffs failed: " << Desc.URI << " with " << Message << std::endl;
+   Complete = false;
+   Status = StatDone;
+   Dequeue();
+
+   // check if we are the first to fail, otherwise we are done here
+   State = StateDoneDiff;
+   for (std::vector<pkgAcqIndexMergeDiffs *>::const_iterator I = allPatches->begin();
+	 I != allPatches->end(); ++I)
+      if ((*I)->State == StateErrorDiff)
+	 return;
+
+   // first failure means we should fallback
+   State = StateErrorDiff;
+   std::clog << "Falling back to normal index file acquire" << std::endl;
+   new pkgAcqIndex(Owner, RealURI, Description,Desc.ShortDesc,
+		   ExpectedHash);
+}
+									/*}}}*/
+void pkgAcqIndexMergeDiffs::Done(string Message,unsigned long long Size,string Md5Hash,	/*{{{*/
+			    pkgAcquire::MethodConfig *Cnf)
+{
+   if(Debug)
+      std::clog << "pkgAcqIndexMergeDiffs::Done(): " << Desc.URI << std::endl;
+
+   Item::Done(Message,Size,Md5Hash,Cnf);
+
+   string const FinalFile = _config->FindDir("Dir::State::lists") + URItoFileName(RealURI);
+
+   if (State == StateFetchDiff)
+   {
+      // rred expects the patch as $FinalFile.ed.$patchname.gz
+      Rename(DestFile, FinalFile + ".ed." + patch.file + ".gz");
+
+      // check if this is the last completed diff
+      State = StateDoneDiff;
+      for (std::vector<pkgAcqIndexMergeDiffs *>::const_iterator I = allPatches->begin();
+	    I != allPatches->end(); ++I)
+	 if ((*I)->State != StateDoneDiff)
+	 {
+	    if(Debug)
+	       std::clog << "Not the last done diff in the batch: " << Desc.URI << std::endl;
+	    return;
+	 }
+
+      // this is the last completed diff, so we are ready to apply now
+      State = StateApplyDiff;
+
+      if(Debug)
+	 std::clog << "Sending to rred method: " << FinalFile << std::endl;
+
+      Local = true;
+      Desc.URI = "rred:" + FinalFile;
+      QueueURI(Desc);
+      Mode = "rred";
+      return;
+   }
+   // success in download/apply all diffs, clean up
+   else if (State == StateApplyDiff)
+   {
+      // see if we really got the expected file
+      if(!ExpectedHash.empty() && !ExpectedHash.VerifyFile(DestFile))
+      {
+	 RenameOnError(HashSumMismatch);
+	 return;
+      }
+
+      // move the result into place
+      if(Debug)
+	 std::clog << "Moving patched file in place: " << std::endl
+		   << DestFile << " -> " << FinalFile << std::endl;
+      Rename(DestFile, FinalFile);
+      chmod(FinalFile.c_str(), 0644);
+
+      // otherwise lists cleanup will eat the file
+      DestFile = FinalFile;
+
+      // ensure the ed's are gone regardless of list-cleanup
+      for (std::vector<pkgAcqIndexMergeDiffs *>::const_iterator I = allPatches->begin();
+	    I != allPatches->end(); ++I)
+      {
+	    std::string patch = FinalFile + ".ed." + (*I)->patch.file + ".gz";
+	    unlink(patch.c_str());
+      }
+
+      // all set and done
+      Complete = true;
+      if(Debug)
+	 std::clog << "allDone: " << DestFile << "\n" << std::endl;
+   }
+}
+									/*}}}*/
 // AcqIndex::AcqIndex - Constructor					/*{{{*/
 // ---------------------------------------------------------------------
 /* The package file is added to the queue and a second class is 
@@ -1089,7 +1249,7 @@ pkgAcqMetaSig::pkgAcqMetaSig(pkgAcquire *Owner,				/*{{{*/
    if (RealFileExists(Final) == true)
    {
       // File was already in place.  It needs to be re-downloaded/verified
-      // because Release might have changed, we do give it a differnt
+      // because Release might have changed, we do give it a different
       // name than DestFile because otherwise the http method will
       // send If-Range requests and there are too many broken servers
       // out there that do not understand them
@@ -1407,7 +1567,7 @@ void pkgAcqMetaIndex::QueueIndexes(bool verify)				/*{{{*/
 	 {
 	    std::vector<std::string> types = APT::Configuration::getCompressionTypes();
 	    for (std::vector<std::string>::const_iterator t = types.begin(); t != types.end(); ++t)
-	       if (MetaIndexParser->Exists(string((*Target)->MetaKey).append(".").append(*t)) == true)
+	       if (MetaIndexParser->Exists((*Target)->MetaKey + "." + *t) == true)
 	       {
 		  compressedAvailable = true;
 		  break;
@@ -1445,7 +1605,7 @@ void pkgAcqMetaIndex::QueueIndexes(bool verify)				/*{{{*/
 	 else if (transInRelease == false || Record != NULL || compressedAvailable == true)
 	 {
 	    if (_config->FindB("Acquire::PDiffs",true) == true && transInRelease == true &&
-		MetaIndexParser->Exists(string((*Target)->MetaKey).append(".diff/Index")) == true)
+		MetaIndexParser->Exists((*Target)->MetaKey + ".diff/Index") == true)
 	       new pkgAcqDiffIndex(Owner, (*Target)->URI, (*Target)->Description,
 				   (*Target)->ShortDesc, ExpectedIndexHash);
 	    else
@@ -1459,7 +1619,7 @@ void pkgAcqMetaIndex::QueueIndexes(bool verify)				/*{{{*/
          in the Meta-Index file. Ideal would be if pkgAcqDiffIndex would test this
          instead, but passing the required info to it is to much hassle */
       if(_config->FindB("Acquire::PDiffs",true) == true && (verify == false ||
-	  MetaIndexParser->Exists(string((*Target)->MetaKey).append(".diff/Index")) == true))
+	  MetaIndexParser->Exists((*Target)->MetaKey + ".diff/Index") == true))
 	 new pkgAcqDiffIndex(Owner, (*Target)->URI, (*Target)->Description,
 			     (*Target)->ShortDesc, ExpectedIndexHash);
       else
@@ -1484,7 +1644,7 @@ bool pkgAcqMetaIndex::VerifyVendor(string Message)			/*{{{*/
       missingkeys += (Fingerprint);
    }
    if(!missingkeys.empty())
-      _error->Warning("%s", string(msg+missingkeys).c_str());
+      _error->Warning("%s", (msg + missingkeys).c_str());
 
    string Transformed = MetaIndexParser->GetExpectedDist();
 
@@ -1547,7 +1707,7 @@ bool pkgAcqMetaIndex::VerifyVendor(string Message)			/*{{{*/
 // pkgAcqMetaIndex::Failed - no Release file present or no signature file present	/*{{{*/
 // ---------------------------------------------------------------------
 /* */
-void pkgAcqMetaIndex::Failed(string Message,pkgAcquire::MethodConfig *Cnf)
+void pkgAcqMetaIndex::Failed(string Message,pkgAcquire::MethodConfig * /*Cnf*/)
 {
    if (AuthPass == true)
    {
@@ -1705,7 +1865,7 @@ pkgAcqArchive::pkgAcqArchive(pkgAcquire *Owner,pkgSourceList *Sources,
       _error->Error(_("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)"),
-		    Version.ParentPkg().Name());
+		    Version.ParentPkg().FullName().c_str());
       return;
    }
    
@@ -1833,7 +1993,7 @@ bool pkgAcqArchive::QueueNext()
       Desc.URI = Index->ArchiveURI(PkgFile);
       Desc.Description = Index->ArchiveInfo(Version);
       Desc.Owner = this;
-      Desc.ShortDesc = Version.ParentPkg().Name();
+      Desc.ShortDesc = Version.ParentPkg().FullName(true);
 
       // See if we already have the file. (Legacy filenames)
       FileSize = Version->Size;
@@ -1870,7 +2030,7 @@ bool pkgAcqArchive::QueueNext()
 	    return true;
 	 }
 	 
-	 /* Hmm, we have a file and its size does not match, this shouldnt
+	 /* Hmm, we have a file and its size does not match, this shouldn't
 	    happen.. */
 	 unlink(FinalFile.c_str());
       }
@@ -1900,10 +2060,6 @@ bool pkgAcqArchive::QueueNext()
 
       // Create the item
       Local = false;
-      Desc.URI = Index->ArchiveURI(PkgFile);
-      Desc.Description = Index->ArchiveInfo(Version);
-      Desc.Owner = this;
-      Desc.ShortDesc = Version.ParentPkg().Name();
       QueueURI(Desc);
 
       ++Vf;
@@ -2002,7 +2158,7 @@ void pkgAcqArchive::Failed(string Message,pkgAcquire::MethodConfig *Cnf)
 									/*}}}*/
 // AcqArchive::IsTrusted - Determine whether this archive comes from a trusted source /*{{{*/
 // ---------------------------------------------------------------------
-bool pkgAcqArchive::IsTrusted()
+APT_PURE bool pkgAcqArchive::IsTrusted()
 {
    return Trusted;
 }
@@ -2050,7 +2206,7 @@ pkgAcqFile::pkgAcqFile(pkgAcquire *Owner,string URI,string Hash,
    if (stat(DestFile.c_str(),&Buf) == 0)
    {
       // Hmm, the partial file is too big, erase it
-      if ((unsigned long long)Buf.st_size > Size)
+      if ((Size > 0) && (unsigned long long)Buf.st_size > Size)
 	 unlink(DestFile.c_str());
       else
 	 PartialSize = Buf.st_size;

+ 111 - 8
apt-pkg/acquire-item.h

@@ -24,6 +24,10 @@
 #include <apt-pkg/hashes.h>
 #include <apt-pkg/weakptr.h>
 #include <apt-pkg/pkgcache.h>
+#include <apt-pkg/cacheiterators.h>
+
+#include <string>
+#include <vector>
 
 #ifndef APT_8_CLEANER_HEADERS
 #include <apt-pkg/indexfile.h>
@@ -64,7 +68,7 @@ class pkgAcquire::Item : public WeakPointable
 
    /** \brief Insert this item into its owner's queue.
     *
-    *  \param ItemDesc Metadata about this item (its URI and
+    *  \param Item Metadata about this item (its URI and
     *  description).
     */
    inline void QueueURI(ItemDesc &Item)
@@ -79,7 +83,7 @@ class pkgAcquire::Item : public WeakPointable
     *
     *  \param From The file to be renamed.
     *
-    *  \param To The new name of #From.  If #To exists it will be
+    *  \param To The new name of \a From.  If \a To exists it will be
     *  overwritten.
     */
    void Rename(std::string From,std::string To);
@@ -115,7 +119,7 @@ class pkgAcquire::Item : public WeakPointable
      } Status;
 
    /** \brief Contains a textual description of the error encountered
-    *  if #Status is #StatError or #StatAuthError.
+    *  if #ItemState is #StatError or #StatAuthError.
     */
    std::string ErrorText;
 
@@ -293,7 +297,6 @@ class pkgAcquire::Item : public WeakPointable
    /** \brief Rename failed file and set error
     *
     * \param state respresenting the error we encountered
-    * \param errorMsg a message describing the error
     */
    bool RenameOnError(RenameOnErrorState const state);
 };
@@ -429,7 +432,105 @@ class pkgAcqDiffIndex : public pkgAcquire::Item
 		   std::string ShortDesc, HashString ExpectedHash);
 };
 									/*}}}*/
-/** \brief An item that is responsible for fetching all the patches	{{{
+/** \brief An item that is responsible for fetching client-merge patches {{{
+ *  that need to be applied to a given package index file.
+ *
+ *  Instead of downloading and applying each patch one by one like its
+ *  sister #pkgAcqIndexDiffs this class will download all patches at once
+ *  and call rred with all the patches downloaded once. Rred will then
+ *  merge and apply them in one go, which should be a lot faster – but is
+ *  incompatible with server-based merges of patches like reprepro can do.
+ *
+ *  \sa pkgAcqDiffIndex, pkgAcqIndex
+ */
+class pkgAcqIndexMergeDiffs : public pkgAcquire::Item
+{
+   protected:
+
+   /** \brief If \b true, debugging output will be written to
+    *  std::clog.
+    */
+   bool Debug;
+
+   /** \brief description of the item that is currently being
+    *  downloaded.
+    */
+   pkgAcquire::ItemDesc Desc;
+
+   /** \brief URI of the package index file that is being
+    *  reconstructed.
+    */
+   std::string RealURI;
+
+   /** \brief HashSum of the package index file that is being
+    *  reconstructed.
+    */
+   HashString ExpectedHash;
+
+   /** \brief description of the file being downloaded. */
+   std::string Description;
+
+   /** \brief information about the current patch */
+   struct DiffInfo const patch;
+
+   /** \brief list of all download items for the patches */
+   std::vector<pkgAcqIndexMergeDiffs*> const * const allPatches;
+
+   /** The current status of this patch. */
+   enum DiffState
+   {
+      /** \brief The diff is currently being fetched. */
+      StateFetchDiff,
+
+      /** \brief The diff is currently being applied. */
+      StateApplyDiff,
+
+      /** \brief the work with this diff is done */
+      StateDoneDiff,
+
+      /** \brief something bad happened and fallback was triggered */
+      StateErrorDiff
+   } State;
+
+   public:
+   /** \brief Called when the patch file failed to be downloaded.
+    *
+    *  This method will fall back to downloading the whole index file
+    *  outright; its arguments are ignored.
+    */
+   virtual void Failed(std::string Message,pkgAcquire::MethodConfig *Cnf);
+
+   virtual void Done(std::string Message,unsigned long long Size,std::string Md5Hash,
+		     pkgAcquire::MethodConfig *Cnf);
+   virtual std::string DescURI() {return RealURI + "Index";};
+
+   /** \brief Create an index merge-diff item.
+    *
+    *  \param Owner The pkgAcquire object that owns this item.
+    *
+    *  \param URI The URI of the package index file being
+    *  reconstructed.
+    *
+    *  \param URIDesc A long description of this item.
+    *
+    *  \param ShortDesc A brief description of this item.
+    *
+    *  \param ExpectedHash The expected md5sum of the completely
+    *  reconstructed package index file; the index file will be tested
+    *  against this value when it is entirely reconstructed.
+    *
+    *  \param patch contains infos about the patch this item is supposed
+    *  to download which were read from the index
+    *
+    *  \param allPatches contains all related items so that each item can
+    *  check if it was the last one to complete the download step
+    */
+   pkgAcqIndexMergeDiffs(pkgAcquire *Owner,std::string const &URI,std::string const &URIDesc,
+		    std::string const &ShortDesc, HashString const &ExpectedHash,
+		    DiffInfo const &patch, std::vector<pkgAcqIndexMergeDiffs*> const * const allPatches);
+};
+									/*}}}*/
+/** \brief An item that is responsible for fetching server-merge patches {{{
  *  that need to be applied to a given package index file.
  *
  *  After downloading and applying a single patch, this item will
@@ -538,7 +639,7 @@ class pkgAcqIndexDiffs : public pkgAcquire::Item
    /** \brief Create an index diff item.
     *
     *  After filling in its basic fields, this invokes Finish(true) if
-    *  #diffs is empty, or QueueNextDiff() otherwise.
+    *  \a diffs is empty, or QueueNextDiff() otherwise.
     *
     *  \param Owner The pkgAcquire object that owns this item.
     *
@@ -553,6 +654,8 @@ class pkgAcqIndexDiffs : public pkgAcquire::Item
     *  reconstructed package index file; the index file will be tested
     *  against this value when it is entirely reconstructed.
     *
+    *  \param ServerSha1 is the sha1sum of the current file on the server
+    *
     *  \param diffs The remaining diffs from the index of diffs.  They
     *  should be ordered so that each diff appears before any diff
     *  that depends on it.
@@ -1064,8 +1167,8 @@ class pkgAcqFile : public pkgAcquire::Item
     *  \param IsIndexFile The file is considered a IndexFile and cache-control
     *                     headers like "cache-control: max-age=0" are send
     *
-    * If DestFilename is empty, download to DestDir/<basename> if
-    * DestDir is non-empty, $CWD/<basename> otherwise.  If
+    * If DestFilename is empty, download to DestDir/\<basename\> if
+    * DestDir is non-empty, $CWD/\<basename\> otherwise.  If
     * DestFilename is NOT empty, DestDir is ignored and DestFilename
     * is the absolute name to which the file should be downloaded.
     */

+ 10 - 2
apt-pkg/acquire-method.cc

@@ -23,10 +23,18 @@
 #include <apt-pkg/strutl.h>
 #include <apt-pkg/fileutl.h>
 #include <apt-pkg/hashes.h>
-
+#include <apt-pkg/md5.h>
+#include <apt-pkg/sha1.h>
+#include <apt-pkg/sha2.h>
+
+#include <stdarg.h>
+#include <stdlib.h>
+#include <string.h>
+#include <unistd.h>
+#include <string>
+#include <vector>
 #include <iostream>
 #include <stdio.h>
-#include <sys/signal.h>
 									/*}}}*/
 
 using namespace std;

+ 4 - 1
apt-pkg/acquire-method.h

@@ -20,7 +20,10 @@
 #ifndef PKGLIB_ACQUIRE_METHOD_H
 #define PKGLIB_ACQUIRE_METHOD_H
 
+#include <apt-pkg/macros.h>
+
 #include <stdarg.h>
+#include <time.h>
 
 #include <string>
 #include <vector>
@@ -106,7 +109,7 @@ class pkgAcqMethod
    virtual ~pkgAcqMethod() {};
 
    private:
-   void Dequeue();
+   APT_HIDDEN void Dequeue();
 };
 
 /** @} */

+ 12 - 4
apt-pkg/acquire-worker.cc

@@ -14,20 +14,23 @@
 // Include Files							/*{{{*/
 #include <config.h>
 
+#include <apt-pkg/acquire.h>
 #include <apt-pkg/acquire-worker.h>
 #include <apt-pkg/acquire-item.h>
 #include <apt-pkg/configuration.h>
 #include <apt-pkg/error.h>
 #include <apt-pkg/fileutl.h>
 #include <apt-pkg/strutl.h>
+#include <apt-pkg/hashes.h>
 
+#include <string>
+#include <vector>
 #include <iostream>
 #include <sstream>
-#include <fstream>
 
 #include <sys/stat.h>
+#include <stdlib.h>
 #include <unistd.h>
-#include <fcntl.h>
 #include <signal.h>
 #include <stdio.h>
 #include <errno.h>
@@ -109,7 +112,12 @@ bool pkgAcquire::Worker::Start()
    // Get the method path
    string Method = _config->FindDir("Dir::Bin::Methods") + Access;
    if (FileExists(Method) == false)
-      return _error->Error(_("The method driver %s could not be found."),Method.c_str());
+   {
+      _error->Error(_("The method driver %s could not be found."),Method.c_str());
+      if (Access == "https")
+	 _error->Notice(_("Is the package %s installed?"), "apt-transport-https");
+      return false;
+   }
 
    if (Debug == true)
       clog << "Starting method '" << Method << '\'' << endl;
@@ -563,7 +571,7 @@ bool pkgAcquire::Worker::InFdReady()
 									/*}}}*/
 // Worker::MethodFailure - Called when the method fails			/*{{{*/
 // ---------------------------------------------------------------------
-/* This is called when the method is belived to have failed, probably because
+/* This is called when the method is believed to have failed, probably because
    read returned -1. */
 bool pkgAcquire::Worker::MethodFailure()
 {

+ 5 - 2
apt-pkg/acquire-worker.h

@@ -22,6 +22,9 @@
 #include <apt-pkg/acquire.h>
 #include <apt-pkg/weakptr.h>
 
+#include <sys/types.h>
+#include <string>
+#include <vector>
 
 /** \brief A fetch subprocess.
  *
@@ -136,8 +139,8 @@ class pkgAcquire::Worker : public WeakPointable
    
    /** \brief Retrieve any available messages from the subprocess.
     *
-    *  The messages are retrieved as in ::ReadMessages(), and
-    *  MessageFailure() is invoked if an error occurs; in particular,
+    *  The messages are retrieved as in \link strutl.h ReadMessages()\endlink, and
+    *  #MethodFailure() is invoked if an error occurs; in particular,
     *  if the pipe to the subprocess dies unexpectedly while a message
     *  is being read.
     *

+ 13 - 7
apt-pkg/acquire.cc

@@ -5,9 +5,9 @@
 
    Acquire - File Acquiration
 
-   The core element for the schedual system is the concept of a named
+   The core element for the schedule system is the concept of a named
    queue. Each queue is unique and each queue has a name derived from the
-   URI. The degree of paralization can be controled by how the queue
+   URI. The degree of paralization can be controlled by how the queue
    name is derived from the URI.
    
    ##################################################################### */
@@ -23,12 +23,18 @@
 #include <apt-pkg/strutl.h>
 #include <apt-pkg/fileutl.h>
 
+#include <string>
+#include <vector>
 #include <iostream>
 #include <sstream>
 #include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <unistd.h>
 
 #include <dirent.h>
 #include <sys/time.h>
+#include <sys/select.h>
 #include <errno.h>
 
 #include <apti18n.h>
@@ -175,7 +181,7 @@ void pkgAcquire::Add(Worker *Work)
 // ---------------------------------------------------------------------
 /* A worker has died. This can not be done while the select loop is running
    as it would require that RunFds could handling a changing list state and
-   it cant.. */
+   it can't.. */
 void pkgAcquire::Remove(Worker *Work)
 {
    if (Running == true)
@@ -468,7 +474,7 @@ void pkgAcquire::Bump()
 pkgAcquire::Worker *pkgAcquire::WorkerStep(Worker *I)
 {
    return I->NextAcquire;
-};
+}
 									/*}}}*/
 // Acquire::Clean - Cleans a directory					/*{{{*/
 // ---------------------------------------------------------------------
@@ -520,7 +526,7 @@ bool pkgAcquire::Clean(string Dir)
 // Acquire::TotalNeeded - Number of bytes to fetch			/*{{{*/
 // ---------------------------------------------------------------------
 /* This is the total number of bytes needed */
-unsigned long long pkgAcquire::TotalNeeded()
+APT_PURE unsigned long long pkgAcquire::TotalNeeded()
 {
    unsigned long long Total = 0;
    for (ItemCIterator I = ItemsBegin(); I != ItemsEnd(); ++I)
@@ -531,7 +537,7 @@ unsigned long long pkgAcquire::TotalNeeded()
 // Acquire::FetchNeeded - Number of bytes needed to get			/*{{{*/
 // ---------------------------------------------------------------------
 /* This is the number of bytes that is not local */
-unsigned long long pkgAcquire::FetchNeeded()
+APT_PURE unsigned long long pkgAcquire::FetchNeeded()
 {
    unsigned long long Total = 0;
    for (ItemCIterator I = ItemsBegin(); I != ItemsEnd(); ++I)
@@ -543,7 +549,7 @@ unsigned long long pkgAcquire::FetchNeeded()
 // Acquire::PartialPresent - Number of partial bytes we already have	/*{{{*/
 // ---------------------------------------------------------------------
 /* This is the number of bytes that is not local */
-unsigned long long pkgAcquire::PartialPresent()
+APT_PURE unsigned long long pkgAcquire::PartialPresent()
 {
   unsigned long long Total = 0;
    for (ItemCIterator I = ItemsBegin(); I != ItemsEnd(); ++I)

+ 10 - 5
apt-pkg/acquire.h

@@ -72,8 +72,13 @@
 #include <vector>
 #include <string>
 
+#include <stddef.h>
 #include <sys/time.h>
+#include <sys/select.h>
+
+#ifndef APT_10_CLEANER_HEADERS
 #include <unistd.h>
+#endif
 
 #ifndef APT_8_CLEANER_HEADERS
 using std::vector;
@@ -282,18 +287,18 @@ class pkgAcquire
     */
    void Shutdown();
    
-   /** \brief Get the first #Worker object.
+   /** \brief Get the first Worker object.
     *
     *  \return the first active worker in this download process.
     */
    inline Worker *WorkersBegin() {return Workers;};
 
-   /** \brief Advance to the next #Worker object.
+   /** \brief Advance to the next Worker object.
     *
     *  \return the worker immediately following I, or \b NULL if none
     *  exists.
     */
-   Worker *WorkerStep(Worker *I);
+   Worker *WorkerStep(Worker *I) APT_PURE;
 
    /** \brief Get the head of the list of items. */
    inline ItemIterator ItemsBegin() {return Items.begin();};
@@ -353,7 +358,7 @@ class pkgAcquire
    void SetLog(pkgAcquireStatus *Progress) { Log = Progress; }
 
    /** \brief Construct a new pkgAcquire. */
-   pkgAcquire(pkgAcquireStatus *Log) __deprecated;
+   pkgAcquire(pkgAcquireStatus *Log) APT_DEPRECATED;
    pkgAcquire();
 
    /** \brief Destroy this pkgAcquire object.
@@ -476,7 +481,7 @@ class pkgAcquire::Queue
     *  \return the first item in the queue whose URI is #URI and that
     *  is being downloaded by #Owner.
     */
-   QItem *FindItem(std::string URI,pkgAcquire::Worker *Owner);
+   QItem *FindItem(std::string URI,pkgAcquire::Worker *Owner) APT_PURE;
 
    /** Presumably this should start downloading an item?
     *

+ 47 - 32
apt-pkg/algorithms.cc

@@ -19,19 +19,18 @@
 #include <apt-pkg/algorithms.h>
 #include <apt-pkg/error.h>
 #include <apt-pkg/configuration.h>
-#include <apt-pkg/version.h>
 #include <apt-pkg/sptr.h>
-#include <apt-pkg/acquire-item.h>
 #include <apt-pkg/edsp.h>
-#include <apt-pkg/sourcelist.h>
-#include <apt-pkg/fileutl.h>
 #include <apt-pkg/progress.h>
+#include <apt-pkg/depcache.h>
+#include <apt-pkg/packagemanager.h>
+#include <apt-pkg/pkgcache.h>
+#include <apt-pkg/cacheiterators.h>
 
-#include <sys/types.h>
+#include <string.h>
+#include <string>
 #include <cstdlib>
-#include <algorithm>
 #include <iostream>
-#include <stdio.h>
 
 #include <apti18n.h>
 									/*}}}*/
@@ -394,8 +393,18 @@ void pkgProblemResolver::MakeScores()
    };
    int PrioEssentials = _config->FindI("pkgProblemResolver::Scores::Essentials",100);
    int PrioInstalledAndNotObsolete = _config->FindI("pkgProblemResolver::Scores::NotObsolete",1);
-   int PrioDepends = _config->FindI("pkgProblemResolver::Scores::Depends",1);
-   int PrioRecommends = _config->FindI("pkgProblemResolver::Scores::Recommends",1);
+   int DepMap[] = {
+      0,
+      _config->FindI("pkgProblemResolver::Scores::Depends",1),
+      _config->FindI("pkgProblemResolver::Scores::PreDepends",1),
+      _config->FindI("pkgProblemResolver::Scores::Suggests",0),
+      _config->FindI("pkgProblemResolver::Scores::Recommends",1),
+      _config->FindI("pkgProblemResolver::Scores::Conflicts",-1),
+      _config->FindI("pkgProblemResolver::Scores::Replaces",0),
+      _config->FindI("pkgProblemResolver::Scores::Obsoletes",0),
+      _config->FindI("pkgProblemResolver::Scores::Breaks",-1),
+      _config->FindI("pkgProblemResolver::Scores::Enhances",0)
+   };
    int AddProtected = _config->FindI("pkgProblemResolver::Scores::AddProtected",10000);
    int AddEssential = _config->FindI("pkgProblemResolver::Scores::AddEssential",5000);
 
@@ -408,8 +417,15 @@ void pkgProblemResolver::MakeScores()
          << "  Extra => " << PrioMap[pkgCache::State::Extra] << endl
          << "  Essentials => " << PrioEssentials << endl
          << "  InstalledAndNotObsolete => " << PrioInstalledAndNotObsolete << endl
-         << "  Depends => " << PrioDepends << endl
-         << "  Recommends => " << PrioRecommends << endl
+         << "  Pre-Depends => " << DepMap[pkgCache::Dep::PreDepends] << endl
+         << "  Depends => " << DepMap[pkgCache::Dep::Depends] << endl
+         << "  Recommends => " << DepMap[pkgCache::Dep::Recommends] << endl
+         << "  Suggests => " << DepMap[pkgCache::Dep::Suggests] << endl
+         << "  Conflicts => " << DepMap[pkgCache::Dep::Conflicts] << endl
+         << "  Breaks => " << DepMap[pkgCache::Dep::DpkgBreaks] << endl
+         << "  Replaces => " << DepMap[pkgCache::Dep::Replaces] << endl
+         << "  Obsoletes => " << DepMap[pkgCache::Dep::Obsoletes] << endl
+         << "  Enhances => " << DepMap[pkgCache::Dep::Enhances] << endl
          << "  AddProtected => " << AddProtected << endl
          << "  AddEssential => " << AddEssential << endl;
 
@@ -424,7 +440,7 @@ void pkgProblemResolver::MakeScores()
       /* This is arbitrary, it should be high enough to elevate an
          essantial package above most other packages but low enough
 	 to allow an obsolete essential packages to be removed by
-	 a conflicts on a powerfull normal package (ie libc6) */
+	 a conflicts on a powerful normal package (ie libc6) */
       if ((I->Flags & pkgCache::Flag::Essential) == pkgCache::Flag::Essential
 	  || (I->Flags & pkgCache::Flag::Important) == pkgCache::Flag::Important)
 	 Score += PrioEssentials;
@@ -439,24 +455,23 @@ void pkgProblemResolver::MakeScores()
       */
       if (I->CurrentVer != 0 && Cache[I].CandidateVer != 0 && Cache[I].CandidateVerIter(Cache).Downloadable())
 	 Score += PrioInstalledAndNotObsolete;
-   }
 
-   // Now that we have the base scores we go and propogate dependencies
-   for (pkgCache::PkgIterator I = Cache.PkgBegin(); I.end() == false; ++I)
-   {
-      if (Cache[I].InstallVer == 0)
-	 continue;
-      
+      // propagate score points along dependencies
       for (pkgCache::DepIterator D = Cache[I].InstVerIter(Cache).DependsList(); D.end() == false; ++D)
       {
-	 if (D->Type == pkgCache::Dep::Depends || 
-	     D->Type == pkgCache::Dep::PreDepends)
-	    Scores[D.TargetPkg()->ID] += PrioDepends;
-	 else if (D->Type == pkgCache::Dep::Recommends)
-	    Scores[D.TargetPkg()->ID] += PrioRecommends;
+	 if (DepMap[D->Type] == 0)
+	    continue;
+	 pkgCache::PkgIterator const T = D.TargetPkg();
+	 if (D->Version != 0)
+	 {
+	    pkgCache::VerIterator const IV = Cache[T].InstVerIter(Cache);
+	    if (IV.end() == true || D.IsSatisfied(IV) != D.IsNegative())
+	       continue;
+	 }
+	 Scores[T->ID] += DepMap[D->Type];
       }
-   }   
-   
+   }
+
    // Copy the scores to advoid additive looping
    SPtrArray<int> OldScores = new int[Size];
    memcpy(OldScores,Scores,sizeof(*Scores)*Size);
@@ -485,7 +500,7 @@ void pkgProblemResolver::MakeScores()
       }      
    }
 
-   /* Now we propogate along provides. This makes the packages that 
+   /* Now we propagate along provides. This makes the packages that
       provide important packages extremely important */
    for (pkgCache::PkgIterator I = Cache.PkgBegin(); I.end() == false; ++I)
    {
@@ -640,7 +655,7 @@ bool pkgProblemResolver::Resolve(bool BrokenFix)
    adjusting the package will inflict. 
       
    It goes from highest score to lowest and corrects all of the breaks by 
-   keeping or removing the dependant packages. If that fails then it removes
+   keeping or removing the dependent packages. If that fails then it removes
    the package itself and goes on. The routine should be able to intelligently
    go from any broken state to a fixed state. 
  
@@ -830,7 +845,7 @@ bool pkgProblemResolver::ResolveInternal(bool const BrokenFix)
 
 	    /* Look across the version list. If there are no possible
 	       targets then we keep the package and bail. This is necessary
-	       if a package has a dep on another package that cant be found */
+	       if a package has a dep on another package that can't be found */
 	    SPtrArray<pkgCache::Version *> VList = Start.AllTargets();
 	    if (*VList == 0 && (Flags[I->ID] & Protected) != Protected &&
 		Start.IsNegative() == false &&
@@ -869,8 +884,8 @@ bool pkgProblemResolver::ResolveInternal(bool const BrokenFix)
                }
 
 	       if (Debug == true)
-		  clog << "  Considering " << Pkg.FullName(false) << ' ' << (int)Scores[Pkg->ID] <<
-		  " as a solution to " << I.FullName(false) << ' ' << (int)Scores[I->ID] << endl;
+		  clog << "  Considering " << Pkg.FullName(false) << ' ' << Scores[Pkg->ID] <<
+		  " as a solution to " << I.FullName(false) << ' ' << Scores[I->ID] << endl;
 
 	       /* Try to fix the package under consideration rather than
 	          fiddle with the VList package */
@@ -1183,7 +1198,7 @@ bool pkgProblemResolver::ResolveByKeepInternal()
          continue;
 
       /* Keep the package. If this works then great, otherwise we have
-       	 to be significantly more agressive and manipulate its dependencies */
+	 to be significantly more aggressive and manipulate its dependencies */
       if ((Flags[I->ID] & Protected) == 0)
       {
 	 if (Debug == true)

+ 7 - 4
apt-pkg/algorithms.h

@@ -10,7 +10,7 @@
    see all of the effects of an upgrade run.
 
    pkgDistUpgrade computes an upgrade that causes as many packages as
-   possible to move to the newest verison.
+   possible to move to the newest version.
    
    pkgApplyStatus sets the target state based on the content of the status
    field in the status file. It is important to get proper crash recovery.
@@ -33,8 +33,11 @@
 
 #include <apt-pkg/packagemanager.h>
 #include <apt-pkg/depcache.h>
+#include <apt-pkg/pkgcache.h>
+#include <apt-pkg/cacheiterators.h>
 
 #include <iostream>
+#include <string>
 
 #include <apt-pkg/macros.h>
 
@@ -44,7 +47,7 @@ using std::ostream;
 #endif
 
 #ifndef APT_9_CLEANER_HEADERS
-// include pkg{DistUpgrade,AllUpgrade,MiniizeUpgrade} here for compatiblity
+// include pkg{DistUpgrade,AllUpgrade,MiniizeUpgrade} here for compatibility
 #include <apt-pkg/upgrade.h>
 #include <apt-pkg/update.h>
 #endif
@@ -111,7 +114,7 @@ class pkgProblemResolver						/*{{{*/
    
    // Sort stuff
    static pkgProblemResolver *This;
-   static int ScoreSort(const void *a,const void *b);
+   static int ScoreSort(const void *a,const void *b) APT_PURE;
 
    struct PackageKill
    {
@@ -140,7 +143,7 @@ class pkgProblemResolver						/*{{{*/
    // Try to resolve problems only by using keep
    bool ResolveByKeep();
 
-   __deprecated void InstallProtect();
+   APT_DEPRECATED void InstallProtect();
 
    pkgProblemResolver(pkgDepCache *Cache);
    ~pkgProblemResolver();

+ 59 - 72
apt-pkg/aptconfiguration.cc

@@ -17,19 +17,24 @@
 #include <apt-pkg/macros.h>
 #include <apt-pkg/strutl.h>
 
-#include <sys/types.h>
 #include <dirent.h>
 #include <stdio.h>
 #include <fcntl.h>
-
+#include <ctype.h>
+#include <stddef.h>
+#include <stdlib.h>
+#include <string.h>
+#include <unistd.h>
 #include <algorithm>
 #include <string>
 #include <vector>
+
+#include <apti18n.h>
 									/*}}}*/
 namespace APT {
-// getCompressionTypes - Return Vector of usbale compressiontypes	/*{{{*/
+// getCompressionTypes - Return Vector of usable compressiontypes	/*{{{*/
 // ---------------------------------------------------------------------
-/* return a vector of compression types in the prefered order. */
+/* return a vector of compression types in the preferred order. */
 std::vector<std::string>
 const Configuration::getCompressionTypes(bool const &Cached) {
 	static std::vector<std::string> types;
@@ -49,11 +54,6 @@ const Configuration::getCompressionTypes(bool const &Cached) {
 	setDefaultConfigurationForCompressors();
 	std::vector<APT::Configuration::Compressor> const compressors = getCompressors();
 
-	// accept non-list order as override setting for config settings on commandline
-	std::string const overrideOrder = _config->Find("Acquire::CompressionTypes::Order","");
-	if (overrideOrder.empty() == false)
-		types.push_back(overrideOrder);
-
 	// load the order setting into our vector
 	std::vector<std::string> const order = _config->FindVector("Acquire::CompressionTypes::Order");
 	for (std::vector<std::string>::const_iterator o = order.begin();
@@ -109,7 +109,7 @@ const Configuration::getCompressionTypes(bool const &Cached) {
 									/*}}}*/
 // GetLanguages - Return Vector of Language Codes			/*{{{*/
 // ---------------------------------------------------------------------
-/* return a vector of language codes in the prefered order.
+/* return a vector of language codes in the preferred order.
    the special word "environment" will be replaced with the long and the short
    code of the local settings and it will be insured that this will not add
    duplicates. So in an german local the setting "environment, de_DE, en, de"
@@ -141,7 +141,7 @@ std::vector<std::string> const Configuration::getLanguages(bool const &All,
 	// so they will be all included in the Cache.
 	std::vector<string> builtin;
 	DIR *D = opendir(_config->FindDir("Dir::State::lists").c_str());
-	if (D != 0) {
+	if (D != NULL) {
 		builtin.push_back("none");
 		for (struct dirent *Ent = readdir(D); Ent != 0; Ent = readdir(D)) {
 			string const name = SubstVar(Ent->d_name, "%5f", "_");
@@ -166,8 +166,8 @@ std::vector<std::string> const Configuration::getLanguages(bool const &All,
 				continue;
 			builtin.push_back(c);
 		}
+		closedir(D);
 	}
-	closedir(D);
 
 	// FIXME: Remove support for the old APT::Acquire::Translation
 	// it was undocumented and so it should be not very widthly used
@@ -227,61 +227,11 @@ std::vector<std::string> const Configuration::getLanguages(bool const &All,
 			}
 		}
 	} else {
+		// cornercase: LANG=C, so we use only "en" Translation
 		environment.push_back("en");
 	}
 
-	// Support settings like Acquire::Languages=none on the command line to
-	// override the configuration settings vector of languages.
-	string const forceLang = _config->Find("Acquire::Languages","");
-	if (forceLang.empty() == false) {
-		if (forceLang == "none") {
-			codes.clear();
-			allCodes.clear();
-			allCodes.push_back("none");
-		} else {
-			if (forceLang == "environment")
-				codes = environment;
-			else
-				codes.push_back(forceLang);
-			allCodes = codes;
-			for (std::vector<string>::const_iterator b = builtin.begin();
-			     b != builtin.end(); ++b)
-				if (std::find(allCodes.begin(), allCodes.end(), *b) == allCodes.end())
-					allCodes.push_back(*b);
-		}
-		if (All == true)
-			return allCodes;
-		else
-			return codes;
-	}
-
-	// cornercase: LANG=C, so we use only "en" Translation
-	if (envShort == "C") {
-		allCodes = codes = environment;
-		allCodes.insert(allCodes.end(), builtin.begin(), builtin.end());
-		if (All == true)
-			return allCodes;
-		else
-			return codes;
-	}
-
-	std::vector<string> const lang = _config->FindVector("Acquire::Languages");
-	// the default setting -> "environment, en"
-	if (lang.empty() == true) {
-		codes = environment;
-		if (envShort != "en")
-			codes.push_back("en");
-		allCodes = codes;
-		for (std::vector<string>::const_iterator b = builtin.begin();
-		     b != builtin.end(); ++b)
-			if (std::find(allCodes.begin(), allCodes.end(), *b) == allCodes.end())
-				allCodes.push_back(*b);
-		if (All == true)
-			return allCodes;
-		else
-			return codes;
-	}
-
+	std::vector<string> const lang = _config->FindVector("Acquire::Languages", "environment,en");
 	// the configs define the order, so add the environment
 	// then needed and ensure the codes are not listed twice.
 	bool noneSeen = false;
@@ -308,10 +258,15 @@ std::vector<std::string> const Configuration::getLanguages(bool const &All,
 		allCodes.push_back(*l);
 	}
 
-	for (std::vector<string>::const_iterator b = builtin.begin();
-	     b != builtin.end(); ++b)
-		if (std::find(allCodes.begin(), allCodes.end(), *b) == allCodes.end())
-			allCodes.push_back(*b);
+	if (allCodes.empty() == false) {
+		for (std::vector<string>::const_iterator b = builtin.begin();
+		     b != builtin.end(); ++b)
+			if (std::find(allCodes.begin(), allCodes.end(), *b) == allCodes.end())
+				allCodes.push_back(*b);
+	} else {
+		// "none" was forced
+		allCodes.push_back("none");
+	}
 
 	if (All == true)
 		return allCodes;
@@ -320,7 +275,7 @@ std::vector<std::string> const Configuration::getLanguages(bool const &All,
 }
 									/*}}}*/
 // checkLanguage - are we interested in the given Language?		/*{{{*/
-bool const Configuration::checkLanguage(std::string Lang, bool const All) {
+bool Configuration::checkLanguage(std::string Lang, bool const All) {
 	// the empty Language is always interesting as it is the original
 	if (Lang.empty() == true)
 		return true;
@@ -330,7 +285,7 @@ bool const Configuration::checkLanguage(std::string Lang, bool const All) {
 	return (std::find(langs.begin(), langs.end(), Lang) != langs.end());
 }
 									/*}}}*/
-// getArchitectures - Return Vector of prefered Architectures		/*{{{*/
+// getArchitectures - Return Vector of preferred Architectures		/*{{{*/
 std::vector<std::string> const Configuration::getArchitectures(bool const &Cached) {
 	using std::string;
 
@@ -440,7 +395,7 @@ std::vector<std::string> const Configuration::getArchitectures(bool const &Cache
 }
 									/*}}}*/
 // checkArchitecture - are we interested in the given Architecture?	/*{{{*/
-bool const Configuration::checkArchitecture(std::string const &Arch) {
+bool Configuration::checkArchitecture(std::string const &Arch) {
 	if (Arch == "all")
 		return true;
 	std::vector<std::string> const archs = getArchitectures(true);
@@ -476,7 +431,7 @@ void Configuration::setDefaultConfigurationForCompressors() {
 	}
 }
 									/*}}}*/
-// getCompressors - Return Vector of usbale compressors			/*{{{*/
+// getCompressors - Return Vector of usealbe compressors		/*{{{*/
 // ---------------------------------------------------------------------
 /* return a vector of compressors used by apt-ftparchive in the
    multicompress functionality or to detect data.tar files */
@@ -507,8 +462,16 @@ const Configuration::getCompressors(bool const Cached) {
 #endif
 	if (_config->Exists("Dir::Bin::xz") == false || FileExists(_config->FindFile("Dir::Bin::xz")) == true)
 		compressors.push_back(Compressor("xz",".xz","xz","-6","-d",4));
+#ifdef HAVE_LZMA
+	else
+		compressors.push_back(Compressor("xz",".xz","false", NULL, NULL, 4));
+#endif
 	if (_config->Exists("Dir::Bin::lzma") == false || FileExists(_config->FindFile("Dir::Bin::lzma")) == true)
 		compressors.push_back(Compressor("lzma",".lzma","lzma","-9","-d",5));
+#ifdef HAVE_LZMA
+	else
+		compressors.push_back(Compressor("lzma",".lzma","false", NULL, NULL, 5));
+#endif
 
 	std::vector<std::string> const comp = _config->FindVector("APT::Compressor");
 	for (std::vector<std::string>::const_iterator c = comp.begin();
@@ -558,4 +521,28 @@ Configuration::Compressor::Compressor(char const *name, char const *extension,
 		UncompressArgs.push_back(uncompressArg);
 }
 									/*}}}*/
+// getBuildProfiles - return a vector of enabled build profiles		/*{{{*/
+std::vector<std::string> const Configuration::getBuildProfiles() {
+	// order is: override value (~= commandline), environment variable, list (~= config file)
+	std::string profiles_env = getenv("DEB_BUILD_PROFILES") == 0 ? "" : getenv("DEB_BUILD_PROFILES");
+	if (profiles_env.empty() == false) {
+		profiles_env = SubstVar(profiles_env, " ", ",");
+		std::string const bp = _config->Find("APT::Build-Profiles");
+		_config->Clear("APT::Build-Profiles");
+		if (bp.empty() == false)
+			_config->Set("APT::Build-Profiles", bp);
+	}
+	return _config->FindVector("APT::Build-Profiles", profiles_env);
+}
+std::string const Configuration::getBuildProfilesString() {
+	std::vector<std::string> profiles = getBuildProfiles();
+	if (profiles.empty() == true)
+		return "";
+	std::vector<std::string>::const_iterator p = profiles.begin();
+	std::string list = *p;
+	for (; p != profiles.end(); ++p)
+	   list.append(",").append(*p);
+	return list;
+}
+									/*}}}*/
 }

+ 12 - 7
apt-pkg/aptconfiguration.h

@@ -37,14 +37,14 @@ public:									/*{{{*/
 	 *  \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 the compression types in the prefered usage order
+	 *  \return a vector of the compression types in the preferred usage order
 	 */
 	std::vector<std::string> static const getCompressionTypes(bool const &Cached = true);
 
 	/** \brief Returns a vector of Language Codes
 	 *
 	 *  Languages can be defined with their two or five chars long code.
-	 *  This methods handles the various ways to set the prefered codes,
+	 *  This methods handles the various ways to set the preferred codes,
 	 *  honors the environment and ensures that the codes are not listed twice.
 	 *
 	 *  The special word "environment" will be replaced with the long and the short
@@ -52,7 +52,7 @@ public:									/*{{{*/
 	 *  duplicates. So in an german local the setting "environment, de_DE, en, de"
 	 *  will result in "de_DE, de, en".
 	 *
-	 *  Another special word is "none" which separates the prefered from all codes
+	 *  Another special word is "none" which separates the preferred from all codes
 	 *  in this setting. So setting and method can be used to get codes the user want
 	 *  to see or to get all language codes APT (should) have Translations available.
 	 *
@@ -62,7 +62,7 @@ public:									/*{{{*/
 	 *  \param Locale don't get the locale from the system but use this one instead
 	 *                this parameter should ony be used for testing purposes.
 	 *
-	 *  \return a vector of (all) Language Codes in the prefered usage order
+	 *  \return a vector of (all) Language Codes in the preferred usage order
 	 */
 	std::vector<std::string> static const getLanguages(bool const &All = false,
 			bool const &Cached = true, char const ** const Locale = 0);
@@ -73,14 +73,14 @@ public:									/*{{{*/
 	 *  \param All defines if we check against all codes or only against used codes
 	 *  \return true if we are interested, false otherwise
 	 */
-	bool static const checkLanguage(std::string Lang, bool const All = false);
+	bool static checkLanguage(std::string Lang, bool const All = false);
 
 	/** \brief Returns a vector of Architectures we support
 	 *
 	 *  \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 Architectures in prefered order
+	 *  \return a vector of Architectures in preferred order
 	 */
 	std::vector<std::string> static const getArchitectures(bool const &Cached = true);
 
@@ -89,7 +89,7 @@ public:									/*{{{*/
 	 *  \param Arch we want to check
 	 *  \return true if we are interested, false otherwise
 	 */
-	bool static const checkArchitecture(std::string const &Arch);
+	bool static checkArchitecture(std::string const &Arch);
 
 	/** \brief Representation of supported compressors */
 	struct Compressor {
@@ -117,6 +117,11 @@ public:									/*{{{*/
 
 	/** \brief Return a vector of extensions supported for data.tar's */
 	std::vector<std::string> static const getCompressorExtensions();
+
+	/** \return Return a vector of enabled build profile specifications */
+	std::vector<std::string> static const getBuildProfiles();
+	/** \return Return a comma-separated list of enabled build profile specifications */
+	std::string static const getBuildProfilesString();
 									/*}}}*/
 	private:							/*{{{*/
 	void static setDefaultConfigurationForCompressors();

+ 10 - 3
apt-pkg/cachefile.cc

@@ -21,9 +21,16 @@
 #include <apt-pkg/configuration.h>
 #include <apt-pkg/policy.h>
 #include <apt-pkg/pkgsystem.h>
-#include <apt-pkg/acquire-item.h>
 #include <apt-pkg/fileutl.h>
 #include <apt-pkg/progress.h>
+#include <apt-pkg/depcache.h>
+#include <apt-pkg/mmap.h>
+#include <apt-pkg/pkgcache.h>
+
+#include <string.h>
+#include <unistd.h>
+#include <string>
+#include <vector>
 
 #include <apti18n.h>
 									/*}}}*/
@@ -99,7 +106,7 @@ bool pkgCacheFile::BuildCaches(OpProgress *Progress, bool WithLock)
 // CacheFile::BuildSourceList - Open and build all relevant sources.list/*{{{*/
 // ---------------------------------------------------------------------
 /* */
-bool pkgCacheFile::BuildSourceList(OpProgress *Progress)
+bool pkgCacheFile::BuildSourceList(OpProgress * /*Progress*/)
 {
    if (SrcList != NULL)
       return true;
@@ -113,7 +120,7 @@ bool pkgCacheFile::BuildSourceList(OpProgress *Progress)
 // CacheFile::BuildPolicy - Open and build all relevant preferences	/*{{{*/
 // ---------------------------------------------------------------------
 /* */
-bool pkgCacheFile::BuildPolicy(OpProgress *Progress)
+bool pkgCacheFile::BuildPolicy(OpProgress * /*Progress*/)
 {
    if (Policy != NULL)
       return true;

+ 7 - 2
apt-pkg/cachefile.h

@@ -17,8 +17,12 @@
 #ifndef PKGLIB_CACHEFILE_H
 #define PKGLIB_CACHEFILE_H
 
+#include <stddef.h>
+
 #include <apt-pkg/depcache.h>
 #include <apt-pkg/macros.h>
+#include <apt-pkg/pkgcache.h>
+#include <apt-pkg/cacheiterators.h>
 
 #ifndef APT_8_CLEANER_HEADERS
 #include <apt-pkg/acquire.h>
@@ -26,6 +30,7 @@
 #include <apt-pkg/sourcelist.h>
 #endif
 
+class MMap;
 class pkgPolicy;
 class pkgSourceList;
 class OpProgress;
@@ -60,13 +65,13 @@ class pkgCacheFile
    inline unsigned char &operator [](pkgCache::DepIterator const &I) {return (*DCache)[I];};
 
    bool BuildCaches(OpProgress *Progress = NULL,bool WithLock = true);
-   __deprecated bool BuildCaches(OpProgress &Progress,bool const &WithLock = true) { return BuildCaches(&Progress, WithLock); };
+   APT_DEPRECATED bool BuildCaches(OpProgress &Progress,bool const &WithLock = true) { return BuildCaches(&Progress, WithLock); };
    bool BuildSourceList(OpProgress *Progress = NULL);
    bool BuildPolicy(OpProgress *Progress = NULL);
    bool BuildDepCache(OpProgress *Progress = NULL);
    bool Open(OpProgress *Progress = NULL, bool WithLock = true);
    inline bool ReadOnlyOpen(OpProgress *Progress = NULL) { return Open(Progress, false); };
-   __deprecated bool Open(OpProgress &Progress,bool const &WithLock = true) { return Open(&Progress, WithLock); };
+   APT_DEPRECATED bool Open(OpProgress &Progress,bool const &WithLock = true) { return Open(&Progress, WithLock); };
    static void RemoveCaches();
    void Close();
 

+ 3 - 1
apt-pkg/cachefilter.cc

@@ -9,10 +9,12 @@
 #include <apt-pkg/cachefilter.h>
 #include <apt-pkg/error.h>
 #include <apt-pkg/pkgcache.h>
+#include <apt-pkg/cacheiterators.h>
 #include <apt-pkg/strutl.h>
+#include <apt-pkg/macros.h>
 
 #include <string>
-
+#include <string.h>
 #include <regex.h>
 #include <fnmatch.h>
 

+ 2 - 1
apt-pkg/cachefilter.h

@@ -7,6 +7,7 @@
 #define APT_CACHEFILTER_H
 // Include Files							/*{{{*/
 #include <apt-pkg/pkgcache.h>
+#include <apt-pkg/cacheiterators.h>
 
 #include <string>
 
@@ -47,7 +48,7 @@ public:
 /** \class PackageArchitectureMatchesSpecification
    \brief matching against architecture specification strings
 
-   The strings are of the format <kernel>-<cpu> where either component,
+   The strings are of the format \<kernel\>-\<cpu\> where either component,
    or the whole string, can be the wildcard "any" as defined in
    debian-policy §11.1 "Architecture specification strings".
 

+ 139 - 134
apt-pkg/cacheiterators.h

@@ -29,7 +29,12 @@
 									/*}}}*/
 #ifndef PKGLIB_CACHEITERATORS_H
 #define PKGLIB_CACHEITERATORS_H
+#include<apt-pkg/pkgcache.h>
+#include<apt-pkg/macros.h>
+
 #include<iterator>
+#include <iosfwd>
+#include <string>
 
 #include<string.h>
 
@@ -46,7 +51,7 @@ template<typename Str, typename Itr> class pkgCache::Iterator :
 	 *  The implementation of this method should be pretty short
 	 *  as it will only return the Pointer into the mmap stored
 	 *  in the owner but the name of this pointer is different for
-	 *  each stucture and we want to abstract here at least for the
+	 *  each structure and we want to abstract here at least for the
 	 *  basic methods from the actual structure.
 	 *  \return Pointer to the first structure of this type
 	 */
@@ -55,36 +60,36 @@ template<typename Str, typename Itr> class pkgCache::Iterator :
 	public:
 	// Iteration
 	virtual void operator ++(int) = 0;
-	virtual void operator ++() = 0; // Should be {operator ++(0);};
-	inline bool end() const {return Owner == 0 || S == OwnerPointer();};
+	virtual void operator ++() = 0; // Should be {operator ++(0);}
+	inline bool end() const {return Owner == 0 || S == OwnerPointer();}
 
 	// Comparison
-	inline bool operator ==(const Itr &B) const {return S == B.S;};
-	inline bool operator !=(const Itr &B) const {return S != B.S;};
+	inline bool operator ==(const Itr &B) const {return S == B.S;}
+	inline bool operator !=(const Itr &B) const {return S != B.S;}
 
 	// Accessors
-	inline Str *operator ->() {return S;};
-	inline Str const *operator ->() const {return S;};
-	inline operator Str *() {return S == OwnerPointer() ? 0 : S;};
-	inline operator Str const *() const {return S == OwnerPointer() ? 0 : S;};
-	inline Str &operator *() {return *S;};
-	inline Str const &operator *() const {return *S;};
-	inline pkgCache *Cache() const {return Owner;};
+	inline Str *operator ->() {return S;}
+	inline Str const *operator ->() const {return S;}
+	inline operator Str *() {return S == OwnerPointer() ? 0 : S;}
+	inline operator Str const *() const {return S == OwnerPointer() ? 0 : S;}
+	inline Str &operator *() {return *S;}
+	inline Str const &operator *() const {return *S;}
+	inline pkgCache *Cache() const {return Owner;}
 
 	// Mixed stuff
-	inline void operator =(const Itr &B) {S = B.S; Owner = B.Owner;};
-	inline bool IsGood() const { return S && Owner && ! end();};
-	inline unsigned long Index() const {return S - OwnerPointer();};
+	inline void operator =(const Itr &B) {S = B.S; Owner = B.Owner;}
+	inline bool IsGood() const { return S && Owner && ! end();}
+	inline unsigned long Index() const {return S - OwnerPointer();}
 
 	void ReMap(void const * const oldMap, void const * const newMap) {
 		if (Owner == 0 || S == 0)
 			return;
-		S += (Str*)(newMap) - (Str*)(oldMap);
+		S += (Str const * const)(newMap) - (Str const * const)(oldMap);
 	}
 
 	// Constructors - look out for the variable assigning
-	inline Iterator() : S(0), Owner(0) {};
-	inline Iterator(pkgCache &Owner,Str *T = 0) : S(T), Owner(&Owner) {};
+	inline Iterator() : S(0), Owner(0) {}
+	inline Iterator(pkgCache &Owner,Str *T = 0) : S(T), Owner(&Owner) {}
 };
 									/*}}}*/
 // Group Iterator							/*{{{*/
@@ -98,19 +103,19 @@ class pkgCache::GrpIterator: public Iterator<Group, GrpIterator> {
 	protected:
 	inline Group* OwnerPointer() const {
 		return (Owner != 0) ? Owner->GrpP : 0;
-	};
+	}
 
 	public:
 	// This constructor is the 'begin' constructor, never use it.
 	inline GrpIterator(pkgCache &Owner) : Iterator<Group, GrpIterator>(Owner), HashIndex(-1) {
 		S = OwnerPointer();
 		operator ++(0);
-	};
+	}
 
 	virtual void operator ++(int);
-	virtual void operator ++() {operator ++(0);};
+	virtual void operator ++() {operator ++(0);}
 
-	inline const char *Name() const {return S->Name == 0?0:Owner->StrP + S->Name;};
+	inline const char *Name() const {return S->Name == 0?0:Owner->StrP + S->Name;}
 	inline PkgIterator PackageList() const;
 	PkgIterator FindPkg(std::string Arch = "any") const;
 	/** \brief find the package with the "best" architecture
@@ -127,8 +132,8 @@ class pkgCache::GrpIterator: public Iterator<Group, GrpIterator> {
 	inline GrpIterator(pkgCache &Owner, Group *Trg) : Iterator<Group, GrpIterator>(Owner, Trg), HashIndex(0) {
 		if (S == 0)
 			S = OwnerPointer();
-	};
-	inline GrpIterator() : Iterator<Group, GrpIterator>(), HashIndex(0) {};
+	}
+	inline GrpIterator() : Iterator<Group, GrpIterator>(), HashIndex(0) {}
 
 };
 									/*}}}*/
@@ -139,35 +144,35 @@ class pkgCache::PkgIterator: public Iterator<Package, PkgIterator> {
 	protected:
 	inline Package* OwnerPointer() const {
 		return (Owner != 0) ? Owner->PkgP : 0;
-	};
+	}
 
 	public:
 	// This constructor is the 'begin' constructor, never use it.
 	inline PkgIterator(pkgCache &Owner) : Iterator<Package, PkgIterator>(Owner), HashIndex(-1) {
 		S = OwnerPointer();
 		operator ++(0);
-	};
+	}
 
 	virtual void operator ++(int);
-	virtual void operator ++() {operator ++(0);};
+	virtual void operator ++() {operator ++(0);}
 
 	enum OkState {NeedsNothing,NeedsUnpack,NeedsConfigure};
 
 	// Accessors
-	inline const char *Name() const {return S->Name == 0?0:Owner->StrP + S->Name;};
-	inline const char *Section() const {return S->Section == 0?0:Owner->StrP + S->Section;};
+	inline const char *Name() const {return S->Name == 0?0:Owner->StrP + S->Name;}
+	inline const char *Section() const {return S->Section == 0?0:Owner->StrP + S->Section;}
 	inline bool Purge() const {return S->CurrentState == pkgCache::State::Purge ||
-		(S->CurrentVer == 0 && S->CurrentState == pkgCache::State::NotInstalled);};
-	inline const char *Arch() const {return S->Arch == 0?0:Owner->StrP + S->Arch;};
-	inline GrpIterator Group() const { return GrpIterator(*Owner, Owner->GrpP + S->Group);};
-
-	inline VerIterator VersionList() const;
-	inline VerIterator CurrentVer() const;
-	inline DepIterator RevDependsList() const;
-	inline PrvIterator ProvidesList() const;
-	OkState State() const;
-	const char *CandVersion() const;
-	const char *CurVersion() const;
+		(S->CurrentVer == 0 && S->CurrentState == pkgCache::State::NotInstalled);}
+	inline const char *Arch() const {return S->Arch == 0?0:Owner->StrP + S->Arch;}
+	inline APT_PURE GrpIterator Group() const { return GrpIterator(*Owner, Owner->GrpP + S->Group);}
+
+	inline VerIterator VersionList() const APT_PURE;
+	inline VerIterator CurrentVer() const APT_PURE;
+	inline DepIterator RevDependsList() const APT_PURE;
+	inline PrvIterator ProvidesList() const APT_PURE;
+	OkState State() const APT_PURE;
+	const char *CandVersion() const APT_PURE;
+	const char *CurVersion() const APT_PURE;
 
 	//Nice printable representation
 	friend std::ostream& operator <<(std::ostream& out, PkgIterator i);
@@ -177,8 +182,8 @@ class pkgCache::PkgIterator: public Iterator<Package, PkgIterator> {
 	inline PkgIterator(pkgCache &Owner,Package *Trg) : Iterator<Package, PkgIterator>(Owner, Trg), HashIndex(0) {
 		if (S == 0)
 			S = OwnerPointer();
-	};
-	inline PkgIterator() : Iterator<Package, PkgIterator>(), HashIndex(0) {};
+	}
+	inline PkgIterator() : Iterator<Package, PkgIterator>(), HashIndex(0) {}
 };
 									/*}}}*/
 // Version Iterator							/*{{{*/
@@ -186,32 +191,32 @@ class pkgCache::VerIterator : public Iterator<Version, VerIterator> {
 	protected:
 	inline Version* OwnerPointer() const {
 		return (Owner != 0) ? Owner->VerP : 0;
-	};
+	}
 
 	public:
 	// Iteration
-	void operator ++(int) {if (S != Owner->VerP) S = Owner->VerP + S->NextVer;};
-	inline void operator ++() {operator ++(0);};
+	void operator ++(int) {if (S != Owner->VerP) S = Owner->VerP + S->NextVer;}
+	inline void operator ++() {operator ++(0);}
 
 	// Comparison
 	int CompareVer(const VerIterator &B) const;
 	/** \brief compares two version and returns if they are similar
 
 	    This method should be used to identify if two pseudo versions are
-	    refering to the same "real" version */
+	    referring to the same "real" version */
 	inline bool SimilarVer(const VerIterator &B) const {
 		return (B.end() == false && S->Hash == B->Hash && strcmp(VerStr(), B.VerStr()) == 0);
-	};
+	}
 
 	// Accessors
-	inline const char *VerStr() const {return S->VerStr == 0?0:Owner->StrP + S->VerStr;};
-	inline const char *Section() const {return S->Section == 0?0:Owner->StrP + S->Section;};
+	inline const char *VerStr() const {return S->VerStr == 0?0:Owner->StrP + S->VerStr;}
+	inline const char *Section() const {return S->Section == 0?0:Owner->StrP + S->Section;}
 	inline const char *Arch() const {
 		if ((S->MultiArch & pkgCache::Version::All) == pkgCache::Version::All)
 			return "all";
 		return S->ParentPkg == 0?0:Owner->StrP + ParentPkg()->Arch;
-	};
-	inline PkgIterator ParentPkg() const {return PkgIterator(*Owner,Owner->PkgP + S->ParentPkg);};
+	}
+	inline PkgIterator ParentPkg() const {return PkgIterator(*Owner,Owner->PkgP + S->ParentPkg);}
 
 	inline DescIterator DescriptionList() const;
 	DescIterator TranslatedDescription() const;
@@ -219,8 +224,8 @@ class pkgCache::VerIterator : public Iterator<Version, VerIterator> {
 	inline PrvIterator ProvidesList() const;
 	inline VerFileIterator FileList() const;
 	bool Downloadable() const;
-	inline const char *PriorityType() const {return Owner->Priority(S->Priority);};
-	const char *MultiArchType() const;
+	inline const char *PriorityType() const {return Owner->Priority(S->Priority);}
+	const char *MultiArchType() const APT_PURE;
 	std::string RelStr() const;
 
 	bool Automatic() const;
@@ -229,8 +234,8 @@ class pkgCache::VerIterator : public Iterator<Version, VerIterator> {
 	inline VerIterator(pkgCache &Owner,Version *Trg = 0) : Iterator<Version, VerIterator>(Owner, Trg) {
 		if (S == 0)
 			S = OwnerPointer();
-	};
-	inline VerIterator() : Iterator<Version, VerIterator>() {};
+	}
+	inline VerIterator() : Iterator<Version, VerIterator>() {}
 };
 									/*}}}*/
 // Description Iterator							/*{{{*/
@@ -238,26 +243,26 @@ class pkgCache::DescIterator : public Iterator<Description, DescIterator> {
 	protected:
 	inline Description* OwnerPointer() const {
 		return (Owner != 0) ? Owner->DescP : 0;
-	};
+	}
 
 	public:
 	// Iteration
-	void operator ++(int) {if (S != Owner->DescP) S = Owner->DescP + S->NextDesc;};
-	inline void operator ++() {operator ++(0);};
+	void operator ++(int) {if (S != Owner->DescP) S = Owner->DescP + S->NextDesc;}
+	inline void operator ++() {operator ++(0);}
 
 	// Comparison
 	int CompareDesc(const DescIterator &B) const;
 
 	// Accessors
-	inline const char *LanguageCode() const {return Owner->StrP + S->language_code;};
-	inline const char *md5() const {return Owner->StrP + S->md5sum;};
+	inline const char *LanguageCode() const {return Owner->StrP + S->language_code;}
+	inline const char *md5() const {return Owner->StrP + S->md5sum;}
 	inline DescFileIterator FileList() const;
 
-	inline DescIterator() : Iterator<Description, DescIterator>() {};
+	inline DescIterator() : Iterator<Description, DescIterator>() {}
 	inline DescIterator(pkgCache &Owner,Description *Trg = 0) : Iterator<Description, DescIterator>(Owner, Trg) {
 		if (S == 0)
 			S = Owner.DescP;
-	};
+	}
 };
 									/*}}}*/
 // Dependency iterator							/*{{{*/
@@ -267,33 +272,33 @@ class pkgCache::DepIterator : public Iterator<Dependency, DepIterator> {
 	protected:
 	inline Dependency* OwnerPointer() const {
 		return (Owner != 0) ? Owner->DepP : 0;
-	};
+	}
 
 	public:
 	// Iteration
 	void operator ++(int) {if (S != Owner->DepP) S = Owner->DepP +
-		(Type == DepVer ? S->NextDepends : S->NextRevDepends);};
-	inline void operator ++() {operator ++(0);};
+		(Type == DepVer ? S->NextDepends : S->NextRevDepends);}
+	inline void operator ++() {operator ++(0);}
 
 	// Accessors
-	inline const char *TargetVer() const {return S->Version == 0?0:Owner->StrP + S->Version;};
-	inline PkgIterator TargetPkg() const {return PkgIterator(*Owner,Owner->PkgP + S->Package);};
-	inline PkgIterator SmartTargetPkg() const {PkgIterator R(*Owner,0);SmartTargetPkg(R);return R;};
-	inline VerIterator ParentVer() const {return VerIterator(*Owner,Owner->VerP + S->ParentVer);};
-	inline PkgIterator ParentPkg() const {return PkgIterator(*Owner,Owner->PkgP + Owner->VerP[S->ParentVer].ParentPkg);};
-	inline bool Reverse() const {return Type == DepRev;};
-	bool IsCritical() const;
-	bool IsNegative() const;
-	bool IsIgnorable(PrvIterator const &Prv) const;
-	bool IsIgnorable(PkgIterator const &Pkg) const;
-	bool IsMultiArchImplicit() const;
-	bool IsSatisfied(VerIterator const &Ver) const;
-	bool IsSatisfied(PrvIterator const &Prv) const;
+	inline const char *TargetVer() const {return S->Version == 0?0:Owner->StrP + S->Version;}
+	inline PkgIterator TargetPkg() const {return PkgIterator(*Owner,Owner->PkgP + S->Package);}
+	inline PkgIterator SmartTargetPkg() const {PkgIterator R(*Owner,0);SmartTargetPkg(R);return R;}
+	inline VerIterator ParentVer() const {return VerIterator(*Owner,Owner->VerP + S->ParentVer);}
+	inline PkgIterator ParentPkg() const {return PkgIterator(*Owner,Owner->PkgP + Owner->VerP[S->ParentVer].ParentPkg);}
+	inline bool Reverse() const {return Type == DepRev;}
+	bool IsCritical() const APT_PURE;
+	bool IsNegative() const APT_PURE;
+	bool IsIgnorable(PrvIterator const &Prv) const APT_PURE;
+	bool IsIgnorable(PkgIterator const &Pkg) const APT_PURE;
+	bool IsMultiArchImplicit() const APT_PURE;
+	bool IsSatisfied(VerIterator const &Ver) const APT_PURE;
+	bool IsSatisfied(PrvIterator const &Prv) const APT_PURE;
 	void GlobOr(DepIterator &Start,DepIterator &End);
 	Version **AllTargets() const;
 	bool SmartTargetPkg(PkgIterator &Result) const;
-	inline const char *CompType() const {return Owner->CompType(S->CompareOp);};
-	inline const char *DepType() const {return Owner->DepType(S->Type);};
+	inline const char *CompType() const {return Owner->CompType(S->CompareOp);}
+	inline const char *DepType() const {return Owner->DepType(S->Type);}
 
 	//Nice printable representation
 	friend std::ostream& operator <<(std::ostream& out, DepIterator D);
@@ -302,13 +307,13 @@ class pkgCache::DepIterator : public Iterator<Dependency, DepIterator> {
 		Iterator<Dependency, DepIterator>(Owner, Trg), Type(DepVer) {
 		if (S == 0)
 			S = Owner.DepP;
-	};
+	}
 	inline DepIterator(pkgCache &Owner, Dependency *Trg, Package*) :
 		Iterator<Dependency, DepIterator>(Owner, Trg), Type(DepRev) {
 		if (S == 0)
 			S = Owner.DepP;
-	};
-	inline DepIterator() : Iterator<Dependency, DepIterator>(), Type(DepVer) {};
+	}
+	inline DepIterator() : Iterator<Dependency, DepIterator>(), Type(DepVer) {}
 };
 									/*}}}*/
 // Provides iterator							/*{{{*/
@@ -318,34 +323,34 @@ class pkgCache::PrvIterator : public Iterator<Provides, PrvIterator> {
 	protected:
 	inline Provides* OwnerPointer() const {
 		return (Owner != 0) ? Owner->ProvideP : 0;
-	};
+	}
 
 	public:
 	// Iteration
 	void operator ++(int) {if (S != Owner->ProvideP) S = Owner->ProvideP +
-		(Type == PrvVer?S->NextPkgProv:S->NextProvides);};
-	inline void operator ++() {operator ++(0);};
+		(Type == PrvVer?S->NextPkgProv:S->NextProvides);}
+	inline void operator ++() {operator ++(0);}
 
 	// Accessors
-	inline const char *Name() const {return Owner->StrP + Owner->PkgP[S->ParentPkg].Name;};
-	inline const char *ProvideVersion() const {return S->ProvideVersion == 0?0:Owner->StrP + S->ProvideVersion;};
-	inline PkgIterator ParentPkg() const {return PkgIterator(*Owner,Owner->PkgP + S->ParentPkg);};
-	inline VerIterator OwnerVer() const {return VerIterator(*Owner,Owner->VerP + S->Version);};
-	inline PkgIterator OwnerPkg() const {return PkgIterator(*Owner,Owner->PkgP + Owner->VerP[S->Version].ParentPkg);};
+	inline const char *Name() const {return Owner->StrP + Owner->PkgP[S->ParentPkg].Name;}
+	inline const char *ProvideVersion() const {return S->ProvideVersion == 0?0:Owner->StrP + S->ProvideVersion;}
+	inline PkgIterator ParentPkg() const {return PkgIterator(*Owner,Owner->PkgP + S->ParentPkg);}
+	inline VerIterator OwnerVer() const {return VerIterator(*Owner,Owner->VerP + S->Version);}
+	inline PkgIterator OwnerPkg() const {return PkgIterator(*Owner,Owner->PkgP + Owner->VerP[S->Version].ParentPkg);}
 
-	bool IsMultiArchImplicit() const;
+	bool IsMultiArchImplicit() const APT_PURE;
 
-	inline PrvIterator() : Iterator<Provides, PrvIterator>(), Type(PrvVer) {};
+	inline PrvIterator() : Iterator<Provides, PrvIterator>(), Type(PrvVer) {}
 	inline PrvIterator(pkgCache &Owner, Provides *Trg, Version*) :
 		Iterator<Provides, PrvIterator>(Owner, Trg), Type(PrvVer) {
 		if (S == 0)
 			S = Owner.ProvideP;
-	};
+	}
 	inline PrvIterator(pkgCache &Owner, Provides *Trg, Package*) :
 		Iterator<Provides, PrvIterator>(Owner, Trg), Type(PrvPkg) {
 		if (S == 0)
 			S = Owner.ProvideP;
-	};
+	}
 };
 									/*}}}*/
 // Package file								/*{{{*/
@@ -353,32 +358,32 @@ class pkgCache::PkgFileIterator : public Iterator<PackageFile, PkgFileIterator>
 	protected:
 	inline PackageFile* OwnerPointer() const {
 		return (Owner != 0) ? Owner->PkgFileP : 0;
-	};
+	}
 
 	public:
 	// Iteration
-	void operator ++(int) {if (S != Owner->PkgFileP) S = Owner->PkgFileP + S->NextFile;};
-	inline void operator ++() {operator ++(0);};
+	void operator ++(int) {if (S != Owner->PkgFileP) S = Owner->PkgFileP + S->NextFile;}
+	inline void operator ++() {operator ++(0);}
 
 	// Accessors
-	inline const char *FileName() const {return S->FileName == 0?0:Owner->StrP + S->FileName;};
-	inline const char *Archive() const {return S->Archive == 0?0:Owner->StrP + S->Archive;};
-	inline const char *Component() const {return S->Component == 0?0:Owner->StrP + S->Component;};
-	inline const char *Version() const {return S->Version == 0?0:Owner->StrP + S->Version;};
-	inline const char *Origin() const {return S->Origin == 0?0:Owner->StrP + S->Origin;};
-	inline const char *Codename() const {return S->Codename ==0?0:Owner->StrP + S->Codename;};
-	inline const char *Label() const {return S->Label == 0?0:Owner->StrP + S->Label;};
-	inline const char *Site() const {return S->Site == 0?0:Owner->StrP + S->Site;};
-	inline const char *Architecture() const {return S->Architecture == 0?0:Owner->StrP + S->Architecture;};
-	inline const char *IndexType() const {return S->IndexType == 0?0:Owner->StrP + S->IndexType;};
+	inline const char *FileName() const {return S->FileName == 0?0:Owner->StrP + S->FileName;}
+	inline const char *Archive() const {return S->Archive == 0?0:Owner->StrP + S->Archive;}
+	inline const char *Component() const {return S->Component == 0?0:Owner->StrP + S->Component;}
+	inline const char *Version() const {return S->Version == 0?0:Owner->StrP + S->Version;}
+	inline const char *Origin() const {return S->Origin == 0?0:Owner->StrP + S->Origin;}
+	inline const char *Codename() const {return S->Codename ==0?0:Owner->StrP + S->Codename;}
+	inline const char *Label() const {return S->Label == 0?0:Owner->StrP + S->Label;}
+	inline const char *Site() const {return S->Site == 0?0:Owner->StrP + S->Site;}
+	inline const char *Architecture() const {return S->Architecture == 0?0:Owner->StrP + S->Architecture;}
+	inline const char *IndexType() const {return S->IndexType == 0?0:Owner->StrP + S->IndexType;}
 
 	bool IsOk();
 	std::string RelStr();
 
 	// Constructors
-	inline PkgFileIterator() : Iterator<PackageFile, PkgFileIterator>() {};
-	inline PkgFileIterator(pkgCache &Owner) : Iterator<PackageFile, PkgFileIterator>(Owner, Owner.PkgFileP) {};
-	inline PkgFileIterator(pkgCache &Owner,PackageFile *Trg) : Iterator<PackageFile, PkgFileIterator>(Owner, Trg) {};
+	inline PkgFileIterator() : Iterator<PackageFile, PkgFileIterator>() {}
+	inline PkgFileIterator(pkgCache &Owner) : Iterator<PackageFile, PkgFileIterator>(Owner, Owner.PkgFileP) {}
+	inline PkgFileIterator(pkgCache &Owner,PackageFile *Trg) : Iterator<PackageFile, PkgFileIterator>(Owner, Trg) {}
 };
 									/*}}}*/
 // Version File								/*{{{*/
@@ -386,18 +391,18 @@ class pkgCache::VerFileIterator : public pkgCache::Iterator<VerFile, VerFileIter
 	protected:
 	inline VerFile* OwnerPointer() const {
 		return (Owner != 0) ? Owner->VerFileP : 0;
-	};
+	}
 
 	public:
 	// Iteration
-	void operator ++(int) {if (S != Owner->VerFileP) S = Owner->VerFileP + S->NextFile;};
-	inline void operator ++() {operator ++(0);};
+	void operator ++(int) {if (S != Owner->VerFileP) S = Owner->VerFileP + S->NextFile;}
+	inline void operator ++() {operator ++(0);}
 
 	// Accessors
-	inline PkgFileIterator File() const {return PkgFileIterator(*Owner,S->File + Owner->PkgFileP);};
+	inline PkgFileIterator File() const {return PkgFileIterator(*Owner,S->File + Owner->PkgFileP);}
 
-	inline VerFileIterator() : Iterator<VerFile, VerFileIterator>() {};
-	inline VerFileIterator(pkgCache &Owner,VerFile *Trg) : Iterator<VerFile, VerFileIterator>(Owner, Trg) {};
+	inline VerFileIterator() : Iterator<VerFile, VerFileIterator>() {}
+	inline VerFileIterator(pkgCache &Owner,VerFile *Trg) : Iterator<VerFile, VerFileIterator>(Owner, Trg) {}
 };
 									/*}}}*/
 // Description File							/*{{{*/
@@ -405,40 +410,40 @@ class pkgCache::DescFileIterator : public Iterator<DescFile, DescFileIterator> {
 	protected:
 	inline DescFile* OwnerPointer() const {
 		return (Owner != 0) ? Owner->DescFileP : 0;
-	};
+	}
 
 	public:
 	// Iteration
-	void operator ++(int) {if (S != Owner->DescFileP) S = Owner->DescFileP + S->NextFile;};
-	inline void operator ++() {operator ++(0);};
+	void operator ++(int) {if (S != Owner->DescFileP) S = Owner->DescFileP + S->NextFile;}
+	inline void operator ++() {operator ++(0);}
 
 	// Accessors
-	inline PkgFileIterator File() const {return PkgFileIterator(*Owner,S->File + Owner->PkgFileP);};
+	inline PkgFileIterator File() const {return PkgFileIterator(*Owner,S->File + Owner->PkgFileP);}
 
-	inline DescFileIterator() : Iterator<DescFile, DescFileIterator>() {};
-	inline DescFileIterator(pkgCache &Owner,DescFile *Trg) : Iterator<DescFile, DescFileIterator>(Owner, Trg) {};
+	inline DescFileIterator() : Iterator<DescFile, DescFileIterator>() {}
+	inline DescFileIterator(pkgCache &Owner,DescFile *Trg) : Iterator<DescFile, DescFileIterator>(Owner, Trg) {}
 };
 									/*}}}*/
-// Inlined Begin functions cant be in the class because of order problems /*{{{*/
+// Inlined Begin functions can't be in the class because of order problems /*{{{*/
 inline pkgCache::PkgIterator pkgCache::GrpIterator::PackageList() const
-       {return PkgIterator(*Owner,Owner->PkgP + S->FirstPackage);};
+       {return PkgIterator(*Owner,Owner->PkgP + S->FirstPackage);}
 inline pkgCache::VerIterator pkgCache::PkgIterator::VersionList() const
-       {return VerIterator(*Owner,Owner->VerP + S->VersionList);};
+       {return VerIterator(*Owner,Owner->VerP + S->VersionList);}
 inline pkgCache::VerIterator pkgCache::PkgIterator::CurrentVer() const
-       {return VerIterator(*Owner,Owner->VerP + S->CurrentVer);};
+       {return VerIterator(*Owner,Owner->VerP + S->CurrentVer);}
 inline pkgCache::DepIterator pkgCache::PkgIterator::RevDependsList() const
-       {return DepIterator(*Owner,Owner->DepP + S->RevDepends,S);};
+       {return DepIterator(*Owner,Owner->DepP + S->RevDepends,S);}
 inline pkgCache::PrvIterator pkgCache::PkgIterator::ProvidesList() const
-       {return PrvIterator(*Owner,Owner->ProvideP + S->ProvidesList,S);};
+       {return PrvIterator(*Owner,Owner->ProvideP + S->ProvidesList,S);}
 inline pkgCache::DescIterator pkgCache::VerIterator::DescriptionList() const
-       {return DescIterator(*Owner,Owner->DescP + S->DescriptionList);};
+       {return DescIterator(*Owner,Owner->DescP + S->DescriptionList);}
 inline pkgCache::PrvIterator pkgCache::VerIterator::ProvidesList() const
-       {return PrvIterator(*Owner,Owner->ProvideP + S->ProvidesList,S);};
+       {return PrvIterator(*Owner,Owner->ProvideP + S->ProvidesList,S);}
 inline pkgCache::DepIterator pkgCache::VerIterator::DependsList() const
-       {return DepIterator(*Owner,Owner->DepP + S->DependsList,S);};
+       {return DepIterator(*Owner,Owner->DepP + S->DependsList,S);}
 inline pkgCache::VerFileIterator pkgCache::VerIterator::FileList() const
-       {return VerFileIterator(*Owner,Owner->VerFileP + S->FileList);};
+       {return VerFileIterator(*Owner,Owner->VerFileP + S->FileList);}
 inline pkgCache::DescFileIterator pkgCache::DescIterator::FileList() const
-       {return DescFileIterator(*Owner,Owner->DescFileP + S->FileList);};
+       {return DescFileIterator(*Owner,Owner->DescFileP + S->FileList);}
 									/*}}}*/
 #endif

+ 54 - 21
apt-pkg/cacheset.cc

@@ -16,14 +16,22 @@
 #include <apt-pkg/cachefilter.h>
 #include <apt-pkg/cacheset.h>
 #include <apt-pkg/error.h>
-#include <apt-pkg/strutl.h>
 #include <apt-pkg/versionmatch.h>
 #include <apt-pkg/pkgrecords.h>
 #include <apt-pkg/policy.h>
-
-#include <vector>
-
+#include <apt-pkg/cacheiterators.h>
+#include <apt-pkg/configuration.h>
+#include <apt-pkg/depcache.h>
+#include <apt-pkg/macros.h>
+#include <apt-pkg/pkgcache.h>
+
+#include <stddef.h>
+#include <stdio.h>
+#include <string.h>
 #include <regex.h>
+#include <list>
+#include <string>
+#include <vector>
 
 #include <apti18n.h>
 									/*}}}*/
@@ -73,6 +81,8 @@ bool PackageContainerInterface::FromTask(PackageContainerInterface * const pci,
 		const char *start, *end;
 		parser.GetRec(start,end);
 		unsigned int const length = end - start;
+		if (unlikely(length == 0))
+		   continue;
 		char buf[length];
 		strncpy(buf, start, length);
 		buf[length-1] = '\0';
@@ -202,12 +212,20 @@ PackageContainerInterface::FromFnmatch(PackageContainerInterface * const pci,
 		}
 
 		pci->insert(Pkg);
+#if (APT_PKG_MAJOR >= 4 && APT_PKG_MINOR >= 13)
+		helper.showFnmatchSelection(Pkg, pattern);
+#else
 		helper.showRegExSelection(Pkg, pattern);
+#endif
 		found = true;
 	}
 
 	if (found == false) {
-		helper.canNotFindRegEx(pci, Cache, pattern);
+#if (APT_PKG_MAJOR >= 4 && APT_PKG_MINOR >= 13)
+		helper.canNotFindFnmatch(pci, Cache, pattern);
+#else
+                helper.canNotFindRegEx(pci, Cache, pattern);
+#endif
 		pci->setConstructor(UNKNOWN);
 		return false;
 	}
@@ -302,7 +320,9 @@ bool PackageContainerInterface::FromString(PackageContainerInterface * const pci
 
 	if (FromGroup(pci, Cache, str, helper) == false &&
 		 FromTask(pci, Cache, str, helper) == false &&
-		 FromFnmatch(pci, Cache, str, helper) == false &&
+#if (APT_PKG_MAJOR >= 4 && APT_PKG_MINOR >= 13)
+		 FromFnmatch(pci, Cache, str, helper) == false)
+#endif
 		 FromRegEx(pci, Cache, str, helper) == false)
 	{
 		helper.canNotFindPackage(pci, Cache, str);
@@ -576,37 +596,43 @@ pkgCache::PkgIterator CacheSetHelper::canNotFindPkgName(pkgCacheFile &Cache,
 }
 									/*}}}*/
 // canNotFindTask - handle the case no package is found for a task	/*{{{*/
-void CacheSetHelper::canNotFindTask(PackageContainerInterface * const pci, pkgCacheFile &Cache, std::string pattern) {
+void CacheSetHelper::canNotFindTask(PackageContainerInterface * const /*pci*/, pkgCacheFile &/*Cache*/, std::string pattern) {
 	if (ShowError == true)
 		_error->Insert(ErrorType, _("Couldn't find task '%s'"), pattern.c_str());
 }
 									/*}}}*/
 // canNotFindRegEx - handle the case no package is found by a regex	/*{{{*/
-void CacheSetHelper::canNotFindRegEx(PackageContainerInterface * const pci, pkgCacheFile &Cache, std::string pattern) {
+void CacheSetHelper::canNotFindRegEx(PackageContainerInterface * const /*pci*/, pkgCacheFile &/*Cache*/, std::string pattern) {
 	if (ShowError == true)
 		_error->Insert(ErrorType, _("Couldn't find any package by regex '%s'"), pattern.c_str());
 }
-									/*}}}*/
+#if (APT_PKG_MAJOR >= 4 && APT_PKG_MINOR >= 13)
+// canNotFindFnmatch - handle the case no package is found by a fnmatch	/*{{{*/
+void CacheSetHelper::canNotFindFnmatch(PackageContainerInterface * const pci, pkgCacheFile &Cache, std::string pattern) {
+	if (ShowError == true)
+		_error->Insert(ErrorType, _("Couldn't find any package by glob '%s'"), pattern.c_str());
+}
+#endif									/*}}}*/
 // canNotFindPackage - handle the case no package is found from a string/*{{{*/
-void CacheSetHelper::canNotFindPackage(PackageContainerInterface * const pci, pkgCacheFile &Cache, std::string const &str) {
+APT_CONST void CacheSetHelper::canNotFindPackage(PackageContainerInterface * const /*pci*/, pkgCacheFile &/*Cache*/, std::string const &/*str*/) {
 }
 									/*}}}*/
 // canNotFindAllVer							/*{{{*/
-void CacheSetHelper::canNotFindAllVer(VersionContainerInterface * const vci, pkgCacheFile &Cache,
+void CacheSetHelper::canNotFindAllVer(VersionContainerInterface * const /*vci*/, pkgCacheFile &/*Cache*/,
 		pkgCache::PkgIterator const &Pkg) {
 	if (ShowError == true)
 		_error->Insert(ErrorType, _("Can't select versions from package '%s' as it is purely virtual"), Pkg.FullName(true).c_str());
 }
 									/*}}}*/
 // canNotFindInstCandVer						/*{{{*/
-void CacheSetHelper::canNotFindInstCandVer(VersionContainerInterface * const vci, pkgCacheFile &Cache,
+void CacheSetHelper::canNotFindInstCandVer(VersionContainerInterface * const /*vci*/, pkgCacheFile &/*Cache*/,
 		pkgCache::PkgIterator const &Pkg) {
 	if (ShowError == true)
 		_error->Insert(ErrorType, _("Can't select installed nor candidate version from package '%s' as it has neither of them"), Pkg.FullName(true).c_str());
 }
 									/*}}}*/
 // canNotFindInstCandVer						/*{{{*/
-void CacheSetHelper::canNotFindCandInstVer(VersionContainerInterface * const vci, pkgCacheFile &Cache,
+void CacheSetHelper::canNotFindCandInstVer(VersionContainerInterface * const /*vci*/, pkgCacheFile &/*Cache*/,
 		pkgCache::PkgIterator const &Pkg) {
 	if (ShowError == true)
 		_error->Insert(ErrorType, _("Can't select installed nor candidate version from package '%s' as it has neither of them"), Pkg.FullName(true).c_str());
@@ -637,20 +663,27 @@ pkgCache::VerIterator CacheSetHelper::canNotFindInstalledVer(pkgCacheFile &Cache
 }
 									/*}}}*/
 // showTaskSelection							/*{{{*/
-void CacheSetHelper::showTaskSelection(pkgCache::PkgIterator const &pkg,
-				       std::string const &pattern) {
+APT_CONST void CacheSetHelper::showTaskSelection(pkgCache::PkgIterator const &/*pkg*/,
+				       std::string const &/*pattern*/) {
 }
 									/*}}}*/
 // showRegExSelection							/*{{{*/
-void CacheSetHelper::showRegExSelection(pkgCache::PkgIterator const &pkg,
-					std::string const &pattern) {
+APT_CONST void CacheSetHelper::showRegExSelection(pkgCache::PkgIterator const &/*pkg*/,
+					std::string const &/*pattern*/) {
+}
+									/*}}}*/
+#if (APT_PKG_MAJOR >= 4 && APT_PKG_MINOR >= 13)
+// showFnmatchSelection							/*{{{*/
+APT_CONST void CacheSetHelper::showFnmatchSelection(pkgCache::PkgIterator const &pkg,
+                                          std::string const &pattern) {
 }
 									/*}}}*/
+#endif
 // showSelectedVersion							/*{{{*/
-void CacheSetHelper::showSelectedVersion(pkgCache::PkgIterator const &Pkg,
-					 pkgCache::VerIterator const Ver,
-					 std::string const &ver,
-					 bool const verIsRel) {
+APT_CONST void CacheSetHelper::showSelectedVersion(pkgCache::PkgIterator const &/*Pkg*/,
+					 pkgCache::VerIterator const /*Ver*/,
+					 std::string const &/*ver*/,
+					 bool const /*verIsRel*/) {
 }
 									/*}}}*/
 }

+ 105 - 91
apt-pkg/cacheset.h

@@ -9,7 +9,6 @@
 #ifndef APT_CACHESET_H
 #define APT_CACHESET_H
 // Include Files							/*{{{*/
-#include <iostream>
 #include <fstream>
 #include <map>
 #include <set>
@@ -17,11 +16,17 @@
 #include <string>
 #include <iterator>
 
+#include <stddef.h>
+
 #include <apt-pkg/error.h>
 #include <apt-pkg/pkgcache.h>
+#include <apt-pkg/cacheiterators.h>
 
 #ifndef APT_8_CLEANER_HEADERS
 #include <apt-pkg/cachefile.h>
+#endif
+#ifndef APT_10_CLEANER_HEADERS
+#include <iostream>
 #endif
 									/*}}}*/
 
@@ -43,16 +48,22 @@ class CacheSetHelper {							/*{{{*/
 public:									/*{{{*/
 	CacheSetHelper(bool const ShowError = true,
 		GlobalError::MsgType ErrorType = GlobalError::ERROR) :
-			ShowError(ShowError), ErrorType(ErrorType) {};
-	virtual ~CacheSetHelper() {};
+			ShowError(ShowError), ErrorType(ErrorType) {}
+	virtual ~CacheSetHelper() {}
 
 	virtual void showTaskSelection(pkgCache::PkgIterator const &pkg, std::string const &pattern);
 	virtual void showRegExSelection(pkgCache::PkgIterator const &pkg, std::string const &pattern);
+#if (APT_PKG_MAJOR >= 4 && APT_PKG_MINOR >= 13)
+	virtual void showFnmatchSelection(pkgCache::PkgIterator const &pkg, std::string const &pattern);
+#endif
 	virtual void showSelectedVersion(pkgCache::PkgIterator const &Pkg, pkgCache::VerIterator const Ver,
 				 std::string const &ver, bool const verIsRel);
 
 	virtual void canNotFindTask(PackageContainerInterface * const pci, pkgCacheFile &Cache, std::string pattern);
 	virtual void canNotFindRegEx(PackageContainerInterface * const pci, pkgCacheFile &Cache, std::string pattern);
+#if (APT_PKG_MAJOR >= 4 && APT_PKG_MINOR >= 13)
+	virtual void canNotFindFnmatch(PackageContainerInterface * const pci, pkgCacheFile &Cache, std::string pattern);
+#endif
 	virtual void canNotFindPackage(PackageContainerInterface * const pci, pkgCacheFile &Cache, std::string const &str);
 
 	virtual void canNotFindAllVer(VersionContainerInterface * const vci, pkgCacheFile &Cache, pkgCache::PkgIterator const &Pkg);
@@ -70,9 +81,9 @@ public:									/*{{{*/
 	virtual pkgCache::VerIterator canNotFindInstalledVer(pkgCacheFile &Cache,
 				pkgCache::PkgIterator const &Pkg);
 
-	bool showErrors() const { return ShowError; };
-	bool showErrors(bool const newValue) { if (ShowError == newValue) return ShowError; else return ((ShowError = newValue) == false); };
-	GlobalError::MsgType errorType() const { return ErrorType; };
+	bool showErrors() const { return ShowError; }
+	bool showErrors(bool const newValue) { if (ShowError == newValue) return ShowError; else return ((ShowError = newValue) == false); }
+	GlobalError::MsgType errorType() const { return ErrorType; }
 	GlobalError::MsgType errorType(GlobalError::MsgType const &newValue)
 	{
 		if (ErrorType == newValue) return ErrorType;
@@ -81,7 +92,7 @@ public:									/*{{{*/
 			ErrorType = newValue;
 			return oldValue;
 		}
-	};
+	}
 
 									/*}}}*/
 protected:
@@ -118,12 +129,12 @@ public:
 		inline pkgCache::PkgIterator::OkState State() const { return getPkg().State(); }
 		inline const char *CandVersion() const { return getPkg().CandVersion(); }
 		inline const char *CurVersion() const { return getPkg().CurVersion(); }
-		inline pkgCache *Cache() const { return getPkg().Cache(); };
-		inline unsigned long Index() const {return getPkg().Index();};
+		inline pkgCache *Cache() const { return getPkg().Cache(); }
+		inline unsigned long Index() const {return getPkg().Index();}
 		// we have only valid iterators here
-		inline bool end() const { return false; };
+		inline bool end() const { return false; }
 
-		inline pkgCache::Package const * operator->() const {return &*getPkg();};
+		inline pkgCache::Package const * operator->() const {return &*getPkg();}
 	};
 									/*}}}*/
 
@@ -148,7 +159,7 @@ public:
 		unsigned short ID;
 		const char * const Alias;
 		Position Pos;
-		Modifier (unsigned short const &id, const char * const alias, Position const &pos) : ID(id), Alias(alias), Pos(pos) {};
+		Modifier (unsigned short const &id, const char * const alias, Position const &pos) : ID(id), Alias(alias), Pos(pos) {}
 	};
 
 	static bool FromModifierCommandLine(unsigned short &modID, PackageContainerInterface * const pci,
@@ -171,12 +182,12 @@ public:									/*{{{*/
 	public:
 		const_iterator(typename Container::const_iterator i) : _iter(i) {}
 		pkgCache::PkgIterator getPkg(void) const { return *_iter; }
-		inline pkgCache::PkgIterator operator*(void) const { return *_iter; };
+		inline pkgCache::PkgIterator operator*(void) const { return *_iter; }
 		operator typename Container::const_iterator(void) const { return _iter; }
 		inline const_iterator& operator++() { ++_iter; return *this; }
 		inline const_iterator operator++(int) { const_iterator tmp(*this); operator++(); return tmp; }
-		inline bool operator!=(const_iterator const &i) const { return _iter != i._iter; };
-		inline bool operator==(const_iterator const &i) const { return _iter == i._iter; };
+		inline bool operator!=(const_iterator const &i) const { return _iter != i._iter; }
+		inline bool operator==(const_iterator const &i) const { return _iter == i._iter; }
 		friend std::ostream& operator<<(std::ostream& out, const_iterator i) { return operator<<(out, *i); }
 	};
 	class iterator : public PackageContainerInterface::const_iterator,
@@ -185,43 +196,43 @@ public:									/*{{{*/
 	public:
 		iterator(typename Container::iterator i) : _iter(i) {}
 		pkgCache::PkgIterator getPkg(void) const { return *_iter; }
-		inline pkgCache::PkgIterator operator*(void) const { return *_iter; };
+		inline pkgCache::PkgIterator operator*(void) const { return *_iter; }
 		operator typename Container::iterator(void) const { return _iter; }
 		operator typename PackageContainer<Container>::const_iterator() { return typename PackageContainer<Container>::const_iterator(_iter); }
 		inline iterator& operator++() { ++_iter; return *this; }
 		inline iterator operator++(int) { iterator tmp(*this); operator++(); return tmp; }
-		inline bool operator!=(iterator const &i) const { return _iter != i._iter; };
-		inline bool operator==(iterator const &i) const { return _iter == i._iter; };
-		inline iterator& operator=(iterator const &i) { _iter = i._iter; return *this; };
-		inline iterator& operator=(typename Container::iterator const &i) { _iter = i; return *this; };
+		inline bool operator!=(iterator const &i) const { return _iter != i._iter; }
+		inline bool operator==(iterator const &i) const { return _iter == i._iter; }
+		inline iterator& operator=(iterator const &i) { _iter = i._iter; return *this; }
+		inline iterator& operator=(typename Container::iterator const &i) { _iter = i; return *this; }
 		friend std::ostream& operator<<(std::ostream& out, iterator i) { return operator<<(out, *i); }
 	};
 									/*}}}*/
 
-	bool insert(pkgCache::PkgIterator const &P) { if (P.end() == true) return false; _cont.insert(P); return true; };
-	template<class Cont> void insert(PackageContainer<Cont> const &pkgcont) { _cont.insert((typename Cont::const_iterator)pkgcont.begin(), (typename Cont::const_iterator)pkgcont.end()); };
-	void insert(const_iterator begin, const_iterator end) { _cont.insert(begin, end); };
+	bool insert(pkgCache::PkgIterator const &P) { if (P.end() == true) return false; _cont.insert(P); return true; }
+	template<class Cont> void insert(PackageContainer<Cont> const &pkgcont) { _cont.insert((typename Cont::const_iterator)pkgcont.begin(), (typename Cont::const_iterator)pkgcont.end()); }
+	void insert(const_iterator begin, const_iterator end) { _cont.insert(begin, end); }
 
-	bool empty() const { return _cont.empty(); };
-	void clear() { return _cont.clear(); };
+	bool empty() const { return _cont.empty(); }
+	void clear() { return _cont.clear(); }
 	//FIXME: on ABI break, replace the first with the second without bool
-	void erase(iterator position) { _cont.erase((typename Container::iterator)position); };
-	iterator& erase(iterator &position, bool) { return position = _cont.erase((typename Container::iterator)position); };
-	size_t erase(const pkgCache::PkgIterator x) { return _cont.erase(x); };
-	void erase(iterator first, iterator last) { _cont.erase(first, last); };
-	size_t size() const { return _cont.size(); };
+	void erase(iterator position) { _cont.erase((typename Container::iterator)position); }
+	iterator& erase(iterator &position, bool) { return position = _cont.erase((typename Container::iterator)position); }
+	size_t erase(const pkgCache::PkgIterator x) { return _cont.erase(x); }
+	void erase(iterator first, iterator last) { _cont.erase(first, last); }
+	size_t size() const { return _cont.size(); }
 
-	const_iterator begin() const { return const_iterator(_cont.begin()); };
-	const_iterator end() const { return const_iterator(_cont.end()); };
-	iterator begin() { return iterator(_cont.begin()); };
-	iterator end() { return iterator(_cont.end()); };
-	const_iterator find(pkgCache::PkgIterator const &P) const { return const_iterator(_cont.find(P)); };
+	const_iterator begin() const { return const_iterator(_cont.begin()); }
+	const_iterator end() const { return const_iterator(_cont.end()); }
+	iterator begin() { return iterator(_cont.begin()); }
+	iterator end() { return iterator(_cont.end()); }
+	const_iterator find(pkgCache::PkgIterator const &P) const { return const_iterator(_cont.find(P)); }
 
-	void setConstructor(Constructor const &by) { ConstructedBy = by; };
-	Constructor getConstructor() const { return ConstructedBy; };
+	void setConstructor(Constructor const &by) { ConstructedBy = by; }
+	Constructor getConstructor() const { return ConstructedBy; }
 
-	PackageContainer() : ConstructedBy(UNKNOWN) {};
-	PackageContainer(Constructor const &by) : ConstructedBy(by) {};
+	PackageContainer() : ConstructedBy(UNKNOWN) {}
+	PackageContainer(Constructor const &by) : ConstructedBy(by) {}
 
 	/** \brief returns all packages in the cache who belong to the given task
 
@@ -359,7 +370,7 @@ private:								/*{{{*/
 template<> template<class Cont> void PackageContainer<std::list<pkgCache::PkgIterator> >::insert(PackageContainer<Cont> const &pkgcont) {
 	for (typename PackageContainer<Cont>::const_iterator p = pkgcont.begin(); p != pkgcont.end(); ++p)
 		_cont.push_back(*p);
-};
+}
 // these two are 'inline' as otherwise the linker has problems with seeing these untemplated
 // specializations again and again - but we need to see them, so that library users can use them
 template<> inline bool PackageContainer<std::list<pkgCache::PkgIterator> >::insert(pkgCache::PkgIterator const &P) {
@@ -367,11 +378,11 @@ template<> inline bool PackageContainer<std::list<pkgCache::PkgIterator> >::inse
 		return false;
 	_cont.push_back(P);
 	return true;
-};
+}
 template<> inline void PackageContainer<std::list<pkgCache::PkgIterator> >::insert(const_iterator begin, const_iterator end) {
 	for (const_iterator p = begin; p != end; ++p)
 		_cont.push_back(*p);
-};
+}
 typedef PackageContainer<std::set<pkgCache::PkgIterator> > PackageSet;
 typedef PackageContainer<std::list<pkgCache::PkgIterator> > PackageList;
 
@@ -386,27 +397,27 @@ public:
 		virtual pkgCache::VerIterator getVer() const = 0;
 		operator pkgCache::VerIterator(void) { return getVer(); }
 
-		inline pkgCache *Cache() const { return getVer().Cache(); };
-		inline unsigned long Index() const {return getVer().Index();};
-		inline int CompareVer(const pkgCache::VerIterator &B) const { return getVer().CompareVer(B); };
-		inline const char *VerStr() const { return getVer().VerStr(); };
-		inline const char *Section() const { return getVer().Section(); };
-		inline const char *Arch() const { return getVer().Arch(); };
-		inline pkgCache::PkgIterator ParentPkg() const { return getVer().ParentPkg(); };
-		inline pkgCache::DescIterator DescriptionList() const { return getVer().DescriptionList(); };
-		inline pkgCache::DescIterator TranslatedDescription() const { return getVer().TranslatedDescription(); };
-		inline pkgCache::DepIterator DependsList() const { return getVer().DependsList(); };
-		inline pkgCache::PrvIterator ProvidesList() const { return getVer().ProvidesList(); };
-		inline pkgCache::VerFileIterator FileList() const { return getVer().FileList(); };
-		inline bool Downloadable() const { return getVer().Downloadable(); };
-		inline const char *PriorityType() const { return getVer().PriorityType(); };
-		inline std::string RelStr() const { return getVer().RelStr(); };
-		inline bool Automatic() const { return getVer().Automatic(); };
-		inline pkgCache::VerFileIterator NewestFile() const { return getVer().NewestFile(); };
+		inline pkgCache *Cache() const { return getVer().Cache(); }
+		inline unsigned long Index() const {return getVer().Index();}
+		inline int CompareVer(const pkgCache::VerIterator &B) const { return getVer().CompareVer(B); }
+		inline const char *VerStr() const { return getVer().VerStr(); }
+		inline const char *Section() const { return getVer().Section(); }
+		inline const char *Arch() const { return getVer().Arch(); }
+		inline pkgCache::PkgIterator ParentPkg() const { return getVer().ParentPkg(); }
+		inline pkgCache::DescIterator DescriptionList() const { return getVer().DescriptionList(); }
+		inline pkgCache::DescIterator TranslatedDescription() const { return getVer().TranslatedDescription(); }
+		inline pkgCache::DepIterator DependsList() const { return getVer().DependsList(); }
+		inline pkgCache::PrvIterator ProvidesList() const { return getVer().ProvidesList(); }
+		inline pkgCache::VerFileIterator FileList() const { return getVer().FileList(); }
+		inline bool Downloadable() const { return getVer().Downloadable(); }
+		inline const char *PriorityType() const { return getVer().PriorityType(); }
+		inline std::string RelStr() const { return getVer().RelStr(); }
+		inline bool Automatic() const { return getVer().Automatic(); }
+		inline pkgCache::VerFileIterator NewestFile() const { return getVer().NewestFile(); }
 		// we have only valid iterators here
-		inline bool end() const { return false; };
+		inline bool end() const { return false; }
 
-		inline pkgCache::Version const * operator->() const { return &*getVer(); };
+		inline pkgCache::Version const * operator->() const { return &*getVer(); }
 	};
 									/*}}}*/
 
@@ -440,7 +451,7 @@ public:
 		Version SelectVersion;
 		Modifier (unsigned short const &id, const char * const alias, Position const &pos,
 			  Version const &select) : ID(id), Alias(alias), Pos(pos),
-			 SelectVersion(select) {};
+			 SelectVersion(select) {}
 	};
 
 	static bool FromCommandLine(VersionContainerInterface * const vci, pkgCacheFile &Cache,
@@ -473,14 +484,16 @@ protected:								/*{{{*/
 	/** \brief returns the candidate version of the package
 
 	    \param Cache to be used to query for information
-	    \param Pkg we want the candidate version from this package */
+	    \param Pkg we want the candidate version from this package
+	    \param helper used in this container instance */
 	static pkgCache::VerIterator getCandidateVer(pkgCacheFile &Cache,
 		pkgCache::PkgIterator const &Pkg, CacheSetHelper &helper);
 
 	/** \brief returns the installed version of the package
 
 	    \param Cache to be used to query for information
-	    \param Pkg we want the installed version from this package */
+	    \param Pkg we want the installed version from this package
+	    \param helper used in this container instance */
 	static pkgCache::VerIterator getInstalledVer(pkgCacheFile &Cache,
 		pkgCache::PkgIterator const &Pkg, CacheSetHelper &helper);
 									/*}}}*/
@@ -501,12 +514,12 @@ public:									/*{{{*/
 	public:
 		const_iterator(typename Container::const_iterator i) : _iter(i) {}
 		pkgCache::VerIterator getVer(void) const { return *_iter; }
-		inline pkgCache::VerIterator operator*(void) const { return *_iter; };
+		inline pkgCache::VerIterator operator*(void) const { return *_iter; }
 		operator typename Container::const_iterator(void) const { return _iter; }
 		inline const_iterator& operator++() { ++_iter; return *this; }
 		inline const_iterator operator++(int) { const_iterator tmp(*this); operator++(); return tmp; }
-		inline bool operator!=(const_iterator const &i) const { return _iter != i._iter; };
-		inline bool operator==(const_iterator const &i) const { return _iter == i._iter; };
+		inline bool operator!=(const_iterator const &i) const { return _iter != i._iter; }
+		inline bool operator==(const_iterator const &i) const { return _iter == i._iter; }
 		friend std::ostream& operator<<(std::ostream& out, const_iterator i) { return operator<<(out, *i); }
 	};
 	class iterator : public VersionContainerInterface::const_iterator,
@@ -515,36 +528,36 @@ public:									/*{{{*/
 	public:
 		iterator(typename Container::iterator i) : _iter(i) {}
 		pkgCache::VerIterator getVer(void) const { return *_iter; }
-		inline pkgCache::VerIterator operator*(void) const { return *_iter; };
+		inline pkgCache::VerIterator operator*(void) const { return *_iter; }
 		operator typename Container::iterator(void) const { return _iter; }
 		operator typename VersionContainer<Container>::const_iterator() { return typename VersionContainer<Container>::const_iterator(_iter); }
 		inline iterator& operator++() { ++_iter; return *this; }
 		inline iterator operator++(int) { iterator tmp(*this); operator++(); return tmp; }
-		inline bool operator!=(iterator const &i) const { return _iter != i._iter; };
-		inline bool operator==(iterator const &i) const { return _iter == i._iter; };
-		inline iterator& operator=(iterator const &i) { _iter = i._iter; return *this; };
-		inline iterator& operator=(typename Container::iterator const &i) { _iter = i; return *this; };
+		inline bool operator!=(iterator const &i) const { return _iter != i._iter; }
+		inline bool operator==(iterator const &i) const { return _iter == i._iter; }
+		inline iterator& operator=(iterator const &i) { _iter = i._iter; return *this; }
+		inline iterator& operator=(typename Container::iterator const &i) { _iter = i; return *this; }
 		friend std::ostream& operator<<(std::ostream& out, iterator i) { return operator<<(out, *i); }
 	};
 									/*}}}*/
 
-	bool insert(pkgCache::VerIterator const &V) { if (V.end() == true) return false; _cont.insert(V); return true; };
-	template<class Cont> void insert(VersionContainer<Cont> const &vercont) { _cont.insert((typename Cont::const_iterator)vercont.begin(), (typename Cont::const_iterator)vercont.end()); };
-	void insert(const_iterator begin, const_iterator end) { _cont.insert(begin, end); };
-	bool empty() const { return _cont.empty(); };
-	void clear() { return _cont.clear(); };
+	bool insert(pkgCache::VerIterator const &V) { if (V.end() == true) return false; _cont.insert(V); return true; }
+	template<class Cont> void insert(VersionContainer<Cont> const &vercont) { _cont.insert((typename Cont::const_iterator)vercont.begin(), (typename Cont::const_iterator)vercont.end()); }
+	void insert(const_iterator begin, const_iterator end) { _cont.insert(begin, end); }
+	bool empty() const { return _cont.empty(); }
+	void clear() { return _cont.clear(); }
 	//FIXME: on ABI break, replace the first with the second without bool
-	void erase(iterator position) { _cont.erase((typename Container::iterator)position); };
-	iterator& erase(iterator &position, bool) { return position = _cont.erase((typename Container::iterator)position); };
-	size_t erase(const pkgCache::VerIterator x) { return _cont.erase(x); };
-	void erase(iterator first, iterator last) { _cont.erase(first, last); };
-	size_t size() const { return _cont.size(); };
-
-	const_iterator begin() const { return const_iterator(_cont.begin()); };
-	const_iterator end() const { return const_iterator(_cont.end()); };
-	iterator begin() { return iterator(_cont.begin()); };
-	iterator end() { return iterator(_cont.end()); };
-	const_iterator find(pkgCache::VerIterator const &V) const { return const_iterator(_cont.find(V)); };
+	void erase(iterator position) { _cont.erase((typename Container::iterator)position); }
+	iterator& erase(iterator &position, bool) { return position = _cont.erase((typename Container::iterator)position); }
+	size_t erase(const pkgCache::VerIterator x) { return _cont.erase(x); }
+	void erase(iterator first, iterator last) { _cont.erase(first, last); }
+	size_t size() const { return _cont.size(); }
+
+	const_iterator begin() const { return const_iterator(_cont.begin()); }
+	const_iterator end() const { return const_iterator(_cont.end()); }
+	iterator begin() { return iterator(_cont.begin()); }
+	iterator end() { return iterator(_cont.end()); }
+	const_iterator find(pkgCache::VerIterator const &V) const { return const_iterator(_cont.find(V)); }
 
 	/** \brief returns all versions specified on the commandline
 
@@ -552,6 +565,7 @@ public:									/*{{{*/
 	    non specifically requested  and executes regex's if needed on names.
 	    \param Cache the packages and versions are in
 	    \param cmdline Command line the versions should be extracted from
+	    \param fallback version specification
 	    \param helper responsible for error and message handling */
 	static VersionContainer FromCommandLine(pkgCacheFile &Cache, const char **cmdline,
 			Version const &fallback, CacheSetHelper &helper) {
@@ -650,7 +664,7 @@ public:									/*{{{*/
 template<> template<class Cont> void VersionContainer<std::list<pkgCache::VerIterator> >::insert(VersionContainer<Cont> const &vercont) {
 	for (typename VersionContainer<Cont>::const_iterator v = vercont.begin(); v != vercont.end(); ++v)
 		_cont.push_back(*v);
-};
+}
 // these two are 'inline' as otherwise the linker has problems with seeing these untemplated
 // specializations again and again - but we need to see them, so that library users can use them
 template<> inline bool VersionContainer<std::list<pkgCache::VerIterator> >::insert(pkgCache::VerIterator const &V) {
@@ -658,11 +672,11 @@ template<> inline bool VersionContainer<std::list<pkgCache::VerIterator> >::inse
 		return false;
 	_cont.push_back(V);
 	return true;
-};
+}
 template<> inline void VersionContainer<std::list<pkgCache::VerIterator> >::insert(const_iterator begin, const_iterator end) {
 	for (const_iterator v = begin; v != end; ++v)
 		_cont.push_back(*v);
-};
+}
 typedef VersionContainer<std::set<pkgCache::VerIterator> > VersionSet;
 typedef VersionContainer<std::list<pkgCache::VerIterator> > VersionList;
 }

+ 94 - 116
apt-pkg/cdrom.cc

@@ -1,28 +1,30 @@
 /*
  */
-#include<config.h>
-
-#include<apt-pkg/init.h>
-#include<apt-pkg/error.h>
-#include<apt-pkg/cdromutl.h>
-#include<apt-pkg/strutl.h>
-#include<apt-pkg/cdrom.h>
-#include<apt-pkg/aptconfiguration.h>
-#include<apt-pkg/configuration.h>
-#include<apt-pkg/fileutl.h>
-
-#include<sstream>
-#include<fstream>
+#include <config.h>
+
+#include <apt-pkg/error.h>
+#include <apt-pkg/cdromutl.h>
+#include <apt-pkg/strutl.h>
+#include <apt-pkg/cdrom.h>
+#include <apt-pkg/aptconfiguration.h>
+#include <apt-pkg/configuration.h>
+#include <apt-pkg/fileutl.h>
+#include <apt-pkg/indexcopy.h>
+
+
+#include <string.h>
+#include <iostream>
+#include <string>
+#include <vector>
+#include <sstream>
+#include <fstream>
 #include <sys/stat.h>
-#include <fcntl.h>
 #include <dirent.h>
 #include <unistd.h>
 #include <stdio.h>
 #include <algorithm>
 #include <dlfcn.h>
 
-#include "indexcopy.h"
-
 #include<apti18n.h>
 
 using namespace std;
@@ -369,7 +371,7 @@ bool pkgCdrom::DropRepeats(vector<string> &List,const char *Name)
 // ---------------------------------------------------------------------
 /* This takes the list of source list expressed entires and collects
    similar ones to form a single entry for each dist */
-void pkgCdrom::ReduceSourcelist(string CD,vector<string> &List)
+void pkgCdrom::ReduceSourcelist(string /*CD*/,vector<string> &List)
 {
    sort(List.begin(),List.end());
    
@@ -440,7 +442,7 @@ bool pkgCdrom::WriteDatabase(Configuration &Cnf)
    Out.close();
 
    if (FileExists(DFile) == true)
-      rename(DFile.c_str(), string(DFile + '~').c_str());
+      rename(DFile.c_str(), (DFile + '~').c_str());
    if (rename(NewFile.c_str(),DFile.c_str()) != 0)
       return _error->Errno("rename","Failed to rename %s.new to %s",
 			   DFile.c_str(),DFile.c_str());
@@ -553,7 +555,7 @@ bool pkgCdrom::WriteSourceList(string Name,vector<string> &List,bool Source)
    
    Out.close();
 
-   rename(File.c_str(),string(File + '~').c_str());
+   rename(File.c_str(), (File + '~').c_str());
    if (rename(NewFile.c_str(),File.c_str()) != 0)
       return _error->Errno("rename","Failed to rename %s.new to %s",
 			   File.c_str(),File.c_str());
@@ -561,45 +563,68 @@ bool pkgCdrom::WriteSourceList(string Name,vector<string> &List,bool Source)
    return true;
 }
 									/*}}}*/
-bool pkgCdrom::Ident(string &ident, pkgCdromStatus *log)		/*{{{*/
+bool pkgCdrom::MountAndIdentCDROM(Configuration &Database, std::string &CDROM, std::string &ident, pkgCdromStatus * const log, bool const interactive)/*{{{*/
 {
-   stringstream msg;
-
    // Startup
-   string CDROM = _config->FindDir("Acquire::cdrom::mount");
+   CDROM = _config->FindDir("Acquire::cdrom::mount");
    if (CDROM[0] == '.')
       CDROM= SafeGetCWD() + '/' + CDROM;
 
    if (log != NULL)
    {
-      msg.str("");
-      ioprintf(msg, _("Using CD-ROM mount point %s\nMounting CD-ROM\n"),
-		      CDROM.c_str());
-      log->Update(msg.str());
+      string msg;
+      log->SetTotal(STEP_LAST);
+      strprintf(msg, _("Using CD-ROM mount point %s\n"), CDROM.c_str());
+      log->Update(msg, STEP_PREPARE);
+   }
+
+   // Unmount the CD and get the user to put in the one they want
+   if (_config->FindB("APT::CDROM::NoMount", false) == false)
+   {
+      if (interactive == true)
+      {
+	 if(log != NULL)
+	    log->Update(_("Unmounting CD-ROM...\n"), STEP_LAST);
+	 UnmountCdrom(CDROM);
+
+	 if(log != NULL)
+	 {
+	    log->Update(_("Waiting for disc...\n"), STEP_WAIT);
+	    if(!log->ChangeCdrom()) {
+	       // user aborted
+	       return false;
+	    }
+	 }
+      }
+
+      // Mount the new CDROM
+      if(log != NULL)
+	 log->Update(_("Mounting CD-ROM...\n"), STEP_MOUNT);
+
+      if (MountCdrom(CDROM) == false)
+	 return _error->Error("Failed to mount the cdrom.");
    }
-   if (MountCdrom(CDROM) == false)
-      return _error->Error("Failed to mount the cdrom.");
 
    // Hash the CD to get an ID
    if (log != NULL)
-      log->Update(_("Identifying.. "));
-   
+      log->Update(_("Identifying... "), STEP_IDENT);
 
    if (IdentCdrom(CDROM,ident) == false)
    {
       ident = "";
+      if (log != NULL)
+	 log->Update("\n");
       return false;
    }
 
    if (log != NULL)
    {
-      msg.str("");
-      ioprintf(msg, "[%s]\n",ident.c_str());
-      log->Update(msg.str());
+      string msg;
+      strprintf(msg, "[%s]\n", ident.c_str());
+      log->Update(msg);
    }
 
    // Read the database
-   Configuration Database;
    string DFile = _config->FindFile("Dir::State::cdroms");
    if (FileExists(DFile) == true)
    {
@@ -607,12 +632,22 @@ bool pkgCdrom::Ident(string &ident, pkgCdromStatus *log)		/*{{{*/
 	 return _error->Error("Unable to read the cdrom database %s",
 			      DFile.c_str());
    }
+   return true;
+}
+									/*}}}*/
+bool pkgCdrom::Ident(string &ident, pkgCdromStatus *log)		/*{{{*/
+{
+   Configuration Database;
+   std::string CDROM;
+   if (MountAndIdentCDROM(Database, CDROM, ident, log, false) == false)
+      return false;
+
    if (log != NULL)
    {
-      msg.str("");
-      ioprintf(msg, _("Stored label: %s\n"),
-      Database.Find("CD::"+ident).c_str());
-      log->Update(msg.str());
+      string msg;
+      strprintf(msg, _("Stored label: %s\n"),
+	    Database.Find("CD::"+ident).c_str());
+      log->Update(msg);
    }
 
    // Unmount and finish
@@ -628,70 +663,13 @@ bool pkgCdrom::Ident(string &ident, pkgCdromStatus *log)		/*{{{*/
 									/*}}}*/
 bool pkgCdrom::Add(pkgCdromStatus *log)					/*{{{*/
 {
-   stringstream msg;
-
-   // Startup
-   string CDROM = _config->FindDir("Acquire::cdrom::mount");
-   if (CDROM[0] == '.')
-      CDROM= SafeGetCWD() + '/' + CDROM;
-   
-   if(log != NULL)
-   {
-      log->SetTotal(STEP_LAST);
-      msg.str("");
-      ioprintf(msg, _("Using CD-ROM mount point %s\n"), CDROM.c_str());
-      log->Update(msg.str(), STEP_PREPARE);
-   }
-
-   // Read the database
    Configuration Database;
-   string DFile = _config->FindFile("Dir::State::cdroms");
-   if (FileExists(DFile) == true)
-   {
-      if (ReadConfigFile(Database,DFile) == false) 
-	 return _error->Error("Unable to read the cdrom database %s",
-			      DFile.c_str());
-   }
-   
-   // Unmount the CD and get the user to put in the one they want
-   if (_config->FindB("APT::CDROM::NoMount",false) == false)
-   {
-      if(log != NULL)
-	 log->Update(_("Unmounting CD-ROM\n"), STEP_UNMOUNT);
-      UnmountCdrom(CDROM);
-
-      if(log != NULL)
-      {
-	 log->Update(_("Waiting for disc...\n"), STEP_WAIT);
-	 if(!log->ChangeCdrom()) {
-	    // user aborted
-	    return false; 
-	 }
-      }
-
-      // Mount the new CDROM
-      if(log != NULL)
-	 log->Update(_("Mounting CD-ROM...\n"), STEP_MOUNT);
-
-      if (MountCdrom(CDROM) == false)
-	 return _error->Error("Failed to mount the cdrom.");
-   }
-   
-   // Hash the CD to get an ID
-   if(log != NULL)
-      log->Update(_("Identifying.. "), STEP_IDENT);
-   string ID;
-   if (IdentCdrom(CDROM,ID) == false)
-   {
-      if (log != NULL)
-	 log->Update("\n");
+   std::string ID, CDROM;
+   if (MountAndIdentCDROM(Database, CDROM, ID, log, true) == false)
       return false;
-   }
+
    if(log != NULL)
-   {
-      log->Update("["+ID+"]\n");
-      log->Update(_("Scanning disc for index files..\n"),STEP_SCAN);
-   }
+      log->Update(_("Scanning disc for index files...\n"),STEP_SCAN);
 
    // Get the CD structure
    vector<string> List;
@@ -740,12 +718,12 @@ bool pkgCdrom::Add(pkgCdromStatus *log)					/*{{{*/
    if (_config->FindB("APT::CDROM::DropTranslation", true) == true)
       DropTranslation(TransList);
    if(log != NULL) {
-      msg.str("");
-      ioprintf(msg, _("Found %zu package indexes, %zu source indexes, "
+      string msg;
+      strprintf(msg, _("Found %zu package indexes, %zu source indexes, "
 		      "%zu translation indexes and %zu signatures\n"), 
 	       List.size(), SourceList.size(), TransList.size(),
 	       SigList.size());
-      log->Update(msg.str(), STEP_SCAN);
+      log->Update(msg, STEP_SCAN);
    }
 
    if (List.empty() == true && SourceList.empty() == true) 
@@ -764,7 +742,7 @@ bool pkgCdrom::Add(pkgCdromStatus *log)					/*{{{*/
       if (InfoDir.empty() == false &&
 	  FileExists(InfoDir + "/info") == true)
       {
-	 ifstream F(string(InfoDir + "/info").c_str());
+	 ifstream F((InfoDir + "/info").c_str());
 	 if (!F == 0)
 	    getline(F,Name);
 
@@ -778,9 +756,9 @@ bool pkgCdrom::Add(pkgCdromStatus *log)					/*{{{*/
 	    
 	    if(log != NULL)
 	    {
-	       msg.str("");
-	       ioprintf(msg, _("Found label '%s'\n"), Name.c_str());
-	       log->Update(msg.str());
+	       string msg;
+	       strprintf(msg, _("Found label '%s'\n"), Name.c_str());
+	       log->Update(msg);
 	    }
 	    Database.Set("CD::" + ID + "::Label",Name);
 	 }	 
@@ -824,9 +802,9 @@ bool pkgCdrom::Add(pkgCdromStatus *log)					/*{{{*/
    Database.Set("CD::" + ID,Name);
    if(log != NULL)
    {
-      msg.str("");
-      ioprintf(msg, _("This disc is called: \n'%s'\n"), Name.c_str());
-      log->Update(msg.str());
+      string msg;
+      strprintf(msg, _("This disc is called: \n'%s'\n"), Name.c_str());
+      log->Update(msg);
       log->Update(_("Copying package lists..."), STEP_COPY);
    }
 
@@ -884,7 +862,7 @@ bool pkgCdrom::Add(pkgCdromStatus *log)					/*{{{*/
 
       if(log != NULL)
       {
-	 msg.str("");
+	 stringstream msg;
 	 msg << "deb cdrom:[" << Name << "]/" << string(*I,0,Space) << 
 	    " " << string(*I,Space+1) << endl;
 	 log->Update(msg.str());
@@ -902,7 +880,7 @@ bool pkgCdrom::Add(pkgCdromStatus *log)					/*{{{*/
       }
 
       if(log != NULL) {
-	 msg.str("");
+	 stringstream msg;
 	 msg << "deb-src cdrom:[" << Name << "]/" << string(*I,0,Space) << 
 	    " " << string(*I,Space+1) << endl;
 	 log->Update(msg.str());
@@ -960,10 +938,10 @@ pkgUdevCdromDevices::Dlopen()                     		        /*{{{*/
 // convenience interface, this will just call ScanForRemovable
 vector<CdromDevice>
 pkgUdevCdromDevices::Scan()
-{ 
+{
    bool CdromOnly = _config->FindB("APT::cdrom::CdromOnly", true);
-   return ScanForRemovable(CdromOnly); 
-};
+   return ScanForRemovable(CdromOnly);
+}
 									/*}}}*/
                                                                         /*{{{*/
 vector<CdromDevice>
@@ -1008,7 +986,7 @@ pkgUdevCdromDevices::ScanForRemovable(bool CdromOnly)
       cdrom.DeviceName = string(devnode);
       if (mountpath != "") {
 	 cdrom.MountPath = mountpath;
-	 string s = string(mountpath);
+	 string s = mountpath;
 	 cdrom.Mounted = IsMounted(s);
       } else {
 	 cdrom.Mounted = false;

+ 9 - 1
apt-pkg/cdrom.h

@@ -1,9 +1,13 @@
 #ifndef PKGLIB_CDROM_H
 #define PKGLIB_CDROM_H
 
+#include <apt-pkg/macros.h>
+
 #include<string>
 #include<vector>
 
+#include <stddef.h>
+
 #ifndef APT_8_CLEANER_HEADERS
 #include <apt-pkg/init.h>
 using namespace std;
@@ -69,6 +73,10 @@ class pkgCdrom								/*{{{*/
  public:
    bool Ident(std::string &ident, pkgCdromStatus *log);
    bool Add(pkgCdromStatus *log);
+
+ private:
+   APT_HIDDEN bool MountAndIdentCDROM(Configuration &Database, std::string &CDROM,
+	 std::string &ident, pkgCdromStatus * const log, bool const interactive);
 };
 									/*}}}*/
 
@@ -84,7 +92,7 @@ struct CdromDevice							/*{{{*/
 class pkgUdevCdromDevices						/*{{{*/
 {
  protected:
-   // libudev dlopen stucture
+   // libudev dlopen structure
    void *libudev_handle;
    struct udev* (*udev_new)(void);
    int (*udev_enumerate_add_match_property)(struct udev_enumerate *udev_enumerate, const char *property, const char *value);

+ 5 - 1
apt-pkg/clean.cc

@@ -16,7 +16,11 @@
 #include <apt-pkg/configuration.h>
 #include <apt-pkg/aptconfiguration.h>
 #include <apt-pkg/fileutl.h>
+#include <apt-pkg/pkgcache.h>
+#include <apt-pkg/cacheiterators.h>
 
+#include <string>
+#include <string.h>
 #include <dirent.h>
 #include <sys/stat.h>
 #include <unistd.h>
@@ -105,7 +109,7 @@ bool pkgArchiveCleaner::Go(std::string Dir,pkgCache &Cache)
 	       break;
 	    }
 	    
-	    // See if this verison matches the file
+	    // See if this version matches the file
 	    if (IsFetchable == true && Ver == V.VerStr())
 	       break;
 	 }

+ 6 - 1
apt-pkg/clean.h

@@ -10,8 +10,13 @@
 #ifndef APTPKG_CLEAN_H
 #define APTPKG_CLEAN_H
 
-
+#ifndef APT_10_CLEANER_HEADERS
 #include <apt-pkg/pkgcache.h>
+#endif
+
+#include <string>
+
+class pkgCache;
 
 class pkgArchiveCleaner
 {

+ 56 - 38
apt-pkg/contrib/cdromutl.cc

@@ -19,7 +19,11 @@
 #include <apt-pkg/configuration.h>
 #include <apt-pkg/strutl.h>
 
-#include <sys/wait.h>
+#include <stdlib.h>
+#include <string.h>
+#include <iostream>
+#include <string>
+#include <vector>
 #include <sys/statvfs.h>
 #include <dirent.h>
 #include <fcntl.h>
@@ -42,13 +46,18 @@ bool IsMounted(string &Path)
 {
    if (Path.empty() == true)
       return false;
-   
+
    // Need that trailing slash for directories
    if (Path[Path.length() - 1] != '/')
       Path += '/';
-   
-   /* First we check if the path is actualy mounted, we do this by
-      stating the path and the previous directory (carefull of links!)
+
+   // if the path has a ".disk" directory we treat it as mounted
+   // this way even extracted copies of disks are recognized
+   if (DirectoryExists(Path + ".disk/") == true)
+      return true;
+
+   /* First we check if the path is actually mounted, we do this by
+      stating the path and the previous directory (careful of links!)
       and comparing their device fields. */
    struct stat Buf,Buf2;
    if (stat(Path.c_str(),&Buf) != 0 || 
@@ -66,7 +75,13 @@ bool IsMounted(string &Path)
    leave /etc/mtab inconsitant. We drop all messages this produces. */
 bool UnmountCdrom(string Path)
 {
-   if (IsMounted(Path) == false)
+   // do not generate errors, even if the mountpoint does not exist
+   // the mountpoint might be auto-created by the mount command
+   // and a non-existing mountpoint is surely not mounted
+   _error->PushToStack();
+   bool const mounted = IsMounted(Path);
+   _error->RevertToStack();
+   if (mounted == false)
       return true;
 
    for (int i=0;i<3;i++)
@@ -78,8 +93,9 @@ bool UnmountCdrom(string Path)
       if (Child == 0)
       {
 	 // Make all the fds /dev/null
-	 for (int I = 0; I != 3; I++)
-	    dup2(open("/dev/null",O_RDWR),I);
+	 int const null_fd = open("/dev/null",O_RDWR);
+	 for (int I = 0; I != 3; ++I)
+	    dup2(null_fd, I);
 
 	 if (_config->Exists("Acquire::cdrom::"+Path+"::UMount") == true)
 	 {
@@ -113,19 +129,24 @@ bool UnmountCdrom(string Path)
 /* We fork mount and drop all messages */
 bool MountCdrom(string Path, string DeviceName)
 {
-   if (IsMounted(Path) == true)
+   // do not generate errors, even if the mountpoint does not exist
+   // the mountpoint might be auto-created by the mount command
+   _error->PushToStack();
+   bool const mounted = IsMounted(Path);
+   _error->RevertToStack();
+   if (mounted == true)
       return true;
-   
+
    int Child = ExecFork();
 
    // The child
    if (Child == 0)
    {
       // Make all the fds /dev/null
-      int null_fd = open("/dev/null",O_RDWR);
-      for (int I = 0; I != 3; I++)
+      int const null_fd = open("/dev/null",O_RDWR);
+      for (int I = 0; I != 3; ++I)
 	 dup2(null_fd, I);
-      
+
       if (_config->Exists("Acquire::cdrom::"+Path+"::Mount") == true)
       {
 	 if (system(_config->Find("Acquire::cdrom::"+Path+"::Mount").c_str()) != 0)
@@ -242,37 +263,34 @@ bool IdentCdrom(string CD,string &Res,unsigned int Version)
    return true;   
 }
 									/*}}}*/
-
 // FindMountPointForDevice - Find mountpoint for the given device	/*{{{*/
 string FindMountPointForDevice(const char *devnode)
 {
-   char buf[255];
-   char *out[10];
-   int i=0;
-
    // this is the order that mount uses as well
-   const char *mount[] = { "/etc/mtab", 
-                           "/proc/mount", 
-                           NULL };
+   std::vector<std::string> const mounts = _config->FindVector("Dir::state::MountPoints", "/etc/mtab,/proc/mount");
 
-   for (i=0; mount[i] != NULL; i++) {
-      if (FileExists(mount[i])) {
-         FILE *f=fopen(mount[i], "r");
-         while ( fgets(buf, sizeof(buf), f) != NULL) {
-            if (strncmp(buf, devnode, strlen(devnode)) == 0) {
-               if(TokSplitString(' ', buf, out, 10))
-               {
-                  fclose(f);
-                  // unescape the \0XXX chars in the path
-                  string mount_point = out[1];
-                  return DeEscapeString(mount_point);
-               }
-            }
-         }
-         fclose(f);
+   for (std::vector<std::string>::const_iterator m = mounts.begin(); m != mounts.end(); ++m)
+      if (FileExists(*m) == true)
+      {
+	 char * line = NULL;
+	 size_t line_len = 0;
+	 FILE * f = fopen(m->c_str(), "r");
+	 while(getline(&line, &line_len, f) != -1)
+	 {
+	    char * out[] = { NULL, NULL, NULL };
+	    TokSplitString(' ', line, out, 3);
+	    if (out[2] != NULL || out[1] == NULL || out[0] == NULL)
+	       continue;
+	    if (strcmp(out[0], devnode) != 0)
+	       continue;
+	    fclose(f);
+	    // unescape the \0XXX chars in the path
+	    string mount_point = out[1];
+	    return DeEscapeString(mount_point);
+	 }
+	 fclose(f);
       }
-   }
-   
+
    return string();
 }
 									/*}}}*/

+ 6 - 1
apt-pkg/contrib/cmndline.cc

@@ -18,6 +18,11 @@
 #include <apt-pkg/error.h>
 #include <apt-pkg/strutl.h>
 
+#include <stddef.h>
+#include <stdlib.h>
+#include <string.h>
+#include <string>
+
 #include <apti18n.h>
 									/*}}}*/
 using namespace std;
@@ -293,7 +298,7 @@ bool CommandLine::HandleOpt(int &I,int argc,const char *argv[],
    // Look for an argument.
    while (1)
    {
-      // Look at preceeding text
+      // Look at preceding text
       char Buffer[300];
       if (Argument == 0)
       {

+ 5 - 3
apt-pkg/contrib/cmndline.h

@@ -44,6 +44,8 @@
 #ifndef PKGLIB_CMNDLINE_H
 #define PKGLIB_CMNDLINE_H
 
+#include <apt-pkg/macros.h>
+
 #ifndef APT_8_CLEANER_HEADERS
 #include <apt-pkg/configuration.h>
 #endif
@@ -80,14 +82,14 @@ class CommandLine
    
    bool Parse(int argc,const char **argv);
    void ShowHelp();
-   unsigned int FileSize() const;
+   unsigned int FileSize() const APT_PURE;
    bool DispatchArg(Dispatch *List,bool NoMatch = true);
       
    static char const * GetCommand(Dispatch const * const Map,
-	 unsigned int const argc, char const * const * const argv);
+	 unsigned int const argc, char const * const * const argv) APT_PURE;
 
    static CommandLine::Args MakeArgs(char ShortOpt, char const *LongOpt,
-	 char const *ConfName, unsigned long Flags);
+	 char const *ConfName, unsigned long Flags) APT_CONST;
 
    CommandLine(Args *AList,Configuration *Conf);
    ~CommandLine();

+ 22 - 6
apt-pkg/contrib/configuration.cc

@@ -21,10 +21,18 @@
 #include <apt-pkg/error.h>
 #include <apt-pkg/strutl.h>
 #include <apt-pkg/fileutl.h>
-
+#include <apt-pkg/macros.h>
+
+#include <ctype.h>
+#include <regex.h>
+#include <stddef.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <algorithm>
+#include <string>
 #include <vector>
 #include <fstream>
-#include <iostream>
 
 #include <apti18n.h>
 
@@ -42,8 +50,7 @@ Configuration::Configuration() : ToFree(true)
 }
 Configuration::Configuration(const Item *Root) : Root((Item *)Root), ToFree(false)
 {
-};
-
+}
 									/*}}}*/
 // Configuration::~Configuration - Destructor				/*{{{*/
 // ---------------------------------------------------------------------
@@ -246,12 +253,18 @@ string Configuration::FindDir(const char *Name,const char *Default) const
 // Configuration::FindVector - Find a vector of values			/*{{{*/
 // ---------------------------------------------------------------------
 /* Returns a vector of config values under the given item */
-vector<string> Configuration::FindVector(const char *Name) const
+#if (APT_PKG_MAJOR >= 4 && APT_PKG_MINOR < 13)
+vector<string> Configuration::FindVector(const char *Name) const { return FindVector(Name, ""); }
+#endif
+vector<string> Configuration::FindVector(const char *Name, std::string const &Default) const
 {
    vector<string> Vec;
    const Item *Top = Lookup(Name);
    if (Top == NULL)
-      return Vec;
+      return VectorizeString(Default, ',');
+
+   if (Top->Value.empty() == false)
+      return VectorizeString(Top->Value, ',');
 
    Item *I = Top->Child;
    while(I != NULL)
@@ -259,6 +272,9 @@ vector<string> Configuration::FindVector(const char *Name) const
       Vec.push_back(I->Value);
       I = I->Next;
    }
+   if (Vec.empty() == true)
+      return VectorizeString(Default, ',');
+
    return Vec;
 }
 									/*}}}*/

+ 15 - 1
apt-pkg/contrib/configuration.h

@@ -74,8 +74,22 @@ class Configuration
    std::string Find(std::string const &Name, std::string const &Default) const {return Find(Name.c_str(),Default.c_str());};
    std::string FindFile(const char *Name,const char *Default = 0) const;
    std::string FindDir(const char *Name,const char *Default = 0) const;
+   /** return a list of child options
+    *
+    * Options like Acquire::Languages are handled as lists which
+    * can be overridden and have a default. For the later two a comma
+    * separated list of values is supported.
+    *
+    * \param Name of the parent node
+    * \param Default list of values separated by commas */
+   std::vector<std::string> FindVector(const char *Name, std::string const &Default) const;
+   std::vector<std::string> FindVector(std::string const &Name, std::string const &Default) const { return FindVector(Name.c_str(), Default); };
+#if (APT_PKG_MAJOR >= 4 && APT_PKG_MINOR >= 13)
+   std::vector<std::string> FindVector(const char *Name) const { return FindVector(Name, ""); };
+#else
    std::vector<std::string> FindVector(const char *Name) const;
-   std::vector<std::string> FindVector(std::string const &Name) const { return FindVector(Name.c_str()); };
+#endif
+   std::vector<std::string> FindVector(std::string const &Name) const { return FindVector(Name.c_str(), ""); };
    int FindI(const char *Name,int const &Default = 0) const;
    int FindI(std::string const &Name,int const &Default = 0) const {return FindI(Name.c_str(),Default);};
    bool FindB(const char *Name,bool const &Default = false) const;

+ 1 - 1
apt-pkg/contrib/crc-16.cc

@@ -10,7 +10,7 @@
    Al Longyear <longyear@netcom.com>
    
    Modified by Jason Gunthorpe <jgg@debian.org> to fit the local coding
-   style, this code is belived to be in the Public Domain.
+   style, this code is believed to be in the Public Domain.
    
    ##################################################################### */
 									/*}}}*/

+ 3 - 1
apt-pkg/contrib/crc-16.h

@@ -10,8 +10,10 @@
 #ifndef APTPKG_CRC16_H
 #define APTPKG_CRC16_H
 
+#include <apt-pkg/macros.h>
+
 #define INIT_FCS  0xffff
 unsigned short AddCRC16(unsigned short fcs, void const *buf,
-			unsigned long long len);
+			unsigned long long len) APT_PURE;
 
 #endif

+ 4 - 2
apt-pkg/contrib/error.cc

@@ -17,12 +17,14 @@
 
 #include <apt-pkg/error.h>
 
+#include <stdarg.h>
+#include <stddef.h>
+#include <list>
 #include <iostream>
 #include <errno.h>
 #include <stdio.h>
 #include <stdlib.h>
 #include <unistd.h>
-
 #include <string>
 #include <cstring>
 
@@ -223,7 +225,7 @@ void GlobalError::DumpErrors(std::ostream &out, MsgType const &threshold,
 void GlobalError::Discard() {
 	Messages.clear();
 	PendingFlag = false;
-};
+}
 									/*}}}*/
 // GlobalError::empty - does our error list include anything?		/*{{{*/
 bool GlobalError::empty(MsgType const &trashhold) const {

+ 20 - 19
apt-pkg/contrib/error.h

@@ -46,6 +46,7 @@
 #include <list>
 #include <string>
 
+#include <stddef.h>
 #include <stdarg.h>
 
 class GlobalError							/*{{{*/
@@ -73,7 +74,7 @@ public:									/*{{{*/
 	 *
 	 *  \return \b false
 	 */
-	bool FatalE(const char *Function,const char *Description,...) __like_printf(3) __cold;
+	bool FatalE(const char *Function,const char *Description,...) APT_PRINTF(3) APT_COLD;
 
 	/** \brief add an Error message with errno to the list
 	 *
@@ -82,7 +83,7 @@ public:									/*{{{*/
 	 *
 	 *  \return \b false
 	 */
-	bool Errno(const char *Function,const char *Description,...) __like_printf(3) __cold;
+	bool Errno(const char *Function,const char *Description,...) APT_PRINTF(3) APT_COLD;
 
 	/** \brief add a warning message with errno to the list
 	 *
@@ -94,7 +95,7 @@ public:									/*{{{*/
 	 *
 	 *  \return \b false
 	 */
-	bool WarningE(const char *Function,const char *Description,...) __like_printf(3) __cold;
+	bool WarningE(const char *Function,const char *Description,...) APT_PRINTF(3) APT_COLD;
 
 	/** \brief add a notice message with errno to the list
 	 *
@@ -103,7 +104,7 @@ public:									/*{{{*/
 	 *
 	 *  \return \b false
 	 */
-	bool NoticeE(const char *Function,const char *Description,...) __like_printf(3) __cold;
+	bool NoticeE(const char *Function,const char *Description,...) APT_PRINTF(3) APT_COLD;
 
 	/** \brief add a debug message with errno to the list
 	 *
@@ -112,7 +113,7 @@ public:									/*{{{*/
 	 *
 	 *  \return \b false
 	 */
-	bool DebugE(const char *Function,const char *Description,...) __like_printf(3) __cold;
+	bool DebugE(const char *Function,const char *Description,...) APT_PRINTF(3) APT_COLD;
 
 	/** \brief adds an errno message with the given type
 	 *
@@ -121,7 +122,7 @@ public:									/*{{{*/
 	 * \param Description of the error
 	 */
 	bool InsertErrno(MsgType const &type, const char* Function,
-			 const char* Description,...) __like_printf(4) __cold;
+			 const char* Description,...) APT_PRINTF(4) APT_COLD;
 
 	/** \brief adds an errno message with the given type
 	 *
@@ -140,7 +141,7 @@ public:									/*{{{*/
 	 */
 	bool InsertErrno(MsgType type, const char* Function,
 			 const char* Description, va_list &args,
-			 int const errsv, size_t &msgSize);
+			 int const errsv, size_t &msgSize) APT_COLD;
 
 	/** \brief add an fatal error message to the list
 	 *
@@ -155,7 +156,7 @@ public:									/*{{{*/
 	 *
 	 *  \return \b false
 	 */
-	bool Fatal(const char *Description,...) __like_printf(2) __cold;
+	bool Fatal(const char *Description,...) APT_PRINTF(2) APT_COLD;
 
 	/** \brief add an Error message to the list
 	 *
@@ -163,7 +164,7 @@ public:									/*{{{*/
 	 *
 	 *  \return \b false
 	 */
-	bool Error(const char *Description,...) __like_printf(2) __cold;
+	bool Error(const char *Description,...) APT_PRINTF(2) APT_COLD;
 
 	/** \brief add a warning message to the list
 	 *
@@ -174,7 +175,7 @@ public:									/*{{{*/
 	 *
 	 *  \return \b false
 	 */
-	bool Warning(const char *Description,...) __like_printf(2) __cold;
+	bool Warning(const char *Description,...) APT_PRINTF(2) APT_COLD;
 
 	/** \brief add a notice message to the list
 	 *
@@ -187,7 +188,7 @@ public:									/*{{{*/
 	 *
 	 *  \return \b false
 	 */
-	bool Notice(const char *Description,...) __like_printf(2) __cold;
+	bool Notice(const char *Description,...) APT_PRINTF(2) APT_COLD;
 
 	/** \brief add a debug message to the list
 	 *
@@ -195,14 +196,14 @@ public:									/*{{{*/
 	 *
 	 *  \return \b false
 	 */
-	bool Debug(const char *Description,...) __like_printf(2) __cold;
+	bool Debug(const char *Description,...) APT_PRINTF(2) APT_COLD;
 
 	/** \brief adds an error message with the given type
 	 *
 	 * \param type of the error message
 	 * \param Description of the error
 	 */
-	bool Insert(MsgType const &type, const char* Description,...) __like_printf(3) __cold;
+	bool Insert(MsgType const &type, const char* Description,...) APT_PRINTF(3) APT_COLD;
 
 	/** \brief adds an error message with the given type
 	 *
@@ -218,25 +219,25 @@ public:									/*{{{*/
 	 * should call this method again in that case
 	 */
 	bool Insert(MsgType type, const char* Description,
-			 va_list &args, size_t &msgSize) __cold;
+			 va_list &args, size_t &msgSize) APT_COLD;
 
 	/** \brief is an error in the list?
 	 *
 	 *  \return \b true if an error is included in the list, \b false otherwise
 	 */
-	inline bool PendingError() const {return PendingFlag;};
+	inline bool PendingError() const APT_PURE {return PendingFlag;};
 
 	/** \brief is the list empty?
 	 *
 	 *  The default checks if the list is empty or contains only notices,
-	 *  if you want to check if also no notices happend set the parameter
+	 *  if you want to check if also no notices happened set the parameter
 	 *  flag to \b false.
 	 *
-	 *  \param WithoutNotice does notices count, default is \b true, so no
+	 *  \param threshold minimim level considered
 	 *
 	 *  \return \b true if an the list is empty, \b false otherwise
 	 */
-	bool empty(MsgType const &trashhold = WARNING) const;
+	bool empty(MsgType const &threshold = WARNING) const APT_PURE;
 
 	/** \brief returns and removes the first (or last) message in the list
 	 *
@@ -302,7 +303,7 @@ public:									/*{{{*/
 	void MergeWithStack();
 
 	/** \brief return the deep of the stack */
-	size_t StackCount() const {
+	size_t StackCount() const APT_PURE {
 		return Stacks.size();
 	}
 

+ 391 - 193
apt-pkg/contrib/fileutl.cc

@@ -1,6 +1,5 @@
 // -*- mode: cpp; mode: fold -*-
 // Description								/*{{{*/
-// $Id: fileutl.cc,v 1.42 2002/09/14 05:29:22 jgg Exp $
 /* ######################################################################
    
    File Utilities
@@ -26,16 +25,22 @@
 #include <apt-pkg/sptr.h>
 #include <apt-pkg/aptconfiguration.h>
 #include <apt-pkg/configuration.h>
-
+#include <apt-pkg/macros.h>
+
+#include <ctype.h>
+#include <stdarg.h>
+#include <stddef.h>
+#include <sys/select.h>
+#include <time.h>
+#include <string>
+#include <vector>
 #include <cstdlib>
 #include <cstring>
 #include <cstdio>
-
 #include <iostream>
 #include <unistd.h>
 #include <fcntl.h>
 #include <sys/stat.h>
-#include <sys/types.h>
 #include <sys/time.h>
 #include <sys/wait.h>
 #include <dirent.h>
@@ -52,6 +57,10 @@
 #ifdef HAVE_BZ2
 	#include <bzlib.h>
 #endif
+#ifdef HAVE_LZMA
+	#include <stdint.h>
+	#include <lzma.h>
+#endif
 
 #ifdef WORDS_BIGENDIAN
 #include <inttypes.h>
@@ -62,54 +71,6 @@
 
 using namespace std;
 
-class FileFdPrivate {
-	public:
-#ifdef HAVE_ZLIB
-	gzFile gz;
-#else
-	void* gz;
-#endif
-#ifdef HAVE_BZ2
-	BZFILE* bz2;
-#else
-	void* bz2;
-#endif
-	int compressed_fd;
-	pid_t compressor_pid;
-	bool pipe;
-	APT::Configuration::Compressor compressor;
-	unsigned int openmode;
-	unsigned long long seekpos;
-	FileFdPrivate() : gz(NULL), bz2(NULL),
-			  compressed_fd(-1), compressor_pid(-1), pipe(false),
-			  openmode(0), seekpos(0) {};
-	bool CloseDown(std::string const &FileName)
-	{
-	   bool Res = true;
-#ifdef HAVE_ZLIB
-	   if (gz != NULL) {
-	      int const e = gzclose(gz);
-	      gz = NULL;
-	      // gzdclose() on empty files always fails with "buffer error" here, ignore that
-	      if (e != 0 && e != Z_BUF_ERROR)
-		 Res &= _error->Errno("close",_("Problem closing the gzip file %s"), FileName.c_str());
-	   }
-#endif
-#ifdef HAVE_BZ2
-	   if (bz2 != NULL) {
-	      BZ2_bzclose(bz2);
-	      bz2 = NULL;
-	   }
-#endif
-	   if (compressor_pid > 0)
-	      ExecWait(compressor_pid, "FileFdCompressor", true);
-	   compressor_pid = -1;
-
-	   return Res;
-	}
-	~FileFdPrivate() { CloseDown(""); }
-};
-
 // RunScripts - Run a set of scripts from a configuration subtree	/*{{{*/
 // ---------------------------------------------------------------------
 /* */
@@ -222,7 +183,7 @@ int GetLock(string File,bool Errors)
    int FD = open(File.c_str(),O_RDWR | O_CREAT | O_NOFOLLOW,0640);
    if (FD < 0)
    {
-      // Read only .. cant have locking problems there.
+      // Read only .. can't have locking problems there.
       if (errno == EROFS)
       {
 	 _error->Warning(_("Not using locking for read only lock file %s"),File.c_str());
@@ -238,7 +199,7 @@ int GetLock(string File,bool Errors)
    }
    SetCloseExec(FD,true);
       
-   // Aquire a write lock
+   // Acquire a write lock
    struct flock fl;
    fl.l_type = F_WRLCK;
    fl.l_whence = SEEK_SET;
@@ -319,7 +280,7 @@ bool CreateDirectory(string const &Parent, string const &Path)
       return false;
 
    // we are not going to create directories "into the blue"
-   if (Path.find(Parent, 0) != 0)
+   if (Path.compare(0, Parent.length(), Parent) != 0)
       return false;
 
    vector<string> const dirs = VectorizeString(Path.substr(Parent.size()), '/');
@@ -465,7 +426,7 @@ std::vector<string> GetListOfFilesInDir(string const &Dir, std::vector<string> c
       const char *C = Ent->d_name;
       for (; *C != 0; ++C)
 	 if (isalpha(*C) == 0 && isdigit(*C) == 0
-	     && *C != '_' && *C != '-') {
+	     && *C != '_' && *C != '-' && *C != ':') {
 	    // no required extension -> dot is a bad character
 	    if (*C == '.' && Ext.empty() == false)
 	       continue;
@@ -874,6 +835,122 @@ bool ExecWait(pid_t Pid,const char *Name,bool Reap)
 }
 									/*}}}*/
 
+class FileFdPrivate {							/*{{{*/
+	public:
+#ifdef HAVE_ZLIB
+	gzFile gz;
+#endif
+#ifdef HAVE_BZ2
+	BZFILE* bz2;
+#endif
+#ifdef HAVE_LZMA
+	struct LZMAFILE {
+	   FILE* file;
+	   uint8_t buffer[4096];
+	   lzma_stream stream;
+	   lzma_ret err;
+	   bool eof;
+	   bool compressing;
+
+	   LZMAFILE() : file(NULL), eof(false), compressing(false) {}
+	   ~LZMAFILE() {
+	      if (compressing == true)
+	      {
+		for (;;) {
+			stream.avail_out = sizeof(buffer)/sizeof(buffer[0]);
+			stream.next_out = buffer;
+			err = lzma_code(&stream, LZMA_FINISH);
+			if (err != LZMA_OK && err != LZMA_STREAM_END)
+			{
+				_error->Error("~LZMAFILE: Compress finalisation failed");
+				break;
+			}
+			size_t const n =  sizeof(buffer)/sizeof(buffer[0]) - stream.avail_out;
+			if (n && fwrite(buffer, 1, n, file) != n)
+			{
+				_error->Errno("~LZMAFILE",_("Write error"));
+				break;
+			}
+			if (err == LZMA_STREAM_END)
+				break;
+		}
+	      }
+	      lzma_end(&stream);
+	      fclose(file);
+	   }
+	};
+	LZMAFILE* lzma;
+#endif
+	int compressed_fd;
+	pid_t compressor_pid;
+	bool pipe;
+	APT::Configuration::Compressor compressor;
+	unsigned int openmode;
+	unsigned long long seekpos;
+	FileFdPrivate() :
+#ifdef HAVE_ZLIB
+			  gz(NULL),
+#endif
+#ifdef HAVE_BZ2
+			  bz2(NULL),
+#endif
+#ifdef HAVE_LZMA
+			  lzma(NULL),
+#endif
+			  compressed_fd(-1), compressor_pid(-1), pipe(false),
+			  openmode(0), seekpos(0) {};
+	bool InternalClose(std::string const &FileName)
+	{
+	   if (false)
+	      /* dummy so that the rest can be 'else if's */;
+#ifdef HAVE_ZLIB
+	   else if (gz != NULL) {
+	      int const e = gzclose(gz);
+	      gz = NULL;
+	      // gzdclose() on empty files always fails with "buffer error" here, ignore that
+	      if (e != 0 && e != Z_BUF_ERROR)
+		 return _error->Errno("close",_("Problem closing the gzip file %s"), FileName.c_str());
+	   }
+#endif
+#ifdef HAVE_BZ2
+	   else if (bz2 != NULL) {
+	      BZ2_bzclose(bz2);
+	      bz2 = NULL;
+	   }
+#endif
+#ifdef HAVE_LZMA
+	   else if (lzma != NULL) {
+	      delete lzma;
+	      lzma = NULL;
+	   }
+#endif
+	   return true;
+	}
+	bool CloseDown(std::string const &FileName)
+	{
+	   bool const Res = InternalClose(FileName);
+
+	   if (compressor_pid > 0)
+	      ExecWait(compressor_pid, "FileFdCompressor", true);
+	   compressor_pid = -1;
+
+	   return Res;
+	}
+	bool InternalStream() const {
+	   return false
+#ifdef HAVE_BZ2
+	      || bz2 != NULL
+#endif
+#ifdef HAVE_LZMA
+	      || lzma != NULL
+#endif
+	      ;
+	}
+
+
+	~FileFdPrivate() { CloseDown(""); }
+};
+									/*}}}*/
 // FileFd::Open - Open a file						/*{{{*/
 // ---------------------------------------------------------------------
 /* The most commonly used open mode combinations are given with Mode */
@@ -891,7 +968,7 @@ bool FileFd::Open(string FileName,unsigned int const Mode,CompressMode Compress,
    {
       for (; compressor != compressors.end(); ++compressor)
       {
-	 std::string file = std::string(FileName).append(compressor->Extension);
+	 std::string file = FileName + compressor->Extension;
 	 if (FileExists(file) == false)
 	    continue;
 	 FileName = file;
@@ -1061,30 +1138,12 @@ bool FileFd::OpenDescriptor(int Fd, unsigned int const Mode, APT::Configuration:
 {
    Close();
    Flags = (AutoClose) ? FileFd::AutoClose : 0;
-   if (AutoClose == false && (
-#ifdef HAVE_ZLIB
-	compressor.Name == "gzip" ||
-#endif
-#ifdef HAVE_BZ2
-	compressor.Name == "bzip2" ||
-#endif
-	false))
-   {
-      // Need to duplicate fd here or gzclose for cleanup will close the fd as well
-      iFd = dup(Fd);
-   }
-   else
-      iFd = Fd;
+   iFd = Fd;
    this->FileName = "";
-   if (Fd == -1 || OpenInternDescriptor(Mode, compressor) == false)
+   if (OpenInternDescriptor(Mode, compressor) == false)
    {
       if (iFd != -1 && (
-#ifdef HAVE_ZLIB
-	compressor.Name == "gzip" ||
-#endif
-#ifdef HAVE_BZ2
-	compressor.Name == "bzip2" ||
-#endif
+	(Flags & Compressed) == Compressed ||
 	AutoClose == true))
       {
 	 close (iFd);
@@ -1096,52 +1155,121 @@ bool FileFd::OpenDescriptor(int Fd, unsigned int const Mode, APT::Configuration:
 }
 bool FileFd::OpenInternDescriptor(unsigned int const Mode, APT::Configuration::Compressor const &compressor)
 {
+   if (iFd == -1)
+      return false;
    if (compressor.Name == "." || compressor.Binary.empty() == true)
       return true;
 
+#if defined HAVE_ZLIB || defined HAVE_BZ2 || defined HAVE_LZMA
+   // the API to open files is similar, so setup to avoid code duplicates later
+   // and while at it ensure that we close before opening (if its a reopen)
+   void* (*compress_open)(int, const char *) = NULL;
+   if (false)
+      /* dummy so that the rest can be 'else if's */;
+#define APT_COMPRESS_INIT(NAME,OPEN) \
+   else if (compressor.Name == NAME) \
+   { \
+      compress_open = (void*(*)(int, const char *)) OPEN; \
+      if (d != NULL) d->InternalClose(FileName); \
+   }
+#ifdef HAVE_ZLIB
+   APT_COMPRESS_INIT("gzip", gzdopen)
+#endif
+#ifdef HAVE_BZ2
+   APT_COMPRESS_INIT("bzip2", BZ2_bzdopen)
+#endif
+#ifdef HAVE_LZMA
+   APT_COMPRESS_INIT("xz", fdopen)
+   APT_COMPRESS_INIT("lzma", fdopen)
+#endif
+#undef APT_COMPRESS_INIT
+#endif
+
    if (d == NULL)
    {
       d = new FileFdPrivate();
       d->openmode = Mode;
       d->compressor = compressor;
+#if defined HAVE_ZLIB || defined HAVE_BZ2 || defined HAVE_LZMA
+      if ((Flags & AutoClose) != AutoClose && compress_open != NULL)
+      {
+	 // Need to duplicate fd here or gz/bz2 close for cleanup will close the fd as well
+	 int const internFd = dup(iFd);
+	 if (internFd == -1)
+	    return FileFdErrno("OpenInternDescriptor", _("Could not open file descriptor %d"), iFd);
+	 iFd = internFd;
+      }
+#endif
    }
 
-#ifdef HAVE_ZLIB
-   if (compressor.Name == "gzip")
+#if defined HAVE_ZLIB || defined HAVE_BZ2 || defined HAVE_LZMA
+   if (compress_open != NULL)
    {
-      if (d->gz != NULL)
-      {
-	 gzclose(d->gz);
-	 d->gz = NULL;
-      }
+      void* compress_struct = NULL;
       if ((Mode & ReadWrite) == ReadWrite)
-	 d->gz = gzdopen(iFd, "r+");
+	 compress_struct = compress_open(iFd, "r+");
       else if ((Mode & WriteOnly) == WriteOnly)
-	 d->gz = gzdopen(iFd, "w");
+	 compress_struct = compress_open(iFd, "w");
       else
-	 d->gz = gzdopen(iFd, "r");
-      if (d->gz == NULL)
+	 compress_struct = compress_open(iFd, "r");
+      if (compress_struct == NULL)
 	 return false;
-      Flags |= Compressed;
-      return true;
-   }
+
+      if (false)
+	 /* dummy so that the rest can be 'else if's */;
+#ifdef HAVE_ZLIB
+      else if (compressor.Name == "gzip")
+	 d->gz = (gzFile) compress_struct;
 #endif
 #ifdef HAVE_BZ2
-   if (compressor.Name == "bzip2")
-   {
-      if (d->bz2 != NULL)
+      else if (compressor.Name == "bzip2")
+	 d->bz2 = (BZFILE*) compress_struct;
+#endif
+#ifdef HAVE_LZMA
+      else if (compressor.Name == "xz" || compressor.Name == "lzma")
       {
-	 BZ2_bzclose(d->bz2);
-	 d->bz2 = NULL;
+	 uint32_t const xzlevel = 6;
+	 uint64_t const memlimit = UINT64_MAX;
+	 if (d->lzma == NULL)
+	    d->lzma = new FileFdPrivate::LZMAFILE;
+	 d->lzma->file = (FILE*) compress_struct;
+	 d->lzma->stream = LZMA_STREAM_INIT;
+
+	 if ((Mode & ReadWrite) == ReadWrite)
+	    return FileFdError("ReadWrite mode is not supported for file %s", FileName.c_str());
+
+	 if ((Mode & WriteOnly) == WriteOnly)
+	 {
+	    if (compressor.Name == "xz")
+	    {
+	       if (lzma_easy_encoder(&d->lzma->stream, xzlevel, LZMA_CHECK_CRC32) != LZMA_OK)
+		  return false;
+	    }
+	    else
+	    {
+	       lzma_options_lzma options;
+	       lzma_lzma_preset(&options, xzlevel);
+	       if (lzma_alone_encoder(&d->lzma->stream, &options) != LZMA_OK)
+		  return false;
+	    }
+	    d->lzma->compressing = true;
+	 }
+	 else
+	 {
+	    if (compressor.Name == "xz")
+	    {
+	       if (lzma_auto_decoder(&d->lzma->stream, memlimit, 0) != LZMA_OK)
+		  return false;
+	    }
+	    else
+	    {
+	       if (lzma_alone_decoder(&d->lzma->stream, memlimit) != LZMA_OK)
+		  return false;
+	    }
+	    d->lzma->compressing = false;
+	 }
       }
-      if ((Mode & ReadWrite) == ReadWrite)
-	 d->bz2 = BZ2_bzdopen(iFd, "r+");
-      else if ((Mode & WriteOnly) == WriteOnly)
-	 d->bz2 = BZ2_bzdopen(iFd, "w");
-      else
-	 d->bz2 = BZ2_bzdopen(iFd, "r");
-      if (d->bz2 == NULL)
-	 return false;
+#endif
       Flags |= Compressed;
       return true;
    }
@@ -1198,7 +1326,7 @@ bool FileFd::OpenInternDescriptor(unsigned int const Mode, APT::Configuration::C
       }
       else
       {
-	 if (FileName.empty() == true)
+	 if (d->compressed_fd != -1)
 	    dup2(d->compressed_fd,STDIN_FILENO);
 	 dup2(Pipe[1],STDOUT_FILENO);
       }
@@ -1256,7 +1384,7 @@ FileFd::~FileFd()
 									/*}}}*/
 // FileFd::Read - Read a bit of the file				/*{{{*/
 // ---------------------------------------------------------------------
-/* We are carefull to handle interruption by a signal while reading 
+/* We are careful to handle interruption by a signal while reading
    gracefully. */
 bool FileFd::Read(void *To,unsigned long long Size,unsigned long long *Actual)
 {
@@ -1267,24 +1395,68 @@ bool FileFd::Read(void *To,unsigned long long Size,unsigned long long *Actual)
    *((char *)To) = '\0';
    do
    {
+      if (false)
+	 /* dummy so that the rest can be 'else if's */;
 #ifdef HAVE_ZLIB
-      if (d != NULL && d->gz != NULL)
+      else if (d != NULL && d->gz != NULL)
 	 Res = gzread(d->gz,To,Size);
-      else
 #endif
 #ifdef HAVE_BZ2
-      if (d != NULL && d->bz2 != NULL)
+      else if (d != NULL && d->bz2 != NULL)
 	 Res = BZ2_bzread(d->bz2,To,Size);
-      else
 #endif
+#ifdef HAVE_LZMA
+      else if (d != NULL && d->lzma != NULL)
+      {
+	 if (d->lzma->eof == true)
+	    break;
+
+	 d->lzma->stream.next_out = (uint8_t *) To;
+	 d->lzma->stream.avail_out = Size;
+	 if (d->lzma->stream.avail_in == 0)
+	 {
+	    d->lzma->stream.next_in = d->lzma->buffer;
+	    d->lzma->stream.avail_in = fread(d->lzma->buffer, 1, sizeof(d->lzma->buffer)/sizeof(d->lzma->buffer[0]), d->lzma->file);
+	 }
+	 d->lzma->err = lzma_code(&d->lzma->stream, LZMA_RUN);
+	 if (d->lzma->err == LZMA_STREAM_END)
+	 {
+	    d->lzma->eof = true;
+	    Res = Size - d->lzma->stream.avail_out;
+	 }
+	 else if (d->lzma->err != LZMA_OK)
+	 {
+	    Res = -1;
+	    errno = 0;
+	 }
+	 else
+	 {
+	    Res = Size - d->lzma->stream.avail_out;
+	    if (Res == 0)
+	    {
+	       // lzma run was okay, but produced no output…
+	       Res = -1;
+	       errno = EINTR;
+	    }
+	 }
+      }
+#endif
+      else
          Res = read(iFd,To,Size);
 
       if (Res < 0)
       {
 	 if (errno == EINTR)
+	 {
+	    // trick the while-loop into running again
+	    Res = 1;
+	    errno = 0;
 	    continue;
+	 }
+	 if (false)
+	    /* dummy so that the rest can be 'else if's */;
 #ifdef HAVE_ZLIB
-	 if (d != NULL && d->gz != NULL)
+	 else if (d != NULL && d->gz != NULL)
 	 {
 	    int err;
 	    char const * const errmsg = gzerror(d->gz, &err);
@@ -1293,13 +1465,17 @@ bool FileFd::Read(void *To,unsigned long long Size,unsigned long long *Actual)
 	 }
 #endif
 #ifdef HAVE_BZ2
-	 if (d != NULL && d->bz2 != NULL)
+	 else if (d != NULL && d->bz2 != NULL)
 	 {
 	    int err;
 	    char const * const errmsg = BZ2_bzerror(d->bz2, &err);
 	    if (err != BZ_IO_ERROR)
 	       return FileFdError("BZ2_bzread: %s (%d: %s)", _("Read error"), err, errmsg);
 	 }
+#endif
+#ifdef HAVE_LZMA
+	 else if (d != NULL && d->lzma != NULL)
+	    return FileFdError("lzma_read: %s (%d)", _("Read error"), d->lzma->err);
 #endif
 	 return FileFdErrno("read",_("Read error"));
       }
@@ -1364,23 +1540,45 @@ bool FileFd::Write(const void *From,unsigned long long Size)
    errno = 0;
    do
    {
+      if (false)
+	 /* dummy so that the rest can be 'else if's */;
 #ifdef HAVE_ZLIB
-      if (d != NULL && d->gz != NULL)
-         Res = gzwrite(d->gz,From,Size);
-      else
+      else if (d != NULL && d->gz != NULL)
+	 Res = gzwrite(d->gz,From,Size);
 #endif
 #ifdef HAVE_BZ2
-      if (d != NULL && d->bz2 != NULL)
-         Res = BZ2_bzwrite(d->bz2,(void*)From,Size);
-      else
+      else if (d != NULL && d->bz2 != NULL)
+	 Res = BZ2_bzwrite(d->bz2,(void*)From,Size);
 #endif
-         Res = write(iFd,From,Size);
+#ifdef HAVE_LZMA
+      else if (d != NULL && d->lzma != NULL)
+      {
+	 d->lzma->stream.next_in = (uint8_t *)From;
+	 d->lzma->stream.avail_in = Size;
+	 d->lzma->stream.next_out = d->lzma->buffer;
+	 d->lzma->stream.avail_out = sizeof(d->lzma->buffer)/sizeof(d->lzma->buffer[0]);
+	 d->lzma->err = lzma_code(&d->lzma->stream, LZMA_RUN);
+	 if (d->lzma->err != LZMA_OK)
+	    return false;
+	 size_t const n = sizeof(d->lzma->buffer)/sizeof(d->lzma->buffer[0]) - d->lzma->stream.avail_out;
+	 size_t const m = (n == 0) ? 0 : fwrite(d->lzma->buffer, 1, n, d->lzma->file);
+	 if (m != n)
+	    Res = -1;
+	 else
+	    Res = Size - d->lzma->stream.avail_in;
+      }
+#endif
+      else
+	 Res = write(iFd,From,Size);
+
       if (Res < 0 && errno == EINTR)
 	 continue;
       if (Res < 0)
       {
+	 if (false)
+	    /* dummy so that the rest can be 'else if's */;
 #ifdef HAVE_ZLIB
-	 if (d != NULL && d->gz != NULL)
+	 else if (d != NULL && d->gz != NULL)
 	 {
 	    int err;
 	    char const * const errmsg = gzerror(d->gz, &err);
@@ -1389,18 +1587,22 @@ bool FileFd::Write(const void *From,unsigned long long Size)
 	 }
 #endif
 #ifdef HAVE_BZ2
-	 if (d != NULL && d->bz2 != NULL)
+	 else if (d != NULL && d->bz2 != NULL)
 	 {
 	    int err;
 	    char const * const errmsg = BZ2_bzerror(d->bz2, &err);
 	    if (err != BZ_IO_ERROR)
 	       return FileFdError("BZ2_bzwrite: %s (%d: %s)", _("Write error"), err, errmsg);
 	 }
+#endif
+#ifdef HAVE_LZMA
+	 else if (d != NULL && d->lzma != NULL)
+	    return FileFdErrno("lzma_fwrite", _("Write error"));
 #endif
 	 return FileFdErrno("write",_("Write error"));
       }
       
-      From = (char *)From + Res;
+      From = (char const *)From + Res;
       Size -= Res;
       if (d != NULL)
 	 d->seekpos += Res;
@@ -1424,7 +1626,7 @@ bool FileFd::Write(int Fd, const void *From, unsigned long long Size)
       if (Res < 0)
 	 return _error->Errno("write",_("Write error"));
 
-      From = (char *)From + Res;
+      From = (char const *)From + Res;
       Size -= Res;
    }
    while (Res > 0 && Size > 0);
@@ -1440,11 +1642,7 @@ bool FileFd::Write(int Fd, const void *From, unsigned long long Size)
 /* */
 bool FileFd::Seek(unsigned long long To)
 {
-   if (d != NULL && (d->pipe == true
-#ifdef HAVE_BZ2
-			|| d->bz2 != NULL
-#endif
-	))
+   if (d != NULL && (d->pipe == true || d->InternalStream() == true))
    {
       // Our poor man seeking in pipes is costly, so try to avoid it
       unsigned long long seekpos = Tell();
@@ -1455,13 +1653,7 @@ bool FileFd::Seek(unsigned long long To)
 
       if ((d->openmode & ReadOnly) != ReadOnly)
 	 return FileFdError("Reopen is only implemented for read-only files!");
-#ifdef HAVE_BZ2
-     if (d->bz2 != NULL) 
-     {
-	BZ2_bzclose(d->bz2);
-	d->bz2 = NULL;
-     }
-#endif
+      d->InternalClose(FileName);
       if (iFd != -1)
 	 close(iFd);
       iFd = -1;
@@ -1507,11 +1699,7 @@ bool FileFd::Seek(unsigned long long To)
 /* */
 bool FileFd::Skip(unsigned long long Over)
 {
-   if (d != NULL && (d->pipe == true
-#ifdef HAVE_BZ2
-			|| d->bz2 != NULL
-#endif
-	))
+   if (d != NULL && (d->pipe == true || d->InternalStream() == true))
    {
       d->seekpos += Over;
       char buffer[1024];
@@ -1548,8 +1736,12 @@ bool FileFd::Truncate(unsigned long long To)
    // truncating /dev/null is always successful - as we get an error otherwise
    if (To == 0 && FileName == "/dev/null")
       return true;
-#if defined HAVE_ZLIB || defined HAVE_BZ2
-   if (d != NULL && (d->gz != NULL || d->bz2 != NULL))
+#if defined HAVE_ZLIB || defined HAVE_BZ2 || defined HAVE_LZMA
+   if (d != NULL && (d->InternalStream() == true
+#ifdef HAVE_ZLIB
+	    || d->gz != NULL
+#endif
+	    ))
       return FileFdError("Truncating compressed files is not implemented (%s)", FileName.c_str());
 #endif
    if (ftruncate(iFd,To) != 0)
@@ -1567,11 +1759,7 @@ unsigned long long FileFd::Tell()
    // seeking around, but not all users of FileFd use always Seek() and co
    // so d->seekpos isn't always true and we can just use it as a hint if
    // we have nothing else, but not always as an authority…
-   if (d != NULL && (d->pipe == true
-#ifdef HAVE_BZ2
-			|| d->bz2 != NULL
-#endif
-	))
+   if (d != NULL && (d->pipe == true || d->InternalStream() == true))
       return d->seekpos;
 
    off_t Res;
@@ -1588,29 +1776,55 @@ unsigned long long FileFd::Tell()
    return Res;
 }
 									/*}}}*/
-// FileFd::FileSize - Return the size of the file			/*{{{*/
-// ---------------------------------------------------------------------
-/* */
-unsigned long long FileFd::FileSize()
+static bool StatFileFd(char const * const msg, int const iFd, std::string const &FileName, struct stat &Buf, FileFdPrivate * const d) /*{{{*/
 {
-   struct stat Buf;
-   if ((d == NULL || d->pipe == false) && fstat(iFd,&Buf) != 0)
-      return FileFdErrno("fstat","Unable to determine the file size");
+   bool ispipe = (d != NULL && d->pipe == true);
+   if (ispipe == false)
+   {
+      if (fstat(iFd,&Buf) != 0)
+	 // higher-level code will generate more meaningful messages,
+	 // even translated this would be meaningless for users
+	 return _error->Errno("fstat", "Unable to determine %s for fd %i", msg, iFd);
+      ispipe = S_ISFIFO(Buf.st_mode);
+   }
 
    // for compressor pipes st_size is undefined and at 'best' zero
-   if ((d != NULL && d->pipe == true) || S_ISFIFO(Buf.st_mode))
+   if (ispipe == true)
    {
       // we set it here, too, as we get the info here for free
       // in theory the Open-methods should take care of it already
       if (d != NULL)
 	 d->pipe = true;
       if (stat(FileName.c_str(), &Buf) != 0)
-	 return FileFdErrno("stat","Unable to determine the file size");
+	 return _error->Errno("fstat", "Unable to determine %s for file %s", msg, FileName.c_str());
+   }
+   return true;
+}
+									/*}}}*/
+// FileFd::FileSize - Return the size of the file			/*{{{*/
+unsigned long long FileFd::FileSize()
+{
+   struct stat Buf;
+   if (StatFileFd("file size", iFd, FileName, Buf, d) == false)
+   {
+      Flags |= Fail;
+      return 0;
    }
-
    return Buf.st_size;
 }
 									/*}}}*/
+// FileFd::ModificationTime - Return the time of last touch		/*{{{*/
+time_t FileFd::ModificationTime()
+{
+   struct stat Buf;
+   if (StatFileFd("modification time", iFd, FileName, Buf, d) == false)
+   {
+      Flags |= Fail;
+      return 0;
+   }
+   return Buf.st_mtime;
+}
+									/*}}}*/
 // FileFd::Size - Return the size of the content in the file		/*{{{*/
 // ---------------------------------------------------------------------
 /* */
@@ -1620,11 +1834,7 @@ unsigned long long FileFd::Size()
 
    // for compressor pipes st_size is undefined and at 'best' zero,
    // so we 'read' the content and 'seek' back - see there
-   if (d != NULL && (d->pipe == true
-#ifdef HAVE_BZ2
-			|| (d->bz2 && size > 0)
-#endif
-	))
+   if (d != NULL && (d->pipe == true || (d->InternalStream() == true && size > 0)))
    {
       unsigned long long const oldSeek = Tell();
       char ignore[1000];
@@ -1682,35 +1892,6 @@ unsigned long long FileFd::Size()
    return size;
 }
 									/*}}}*/
-// FileFd::ModificationTime - Return the time of last touch		/*{{{*/
-// ---------------------------------------------------------------------
-/* */
-time_t FileFd::ModificationTime()
-{
-   struct stat Buf;
-   if ((d == NULL || d->pipe == false) && fstat(iFd,&Buf) != 0)
-   {
-      FileFdErrno("fstat","Unable to determine the modification time of file %s", FileName.c_str());
-      return 0;
-   }
-
-   // for compressor pipes st_size is undefined and at 'best' zero
-   if ((d != NULL && d->pipe == true) || S_ISFIFO(Buf.st_mode))
-   {
-      // we set it here, too, as we get the info here for free
-      // in theory the Open-methods should take care of it already
-      if (d != NULL)
-	 d->pipe = true;
-      if (stat(FileName.c_str(), &Buf) != 0)
-      {
-	 FileFdErrno("fstat","Unable to determine the modification time of file %s", FileName.c_str());
-	 return 0;
-      }
-   }
-
-   return Buf.st_mtime;
-}
-									/*}}}*/
 // FileFd::Close - Close the file if the close flag is set		/*{{{*/
 // ---------------------------------------------------------------------
 /* */
@@ -1796,7 +1977,13 @@ bool FileFd::FileFdError(const char *Description,...) {
 }
 									/*}}}*/
 
-gzFile FileFd::gzFd() { return (gzFile) d->gz; }
+APT_DEPRECATED gzFile FileFd::gzFd() {
+#ifdef HAVE_ZLIB
+   return d->gz;
+#else
+   return NULL;
+#endif
+}
 
 
 // Glob - wrapper around "glob()"                                      /*{{{*/
@@ -1844,3 +2031,14 @@ std::string GetTempDir()
 
    return string(tmpdir);
 }
+
+bool Rename(std::string From, std::string To)
+{
+   if (rename(From.c_str(),To.c_str()) != 0)
+   {
+      _error->Error(_("rename failed, %s (%s -> %s)."),strerror(errno),
+                    From.c_str(),To.c_str());
+      return false;
+   }   
+   return true;
+}

+ 8 - 6
apt-pkg/contrib/fileutl.h

@@ -27,6 +27,7 @@
 #include <string>
 #include <vector>
 #include <set>
+#include <time.h>
 
 #include <zlib.h>
 
@@ -94,7 +95,7 @@ class FileFd
       And as the auto-conversation converts a 'unsigned long *' to a 'bool'
       instead of 'unsigned long long *' we need to provide this explicitely -
       otherwise applications magically start to fail… */
-   __deprecated bool Read(void *To,unsigned long long Size,unsigned long *Actual)
+   bool Read(void *To,unsigned long long Size,unsigned long *Actual) APT_DEPRECATED
    {
 	unsigned long long R;
 	bool const T = Read(To, Size, &R);
@@ -118,7 +119,7 @@ class FileFd
    // Simple manipulators
    inline int Fd() {return iFd;};
    inline void Fd(int fd) { OpenDescriptor(fd, ReadWrite);};
-   __deprecated gzFile gzFd();
+   gzFile gzFd() APT_DEPRECATED APT_PURE;
 
    inline bool IsOpen() {return iFd >= 0;};
    inline bool Failed() {return (Flags & Fail) == Fail;};
@@ -149,11 +150,11 @@ class FileFd
 
    private:
    FileFdPrivate* d;
-   bool OpenInternDescriptor(unsigned int const Mode, APT::Configuration::Compressor const &compressor);
+   APT_HIDDEN bool OpenInternDescriptor(unsigned int const Mode, APT::Configuration::Compressor const &compressor);
 
    // private helpers to set Fail flag and call _error->Error
-   bool FileFdErrno(const char* Function, const char* Description,...) __like_printf(3) __cold;
-   bool FileFdError(const char* Description,...) __like_printf(2) __cold;
+   APT_HIDDEN bool FileFdErrno(const char* Function, const char* Description,...) APT_PRINTF(3) APT_COLD;
+   APT_HIDDEN bool FileFdError(const char* Description,...) APT_PRINTF(2) APT_COLD;
 };
 
 bool RunScripts(const char *Cnf);
@@ -161,9 +162,10 @@ bool CopyFile(FileFd &From,FileFd &To);
 int GetLock(std::string File,bool Errors = true);
 bool FileExists(std::string File);
 bool RealFileExists(std::string File);
-bool DirectoryExists(std::string const &Path) __attrib_const;
+bool DirectoryExists(std::string const &Path) APT_CONST;
 bool CreateDirectory(std::string const &Parent, std::string const &Path);
 time_t GetModificationTime(std::string const &Path);
+bool Rename(std::string From, std::string To);
 
 std::string GetTempDir();
 

+ 15 - 14
apt-pkg/contrib/gpgv.cc

@@ -2,21 +2,23 @@
 // Include Files							/*{{{*/
 #include<config.h>
 
+#include<apt-pkg/configuration.h>
+#include<apt-pkg/error.h>
+#include<apt-pkg/strutl.h>
+#include<apt-pkg/fileutl.h>
+#include<apt-pkg/gpgv.h>
+
 #include <errno.h>
 #include <stdio.h>
 #include <string.h>
 #include <stdlib.h>
 #include <fcntl.h>
-#include <sys/stat.h>
-#include <sys/types.h>
 #include <sys/wait.h>
 #include <unistd.h>
-
-#include<apt-pkg/configuration.h>
-#include<apt-pkg/error.h>
-#include<apt-pkg/strutl.h>
-#include<apt-pkg/fileutl.h>
-#include<apt-pkg/gpgv.h>
+#include <stddef.h>
+#include <iostream>
+#include <string>
+#include <vector>
 
 #include <apti18n.h>
 									/*}}}*/
@@ -103,12 +105,12 @@ void ExecGPGV(std::string const &File, std::string const &FileGPG,
       }
    }
 
+   enum  { DETACHED, CLEARSIGNED } releaseSignature = (FileGPG != File) ? DETACHED : CLEARSIGNED;
    std::vector<std::string> dataHeader;
    char * sig = NULL;
    char * data = NULL;
 
-   // file with detached signature
-   if (FileGPG != File)
+   if (releaseSignature == DETACHED)
    {
       Args.push_back(FileGPG.c_str());
       Args.push_back(File.c_str());
@@ -181,7 +183,7 @@ void ExecGPGV(std::string const &File, std::string const &FileGPG,
       putenv((char *)"LC_MESSAGES=");
    }
 
-   if (FileGPG != File)
+   if (releaseSignature == DETACHED)
    {
       execvp(gpgvpath.c_str(), (char **) &Args[0]);
       ioprintf(std::cerr, "Couldn't execute %s to check %s", Args[0], File.c_str());
@@ -260,8 +262,7 @@ bool SplitClearSignedFile(std::string const &InFile, FileFd * const ContentFile,
 
    char *buf = NULL;
    size_t buf_size = 0;
-   ssize_t line_len = 0;
-   while ((line_len = getline(&buf, &buf_size, in)) != -1)
+   while (getline(&buf, &buf_size, in) != -1)
    {
       _strrstrip(buf);
       if (found_message_start == false)
@@ -355,7 +356,7 @@ bool OpenMaybeClearSignedFile(std::string const &ClearSignedFileName, FileFd &Me
       return _error->Error("Couldn't open temporary file to work with %s", ClearSignedFileName.c_str());
 
    _error->PushToStack();
-   bool const splitDone = SplitClearSignedFile(ClearSignedFileName.c_str(), &MessageFile, NULL, NULL);
+   bool const splitDone = SplitClearSignedFile(ClearSignedFileName, &MessageFile, NULL, NULL);
    bool const errorDone = _error->PendingError();
    _error->MergeWithStack();
    if (splitDone == false)

+ 9 - 11
apt-pkg/contrib/gpgv.h

@@ -9,17 +9,17 @@
 #ifndef CONTRIB_GPGV_H
 #define CONTRIB_GPGV_H
 
+#include <apt-pkg/macros.h>
+
 #include <string>
 #include <vector>
 
+#ifndef APT_10_CLEANER_HEADERS
 #include <apt-pkg/fileutl.h>
-
-#if __GNUC__ >= 4
-	#define APT_noreturn	__attribute__ ((noreturn))
-#else
-	#define APT_noreturn	/* no support */
 #endif
 
+class FileFd;
+
 /** \brief generates and run the command to verify a file with gpgv
  *
  * If File and FileSig specify the same file it is assumed that we
@@ -29,7 +29,7 @@
  * for reading. Use #OpenMaybeClearSignedFile to access the message
  * instead to ensure you are only reading signed data.
  *
- * The method does not return, but has some noteable exit-codes:
+ * The method does not return, but has some notable exit-codes:
  * 111 signals an internal error like the inability to execute gpgv,
  * 112 indicates a clear-signed file which doesn't include a message,
  *  which can happen if APT is run while on a network requiring
@@ -40,14 +40,12 @@
  * @param FileSig is the signature (detached or clear-signed)
  */
 void ExecGPGV(std::string const &File, std::string const &FileSig,
-      int const &statusfd, int fd[2]) APT_noreturn;
-inline void ExecGPGV(std::string const &File, std::string const &FileSig,
+      int const &statusfd, int fd[2]) APT_NORETURN;
+inline APT_NORETURN void ExecGPGV(std::string const &File, std::string const &FileSig,
       int const &statusfd = -1) {
    int fd[2];
    ExecGPGV(File, FileSig, statusfd, fd);
-};
-
-#undef APT_noreturn
+}
 
 /** \brief Split an inline signature into message and signature
  *

+ 8 - 5
apt-pkg/contrib/hashes.cc

@@ -16,8 +16,12 @@
 #include <apt-pkg/hashes.h>
 #include <apt-pkg/fileutl.h>
 #include <apt-pkg/configuration.h>
-#include <apt-pkg/macros.h>
+#include <apt-pkg/md5.h>
+#include <apt-pkg/sha1.h>
+#include <apt-pkg/sha2.h>
 
+#include <stddef.h>
+#include <algorithm>
 #include <unistd.h>
 #include <string>
 #include <iostream>
@@ -112,7 +116,7 @@ const char** HashString::SupportedHashes()
    return _SupportedHashes;
 }
 
-bool HashString::empty() const
+APT_PURE bool HashString::empty() const
 {
    return (Type.empty() || Hash.empty());
 }
@@ -129,13 +133,12 @@ bool Hashes::AddFD(int const Fd,unsigned long long Size, bool const addMD5,
 		   bool const addSHA1, bool const addSHA256, bool const addSHA512)
 {
    unsigned char Buf[64*64];
-   ssize_t Res = 0;
-   int ToEOF = (Size == 0);
+   bool const ToEOF = (Size == 0);
    while (Size != 0 || ToEOF)
    {
       unsigned long long n = sizeof(Buf);
       if (!ToEOF) n = std::min(Size, n);
-      Res = read(Fd,Buf,n);
+      ssize_t const Res = read(Fd,Buf,n);
       if (Res < 0 || (!ToEOF && Res != (ssize_t) n)) // error, or short read
 	 return false;
       if (ToEOF && Res == 0) // EOF

+ 11 - 6
apt-pkg/contrib/hashes.h

@@ -17,17 +17,22 @@
 #include <apt-pkg/md5.h>
 #include <apt-pkg/sha1.h>
 #include <apt-pkg/sha2.h>
-#include <apt-pkg/fileutl.h>
 
-#include <algorithm>
-#include <vector>
 #include <cstring>
-
+#include <string>
 
 #ifndef APT_8_CLEANER_HEADERS
 using std::min;
 using std::vector;
 #endif
+#ifndef APT_10_CLEANER_HEADERS
+#include <apt-pkg/fileutl.h>
+#include <algorithm>
+#include <vector>
+#endif
+
+
+class FileFd;
 
 // helper class that contains hash function name
 // and hash
@@ -61,7 +66,7 @@ class HashString
    bool empty() const;
 
    // return the list of hashes we support
-   static const char** SupportedHashes();
+   static APT_CONST const char** SupportedHashes();
 };
 
 class Hashes
@@ -77,7 +82,7 @@ class Hashes
    {
       return MD5.Add(Data,Size) && SHA1.Add(Data,Size) && SHA256.Add(Data,Size) && SHA512.Add(Data,Size);
    };
-   inline bool Add(const char *Data) {return Add((unsigned char *)Data,strlen(Data));};
+   inline bool Add(const char *Data) {return Add((unsigned char const *)Data,strlen(Data));};
    inline bool AddFD(int const Fd,unsigned long long Size = 0)
    { return AddFD(Fd, Size, true, true, true, true); };
    bool AddFD(int const Fd, unsigned long long Size, bool const addMD5,

+ 6 - 4
apt-pkg/contrib/hashsum.cc

@@ -1,6 +1,9 @@
 // Cryptographic API Base
 #include <config.h>
 
+#include <apt-pkg/fileutl.h>
+
+#include <algorithm>
 #include <unistd.h>
 #include "hashsum_template.h"
 
@@ -9,13 +12,12 @@
 /* */
 bool SummationImplementation::AddFD(int const Fd, unsigned long long Size) {
    unsigned char Buf[64 * 64];
-   ssize_t Res = 0;
-   int ToEOF = (Size == 0);
+   bool const ToEOF = (Size == 0);
    while (Size != 0 || ToEOF)
    {
       unsigned long long n = sizeof(Buf);
       if (!ToEOF) n = std::min(Size, n);
-      Res = read(Fd, Buf, n);
+      ssize_t const Res = read(Fd, Buf, n);
       if (Res < 0 || (!ToEOF && Res != (ssize_t) n)) // error, or short read
 	 return false;
       if (ToEOF && Res == 0) // EOF
@@ -27,7 +29,7 @@ bool SummationImplementation::AddFD(int const Fd, unsigned long long Size) {
 }
 bool SummationImplementation::AddFD(FileFd &Fd, unsigned long long Size) {
    unsigned char Buf[64 * 64];
-   bool ToEOF = (Size == 0);
+   bool const ToEOF = (Size == 0);
    while (Size != 0 || ToEOF)
    {
       unsigned long long n = sizeof(Buf);

+ 28 - 24
apt-pkg/contrib/hashsum_template.h

@@ -10,36 +10,40 @@
 #ifndef APTPKG_HASHSUM_TEMPLATE_H
 #define APTPKG_HASHSUM_TEMPLATE_H
 
-#include <apt-pkg/fileutl.h>
 
 #include <string>
 #include <cstring>
-#include <algorithm>
-#include <stdint.h>
 
 #include <apt-pkg/strutl.h>
 
+#ifndef APT_10_CLEANER_HEADERS
+#include <apt-pkg/fileutl.h>
+#include <algorithm>
+#include <stdint.h>
+#endif
 #ifndef APT_8_CLEANER_HEADERS
 using std::string;
 using std::min;
 #endif
 
+class FileFd;
+
 template<int N>
 class HashSumValue
 {
    unsigned char Sum[N/8];
-   
+
    public:
 
    // Accessors
    bool operator ==(const HashSumValue &rhs) const
    {
       return memcmp(Sum,rhs.Sum,sizeof(Sum)) == 0;
-   };
+   }
    bool operator !=(const HashSumValue &rhs) const
    {
       return memcmp(Sum,rhs.Sum,sizeof(Sum)) != 0;
-   };
+   }
 
    std::string Value() const
    {
@@ -49,7 +53,7 @@ class HashSumValue
       };
       char Result[((N/8)*2)+1];
       Result[(N/8)*2] = 0;
-      
+
       // Convert each char into two letters
       int J = 0;
       int I = 0;
@@ -59,31 +63,31 @@ class HashSumValue
          Result[I + 1] = Conv[Sum[J] & 0xF];
       }
       return std::string(Result);
-   };
-   
+   }
+
    inline void Value(unsigned char S[N/8])
    {
-      for (int I = 0; I != sizeof(Sum); I++) 
+      for (int I = 0; I != sizeof(Sum); ++I)
          S[I] = Sum[I];
-   };
+   }
 
-   inline operator std::string() const 
+   inline operator std::string() const
    {
       return Value();
-   };
+   }
 
-   bool Set(std::string Str) 
+   bool Set(std::string Str)
    {
       return Hex2Num(Str,Sum,sizeof(Sum));
-   };
+   }
 
-   inline void Set(unsigned char S[N/8]) 
+   inline void Set(unsigned char S[N/8])
    {
-      for (int I = 0; I != sizeof(Sum); I++) 
+      for (int I = 0; I != sizeof(Sum); ++I)
          Sum[I] = S[I];
-   };
+   }
 
-   HashSumValue(std::string Str) 
+   HashSumValue(std::string Str)
    {
          memset(Sum,0,sizeof(Sum));
          Set(Str);
@@ -99,17 +103,17 @@ class SummationImplementation
    public:
    virtual bool Add(const unsigned char *inbuf, unsigned long long inlen) = 0;
    inline bool Add(const char *inbuf, unsigned long long const inlen)
-   { return Add((unsigned char *)inbuf, inlen); };
+   { return Add((const unsigned char *)inbuf, inlen); }
 
    inline bool Add(const unsigned char *Data)
-   { return Add(Data, strlen((const char *)Data)); };
+   { return Add(Data, strlen((const char *)Data)); }
    inline bool Add(const char *Data)
-   { return Add((const unsigned char *)Data, strlen((const char *)Data)); };
+   { return Add((const unsigned char *)Data, strlen(Data)); }
 
    inline bool Add(const unsigned char *Beg, const unsigned char *End)
-   { return Add(Beg, End - Beg); };
+   { return Add(Beg, End - Beg); }
    inline bool Add(const char *Beg, const char *End)
-   { return Add((const unsigned char *)Beg, End - Beg); };
+   { return Add((const unsigned char *)Beg, End - Beg); }
 
    bool AddFD(int Fd, unsigned long long Size = 0);
    bool AddFD(FileFd &Fd, unsigned long long Size = 0);

+ 72 - 18
apt-pkg/contrib/macros.h

@@ -44,7 +44,7 @@
 #define _boundv(a,b,c) b = _bound(a,b,c)
 #define ABS(a) (((a) < (0)) ?-(a) : (a))
 
-/* Usefull count macro, use on an array of things and it will return the
+/* Useful count macro, use on an array of things and it will return the
    number of items in the array */
 #define _count(a) (sizeof(a)/sizeof(a[0]))
 
@@ -54,37 +54,91 @@
 #define CLRFLAG(v,f)	((v) &=~FLAG(f))
 #define	CHKFLAG(v,f)	((v) &  FLAG(f) ? true : false)
 
-// some nice optional GNUC features
-#if __GNUC__ >= 3
-	#define __must_check	__attribute__ ((warn_unused_result))
-	#define __deprecated	__attribute__ ((deprecated))
-	#define __attrib_const	__attribute__ ((__const__))
-	/* likely() and unlikely() can be used to mark boolean expressions
-	   as (not) likely true which will help the compiler to optimise */
+#ifdef __GNUC__
+#define APT_GCC_VERSION (__GNUC__ << 8 | __GNUC_MINOR__)
+#else
+#define APT_GCC_VERSION 0
+#endif
+
+/* likely() and unlikely() can be used to mark boolean expressions
+   as (not) likely true which will help the compiler to optimise */
+#if APT_GCC_VERSION >= 0x0300
 	#define likely(x)	__builtin_expect (!!(x), 1)
 	#define unlikely(x)	__builtin_expect (!!(x), 0)
 #else
-	#define __must_check	/* no warn_unused_result */
-	#define __deprecated	/* no deprecated */
-	#define __attrib_const	/* no const attribute */
 	#define likely(x)	(x)
 	#define unlikely(x)	(x)
 #endif
 
+#if APT_GCC_VERSION >= 0x0300
+	#define APT_DEPRECATED	__attribute__ ((deprecated))
+	#define APT_CONST	__attribute__((const))
+	#define APT_PURE	__attribute__((pure))
+	#define APT_NORETURN	__attribute__((noreturn))
+	#define APT_PRINTF(n)	__attribute__((format(printf, n, n + 1)))
+#else
+	#define APT_DEPRECATED
+	#define APT_CONST
+	#define APT_PURE
+	#define APT_NORETURN
+	#define APT_PRINTF(n)
+#endif
+
+#if APT_GCC_VERSION > 0x0302
+	#define APT_NONNULL(...)	__attribute__((nonnull(__VA_ARGS__)))
+	#define APT_MUSTCHECK		__attribute__((warn_unused_result))
+#else
+	#define APT_NONNULL(...)
+	#define APT_REQRET
+#endif
+
+#if APT_GCC_VERSION >= 0x0400
+	#define APT_SENTINEL	__attribute__((sentinel))
+	#define APT_PUBLIC __attribute__ ((visibility ("default")))
+	#define APT_HIDDEN __attribute__ ((visibility ("hidden")))
+#else
+	#define APT_SENTINEL
+	#define APT_PUBLIC
+	#define APT_HIDDEN
+#endif
+
 // cold functions are unlikely() to be called
-#if (__GNUC__ == 4 && __GNUC_MINOR__ >= 3) || __GNUC__ > 4
-	#define __cold	__attribute__ ((__cold__))
-	#define __hot	__attribute__ ((__hot__))
+#if APT_GCC_VERSION >= 0x0403
+	#define APT_COLD	__attribute__ ((__cold__))
+	#define APT_HOT		__attribute__ ((__hot__))
 #else
-	#define __cold	/* no cold marker */
-	#define __hot	/* no hot marker */
+	#define APT_COLD
+	#define APT_HOT
 #endif
 
-#ifdef __GNUG__
-// Methods have a hidden this parameter that is visible to this attribute
+#ifndef APT_10_CLEANER_HEADERS
+#if APT_GCC_VERSION >= 0x0300
+	#define __must_check	__attribute__ ((warn_unused_result))
+	#define __deprecated	__attribute__ ((deprecated))
+	#define __attrib_const	__attribute__ ((__const__))
 	#define __like_printf(n)	__attribute__((format(printf, n, n + 1)))
 #else
+	#define __must_check	/* no warn_unused_result */
+	#define __deprecated	/* no deprecated */
+	#define __attrib_const	/* no const attribute */
 	#define __like_printf(n)	/* no like-printf */
 #endif
+#if APT_GCC_VERSION >= 0x0403
+	#define __cold	__attribute__ ((__cold__))
+	#define __hot	__attribute__ ((__hot__))
+#else
+	#define __cold	/* no cold marker */
+	#define __hot	/* no hot marker */
+#endif
+#endif
+
+// These lines are extracted by the makefiles and the buildsystem
+// Increasing MAJOR or MINOR results in the need of recompiling all
+// reverse-dependencies of libapt-pkg against the new SONAME.
+// Non-ABI-Breaks should only increase RELEASE number.
+// See also buildlib/libversion.mak
+#define APT_PKG_MAJOR 4
+#define APT_PKG_MINOR 12
+#define APT_PKG_RELEASE 0
 
 #endif

+ 1 - 5
apt-pkg/contrib/md5.cc

@@ -38,13 +38,9 @@
 #include <config.h>
 
 #include <apt-pkg/md5.h>
-#include <apt-pkg/strutl.h>
-#include <apt-pkg/macros.h>
 
+#include <stdint.h>
 #include <string.h>
-#include <unistd.h>
-#include <netinet/in.h>                          // For htonl
-#include <inttypes.h>
 									/*}}}*/
 
 // byteSwap - Swap bytes in a buffer					/*{{{*/

+ 6 - 5
apt-pkg/contrib/md5.h

@@ -10,7 +10,7 @@
    store a MD5Sum in 16 bytes of memory.
    
    A MD5Sum is used to generate a (hopefully) unique 16 byte number for a
-   block of data. This can be used to gaurd against corruption of a file.
+   block of data. This can be used to guard against corruption of a file.
    MD5 should not be used for tamper protection, use SHA or something more
    secure.
    
@@ -23,14 +23,15 @@
 #ifndef APTPKG_MD5_H
 #define APTPKG_MD5_H
 
-
-#include <string>
-#include <cstring>
-#include <algorithm>
 #include <stdint.h>
 
 #include "hashsum_template.h"
 
+#ifndef APT_10_CLEANER_HEADERS
+#include <string>
+#include <cstring>
+#include <algorithm>
+#endif
 #ifndef APT_8_CLEANER_HEADERS
 using std::string;
 using std::min;

+ 10 - 4
apt-pkg/contrib/mmap.cc

@@ -22,11 +22,11 @@
 #include <apt-pkg/mmap.h>
 #include <apt-pkg/error.h>
 #include <apt-pkg/fileutl.h>
+#include <apt-pkg/macros.h>
 
+#include <string>
 #include <sys/mman.h>
-#include <sys/stat.h>
 #include <unistd.h>
-#include <fcntl.h>
 #include <stdlib.h>
 #include <errno.h>
 #include <cstring>
@@ -198,7 +198,7 @@ bool MMap::Sync(unsigned long Start,unsigned long Stop)
       {
 #ifdef _POSIX_SYNCHRONIZED_IO
 	 unsigned long long const PSize = sysconf(_SC_PAGESIZE);
-	 if (msync((char *)Base+(unsigned long long)(Start/PSize)*PSize,Stop - Start,MS_SYNC) < 0)
+	 if (msync((char *)Base+(Start/PSize)*PSize, Stop - Start, MS_SYNC) < 0)
 	    return _error->Errno("msync", _("Unable to synchronize mmap"));
 #endif
       }
@@ -352,6 +352,12 @@ unsigned long DynamicMMap::RawAllocate(unsigned long long Size,unsigned long Aln
    size in the file. */
 unsigned long DynamicMMap::Allocate(unsigned long ItemSize)
 {
+   if (unlikely(ItemSize == 0))
+   {
+      _error->Fatal("Can't allocate an item of size zero");
+      return 0;
+   }
+
    // Look for a matching pool entry
    Pool *I;
    Pool *Empty = 0;
@@ -412,7 +418,7 @@ unsigned long DynamicMMap::WriteString(const char *String,
 
    unsigned long const Result = RawAllocate(Len+1,0);
 
-   if (Result == 0 && _error->PendingError())
+   if (Base == NULL || (Result == 0 && _error->PendingError()))
       return 0;
 
    memcpy((char *)Base + Result,String,Len);

+ 2 - 2
apt-pkg/contrib/mmap.h

@@ -6,7 +6,7 @@
    MMap Class - Provides 'real' mmap or a faked mmap using read().
 
    The purpose of this code is to provide a generic way for clients to
-   access the mmap function. In enviroments that do not support mmap
+   access the mmap function. In environments that do not support mmap
    from file fd's this function will use read and normal allocated 
    memory.
    
@@ -15,7 +15,7 @@
 
    The DynamicMMap class is used to help the on-disk data structure 
    generators. It provides a large allocated workspace and members
-   to allocate space from the workspace in an effecient fashion.
+   to allocate space from the workspace in an efficient fashion.
    
    This source is placed in the Public Domain, do with it what you will
    It was originally written by Jason Gunthorpe.

+ 2 - 3
apt-pkg/contrib/netrc.cc

@@ -15,14 +15,13 @@
 
 #include <apt-pkg/configuration.h>
 #include <apt-pkg/strutl.h>
-#include <apt-pkg/error.h>
-#include <apt-pkg/fileutl.h>
 
 #include <iostream>
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
 #include <unistd.h>
+#include <stddef.h>
 #include <pwd.h>
 
 #include "netrc.h"
@@ -198,7 +197,7 @@ void maybe_add_auth (URI &Uri, string NetRCFile)
       // if host did not work, try Host+Path next, this will trigger
       // a lookup uri.startswith(host) in the netrc file parser (because
       // of the "/"
-      char *hostpath = strdup(string(Uri.Host+Uri.Path).c_str());
+      char *hostpath = strdup((Uri.Host + Uri.Path).c_str());
       if (hostpath && parsenetrc_string(hostpath, login, password, netrcfile) == 0)
       {
 	 if (_config->FindB("Debug::Acquire::netrc", false) == true)

+ 4 - 2
apt-pkg/contrib/netrc.h

@@ -16,6 +16,8 @@
 
 #include <string>
 
+#include <apt-pkg/macros.h>
+
 #ifndef APT_8_CLEANER_HEADERS
 #include <apt-pkg/strutl.h>
 #endif
@@ -25,9 +27,9 @@
 
 class URI;
 
-// kill this export on the next ABI break - strongly doubt its in use anyway
+// FIXME: kill this export on the next ABI break - strongly doubt its in use anyway
 // outside of the apt itself, its really a internal interface
-__deprecated int parsenetrc (char *host, char *login, char *password, char *filename);
+APT_DEPRECATED int parsenetrc (char *host, char *login, char *password, char *filename);
 
 void maybe_add_auth (URI &Uri, std::string NetRCFile);
 #endif

+ 8 - 6
apt-pkg/contrib/progress.cc

@@ -14,6 +14,8 @@
 #include <apt-pkg/error.h>
 #include <apt-pkg/configuration.h>
 
+#include <sys/time.h>
+#include <string>
 #include <iostream>
 #include <stdio.h>
 #include <cstring>
@@ -125,14 +127,14 @@ bool OpProgress::CheckChange(float Interval)
 // OpTextProgress::OpTextProgress - Constructor				/*{{{*/
 // ---------------------------------------------------------------------
 /* */
-OpTextProgress::OpTextProgress(Configuration &Config) : 
-                               NoUpdate(false), NoDisplay(false), LastLen(0) 
+OpTextProgress::OpTextProgress(Configuration &Config) :
+                               NoUpdate(false), NoDisplay(false), LastLen(0)
 {
    if (Config.FindI("quiet",0) >= 1 || Config.FindB("quiet::NoUpdate", false) == true)
       NoUpdate = true;
    if (Config.FindI("quiet",0) >= 2)
       NoDisplay = true;
-};
+}
 									/*}}}*/
 // OpTextProgress::Done - Clean up the display				/*{{{*/
 // ---------------------------------------------------------------------
@@ -150,12 +152,12 @@ void OpTextProgress::Done()
       cout << endl;
       OldOp = string();
    }
-   
+
    if (NoUpdate == true && NoDisplay == false && OldOp.empty() == false)
    {
       OldOp = string();
-      cout << endl;   
-   }   
+      cout << endl;
+   }
 }
 									/*}}}*/
 // OpTextProgress::Update - Simple text spinner				/*{{{*/

+ 1 - 1
apt-pkg/contrib/progress.h

@@ -7,7 +7,7 @@
    
    This class allows lengthy operations to communicate their progress 
    to the GUI. The progress model is simple and is not designed to handle
-   the complex case of the multi-activity aquire class.
+   the complex case of the multi-activity acquire class.
    
    The model is based on the concept of an overall operation consisting
    of a series of small sub operations. Each sub operation has it's own

+ 1 - 4
apt-pkg/contrib/sha1.cc

@@ -32,12 +32,9 @@
 #include <config.h>
 
 #include <apt-pkg/sha1.h>
-#include <apt-pkg/strutl.h>
-#include <apt-pkg/macros.h>
 
+#include <stdint.h>
 #include <string.h>
-#include <unistd.h>
-#include <inttypes.h>
 									/*}}}*/
 
 // SHA1Transform - Alters an existing SHA-1 hash			/*{{{*/

+ 4 - 3
apt-pkg/contrib/sha1.h

@@ -14,12 +14,13 @@
 #ifndef APTPKG_SHA1_H
 #define APTPKG_SHA1_H
 
+#include "hashsum_template.h"
+
+#ifndef APT_10_CLEANER_HEADERS
 #include <string>
 #include <cstring>
 #include <algorithm>
-
-#include "hashsum_template.h"
-
+#endif
 #ifndef APT_8_CLEANER_HEADERS
 using std::string;
 using std::min;

+ 7 - 3
apt-pkg/contrib/sha2.h

@@ -14,14 +14,18 @@
 #ifndef APTPKG_SHA2_H
 #define APTPKG_SHA2_H
 
-#include <string>
 #include <cstring>
-#include <algorithm>
-#include <stdint.h>
 
 #include "sha2_internal.h"
 #include "hashsum_template.h"
 
+#ifndef APT_10_CLEANER_HEADERS
+#include <string>
+#include <algorithm>
+#include <stdint.h>
+#endif
+
+
 typedef HashSumValue<512> SHA512SumValue;
 typedef HashSumValue<256> SHA256SumValue;
 

+ 2 - 1
apt-pkg/contrib/sha2_internal.cc

@@ -33,6 +33,7 @@
  */
 #include <config.h>
 
+#include <endian.h>
 #include <string.h>	/* memcpy()/memset() or bcopy()/bzero() */
 #include <assert.h>	/* assert() */
 #include "sha2_internal.h"
@@ -65,7 +66,7 @@
  * Please make sure that your system defines BYTE_ORDER.  If your
  * architecture is little-endian, make sure it also defines
  * LITTLE_ENDIAN and that the two (BYTE_ORDER and LITTLE_ENDIAN) are
- * equivilent.
+ * equivalent.
  *
  * If your system does not define the above, then you can do so by
  * hand like this:

+ 1 - 0
apt-pkg/contrib/sha2_internal.h

@@ -44,6 +44,7 @@
 
 #ifdef SHA2_USE_INTTYPES_H
 
+#include <stddef.h>
 #include <inttypes.h>
 
 #endif /* SHA2_USE_INTTYPES_H */

+ 17 - 10
apt-pkg/contrib/strutl.cc

@@ -21,6 +21,11 @@
 #include <apt-pkg/fileutl.h>
 #include <apt-pkg/error.h>
 
+#include <stddef.h>
+#include <stdlib.h>
+#include <time.h>
+#include <string>
+#include <vector>
 #include <ctype.h>
 #include <string.h>
 #include <sstream>
@@ -33,9 +38,9 @@
 #include <iconv.h>
 
 #include <apti18n.h>
-
-using namespace std;
 									/*}}}*/
+using namespace std;
+
 // Strip - Remove white space from the front and back of a string       /*{{{*/
 // ---------------------------------------------------------------------
 namespace APT {
@@ -153,7 +158,7 @@ char *_strrstrip(char *String)
    End++;
    *End = 0;
    return String;
-};
+}
 									/*}}}*/
 // strtabexpand - Converts tabs into 8 spaces				/*{{{*/
 // ---------------------------------------------------------------------
@@ -426,7 +431,7 @@ string TimeToStr(unsigned long Sec)
 									/*}}}*/
 // SubstVar - Substitute a string for another string			/*{{{*/
 // ---------------------------------------------------------------------
-/* This replaces all occurances of Subst with Contents in Str. */
+/* This replaces all occurrences of Subst with Contents in Str. */
 string SubstVar(const string &Str,const string &Subst,const string &Contents)
 {
    string::size_type Pos = 0;
@@ -926,7 +931,7 @@ bool FTPMDTMStrToTime(const char* const str,time_t &time)
 									/*}}}*/
 // StrToTime - Converts a string into a time_t				/*{{{*/
 // ---------------------------------------------------------------------
-/* This handles all 3 populare time formats including RFC 1123, RFC 1036
+/* This handles all 3 popular time formats including RFC 1123, RFC 1036
    and the C library asctime format. It requires the GNU library function
    'timegm' to convert a struct tm in UTC to a time_t. For some bizzar
    reason the C library does not provide any such function :< This also
@@ -1130,9 +1135,11 @@ bool TokSplitString(char Tok,char *Input,char **List,
    also, but the advantage is that we have an iteratable vector */
 vector<string> VectorizeString(string const &haystack, char const &split)
 {
+   vector<string> exploded;
+   if (haystack.empty() == true)
+      return exploded;
    string::const_iterator start = haystack.begin();
    string::const_iterator end = start;
-   vector<string> exploded;
    do {
       for (; end != haystack.end() && *end != split; ++end);
       exploded.push_back(string(start, end));
@@ -1182,7 +1189,7 @@ unsigned long RegexChoice(RxChoiceList *Rxs,const char **ListBegin,
       R->Hit = false;
 
    unsigned long Hits = 0;
-   for (; ListBegin != ListEnd; ListBegin++)
+   for (; ListBegin < ListEnd; ++ListBegin)
    {
       // Check if the name is a regex
       const char *I;
@@ -1313,7 +1320,7 @@ string StripEpoch(const string &VerStr)
 // tolower_ascii - tolower() function that ignores the locale		/*{{{*/
 // ---------------------------------------------------------------------
 /* This little function is the most called method we have and tries
-   therefore to do the absolut minimum - and is noteable faster than
+   therefore to do the absolut minimum - and is notable faster than
    standard tolower/toupper and as a bonus avoids problems with different
    locales - we only operate on ascii chars anyway. */
 int tolower_ascii(int const c)
@@ -1324,9 +1331,9 @@ int tolower_ascii(int const c)
 }
 									/*}}}*/
 
-// CheckDomainList - See if Host is in a , seperate list		/*{{{*/
+// CheckDomainList - See if Host is in a , separate list		/*{{{*/
 // ---------------------------------------------------------------------
-/* The domain list is a comma seperate list of domains that are suffix
+/* The domain list is a comma separate list of domains that are suffix
    matched against the argument */
 bool CheckDomainList(const string &Host,const string &List)
 {

+ 39 - 36
apt-pkg/contrib/strutl.h

@@ -18,15 +18,18 @@
 
 
 #include <limits>
-#include <stdlib.h>
 #include <string>
 #include <cstring>
 #include <vector>
 #include <iostream>
 #include <time.h>
+#include <stddef.h>
 
 #include "macros.h"
 
+#ifndef APT_10_CLEANER_HEADERS
+#include <stdlib.h>
+#endif
 #ifndef APT_8_CLEANER_HEADERS
 using std::string;
 using std::vector;
@@ -37,8 +40,8 @@ namespace APT {
    namespace String {
       std::string Strip(const std::string &s);
       bool Endswith(const std::string &s, const std::string &ending);
-   };
-};
+   }
+}
 
 
 bool UTF8ToCodeset(const char *codeset, const std::string &orig, std::string *dest);
@@ -60,9 +63,9 @@ std::string Base64Encode(const std::string &Str);
 std::string OutputInDepth(const unsigned long Depth, const char* Separator="  ");
 std::string URItoFileName(const std::string &URI);
 std::string TimeRFC1123(time_t Date);
-bool RFC1123StrToTime(const char* const str,time_t &time) __must_check;
-bool FTPMDTMStrToTime(const char* const str,time_t &time) __must_check;
-__deprecated bool StrToTime(const std::string &Val,time_t &Result);
+bool RFC1123StrToTime(const char* const str,time_t &time) APT_MUSTCHECK;
+bool FTPMDTMStrToTime(const char* const str,time_t &time) APT_MUSTCHECK;
+APT_DEPRECATED bool StrToTime(const std::string &Val,time_t &Result);
 std::string LookupTag(const std::string &Message,const char *Tag,const char *Default = 0);
 int StringToBool(const std::string &Text,int Default = -1);
 bool ReadMessages(int Fd, std::vector<std::string> &List);
@@ -76,7 +79,7 @@ bool TokSplitString(char Tok,char *Input,char **List,
 		    unsigned long ListMax);
 
 // split a given string by a char
-std::vector<std::string> VectorizeString(std::string const &haystack, char const &split) __attrib_const;
+std::vector<std::string> VectorizeString(std::string const &haystack, char const &split) APT_CONST;
 
 /* \brief Return a vector of strings from string "input" where "sep"
  * is used as the delimiter string.
@@ -94,56 +97,56 @@ std::vector<std::string> VectorizeString(std::string const &haystack, char const
  */
 std::vector<std::string> StringSplit(std::string const &input, 
                                      std::string const &sep, 
-                                     unsigned int maxsplit=std::numeric_limits<unsigned int>::max()) __attrib_const;
+                                     unsigned int maxsplit=std::numeric_limits<unsigned int>::max()) APT_CONST;
 
-void ioprintf(std::ostream &out,const char *format,...) __like_printf(2);
-void strprintf(std::string &out,const char *format,...) __like_printf(2);
-char *safe_snprintf(char *Buffer,char *End,const char *Format,...) __like_printf(3);
+void ioprintf(std::ostream &out,const char *format,...) APT_PRINTF(2);
+void strprintf(std::string &out,const char *format,...) APT_PRINTF(2);
+char *safe_snprintf(char *Buffer,char *End,const char *Format,...) APT_PRINTF(3);
 bool CheckDomainList(const std::string &Host, const std::string &List);
-int tolower_ascii(int const c) __attrib_const __hot;
+int tolower_ascii(int const c) APT_CONST APT_HOT;
 std::string StripEpoch(const std::string &VerStr);
 
 #define APT_MKSTRCMP(name,func) \
-inline int name(const char *A,const char *B) {return func(A,A+strlen(A),B,B+strlen(B));}; \
-inline int name(const char *A,const char *AEnd,const char *B) {return func(A,AEnd,B,B+strlen(B));}; \
-inline int name(const std::string& A,const char *B) {return func(A.c_str(),A.c_str()+A.length(),B,B+strlen(B));}; \
-inline int name(const std::string& A,const std::string& B) {return func(A.c_str(),A.c_str()+A.length(),B.c_str(),B.c_str()+B.length());}; \
-inline int name(const std::string& A,const char *B,const char *BEnd) {return func(A.c_str(),A.c_str()+A.length(),B,BEnd);};
+inline APT_PURE int name(const char *A,const char *B) {return func(A,A+strlen(A),B,B+strlen(B));} \
+inline APT_PURE int name(const char *A,const char *AEnd,const char *B) {return func(A,AEnd,B,B+strlen(B));} \
+inline APT_PURE int name(const std::string& A,const char *B) {return func(A.c_str(),A.c_str()+A.length(),B,B+strlen(B));} \
+inline APT_PURE int name(const std::string& A,const std::string& B) {return func(A.c_str(),A.c_str()+A.length(),B.c_str(),B.c_str()+B.length());} \
+inline APT_PURE int name(const std::string& A,const char *B,const char *BEnd) {return func(A.c_str(),A.c_str()+A.length(),B,BEnd);}
 
 #define APT_MKSTRCMP2(name,func) \
-inline int name(const char *A,const char *AEnd,const char *B) {return func(A,AEnd,B,B+strlen(B));}; \
-inline int name(const std::string& A,const char *B) {return func(A.begin(),A.end(),B,B+strlen(B));}; \
-inline int name(const std::string& A,const std::string& B) {return func(A.begin(),A.end(),B.begin(),B.end());}; \
-inline int name(const std::string& A,const char *B,const char *BEnd) {return func(A.begin(),A.end(),B,BEnd);};
+inline APT_PURE int name(const char *A,const char *AEnd,const char *B) {return func(A,AEnd,B,B+strlen(B));} \
+inline APT_PURE int name(const std::string& A,const char *B) {return func(A.begin(),A.end(),B,B+strlen(B));} \
+inline APT_PURE int name(const std::string& A,const std::string& B) {return func(A.begin(),A.end(),B.begin(),B.end());} \
+inline APT_PURE int name(const std::string& A,const char *B,const char *BEnd) {return func(A.begin(),A.end(),B,BEnd);}
 
-int stringcmp(const char *A,const char *AEnd,const char *B,const char *BEnd);
-int stringcasecmp(const char *A,const char *AEnd,const char *B,const char *BEnd);
+int APT_PURE stringcmp(const char *A,const char *AEnd,const char *B,const char *BEnd);
+int APT_PURE stringcasecmp(const char *A,const char *AEnd,const char *B,const char *BEnd);
 
 /* We assume that GCC 3 indicates that libstdc++3 is in use too. In that
    case the definition of string::const_iterator is not the same as
    const char * and we need these extra functions */
 #if __GNUC__ >= 3
-int stringcmp(std::string::const_iterator A,std::string::const_iterator AEnd,
+int APT_PURE stringcmp(std::string::const_iterator A,std::string::const_iterator AEnd,
 	      const char *B,const char *BEnd);
-int stringcmp(std::string::const_iterator A,std::string::const_iterator AEnd,
+int APT_PURE stringcmp(std::string::const_iterator A,std::string::const_iterator AEnd,
 	      std::string::const_iterator B,std::string::const_iterator BEnd);
-int stringcasecmp(std::string::const_iterator A,std::string::const_iterator AEnd,
+int APT_PURE stringcasecmp(std::string::const_iterator A,std::string::const_iterator AEnd,
 		  const char *B,const char *BEnd);
-int stringcasecmp(std::string::const_iterator A,std::string::const_iterator AEnd,
+int APT_PURE stringcasecmp(std::string::const_iterator A,std::string::const_iterator AEnd,
                   std::string::const_iterator B,std::string::const_iterator BEnd);
 
-inline int stringcmp(std::string::const_iterator A,std::string::const_iterator Aend,const char *B) {return stringcmp(A,Aend,B,B+strlen(B));};
-inline int stringcasecmp(std::string::const_iterator A,std::string::const_iterator Aend,const char *B) {return stringcasecmp(A,Aend,B,B+strlen(B));};
+inline APT_PURE int stringcmp(std::string::const_iterator A,std::string::const_iterator Aend,const char *B) {return stringcmp(A,Aend,B,B+strlen(B));}
+inline APT_PURE int stringcasecmp(std::string::const_iterator A,std::string::const_iterator Aend,const char *B) {return stringcasecmp(A,Aend,B,B+strlen(B));}
 #endif
 
-APT_MKSTRCMP2(stringcmp,stringcmp);
-APT_MKSTRCMP2(stringcasecmp,stringcasecmp);
+APT_MKSTRCMP2(stringcmp,stringcmp)
+APT_MKSTRCMP2(stringcasecmp,stringcasecmp)
 
 // Return the length of a NULL-terminated string array
-size_t strv_length(const char **str_array);
+size_t APT_PURE strv_length(const char **str_array);
 
 
-inline const char *DeNull(const char *s) {return (s == 0?"(null)":s);};
+inline const char *DeNull(const char *s) {return (s == 0?"(null)":s);}
 
 class URI
 {
@@ -159,13 +162,13 @@ class URI
    unsigned int Port;
    
    operator std::string();
-   inline void operator =(const std::string &From) {CopyFrom(From);};
+   inline void operator =(const std::string &From) {CopyFrom(From);}
    inline bool empty() {return Access.empty();};
    static std::string SiteOnly(const std::string &URI);
    static std::string NoUserPassword(const std::string &URI);
    
-   URI(std::string Path) {CopyFrom(Path);};
-   URI() : Port(0) {};
+   URI(std::string Path) {CopyFrom(Path);}
+   URI() : Port(0) {}
 };
 
 struct SubstVar

+ 13 - 3
apt-pkg/deb/debindexfile.cc

@@ -15,7 +15,6 @@
 #include <apt-pkg/debsrcrecords.h>
 #include <apt-pkg/deblistparser.h>
 #include <apt-pkg/debrecords.h>
-#include <apt-pkg/sourcelist.h>
 #include <apt-pkg/configuration.h>
 #include <apt-pkg/progress.h>
 #include <apt-pkg/error.h>
@@ -23,7 +22,18 @@
 #include <apt-pkg/acquire-item.h>
 #include <apt-pkg/debmetaindex.h>
 #include <apt-pkg/gpgv.h>
-
+#include <apt-pkg/fileutl.h>
+#include <apt-pkg/indexfile.h>
+#include <apt-pkg/mmap.h>
+#include <apt-pkg/pkgcache.h>
+#include <apt-pkg/cacheiterators.h>
+#include <apt-pkg/pkgcachegen.h>
+#include <apt-pkg/pkgrecords.h>
+#include <apt-pkg/srcrecords.h>
+
+#include <stdio.h>
+#include <iostream>
+#include <string>
 #include <sys/stat.h>
 									/*}}}*/
 
@@ -650,7 +660,7 @@ pkgCache::PkgFileIterator debStatusIndex::FindInCache(pkgCache &Cache) const
 // StatusIndex::Exists - Check if the index is available		/*{{{*/
 // ---------------------------------------------------------------------
 /* */
-bool debStatusIndex::Exists() const
+APT_CONST bool debStatusIndex::Exists() const
 {
    // Abort if the file does not exist.
    return true;

+ 14 - 6
apt-pkg/deb/debindexfile.h

@@ -16,9 +16,17 @@
 #ifndef PKGLIB_DEBINDEXFILE_H
 #define PKGLIB_DEBINDEXFILE_H
 
+#include <apt-pkg/indexfile.h>
+#include <apt-pkg/cacheiterators.h>
+#include <apt-pkg/pkgcache.h>
+#include <apt-pkg/srcrecords.h>
 
+#include <string>
+
+class OpProgress;
+class pkgAcquire;
+class pkgCacheGenerator;
 
-#include <apt-pkg/indexfile.h>
 
 class debStatusIndex : public pkgIndexFile
 {
@@ -30,10 +38,10 @@ class debStatusIndex : public pkgIndexFile
 
    public:
 
-   virtual const Type *GetType() const;
+   virtual const Type *GetType() const APT_CONST;
    
    // Interface for acquire
-   virtual std::string Describe(bool Short) const {return File;};
+   virtual std::string Describe(bool /*Short*/) const {return File;};
    
    // Interface for the Cache Generator
    virtual bool Exists() const;
@@ -63,7 +71,7 @@ class debPackagesIndex : public pkgIndexFile
    
    public:
    
-   virtual const Type *GetType() const;
+   virtual const Type *GetType() const APT_CONST;
 
    // Stuff for accessing files on remote items
    virtual std::string ArchiveInfo(pkgCache::VerIterator Ver) const;
@@ -102,7 +110,7 @@ class debTranslationsIndex : public pkgIndexFile
 
    public:
    
-   virtual const Type *GetType() const;
+   virtual const Type *GetType() const APT_CONST;
 
    // Interface for acquire
    virtual std::string Describe(bool Short) const;   
@@ -134,7 +142,7 @@ class debSourcesIndex : public pkgIndexFile
    
    public:
 
-   virtual const Type *GetType() const;
+   virtual const Type *GetType() const APT_CONST;
 
    // Stuff for accessing files on remote items
    virtual std::string SourceInfo(pkgSrcRecords::Parser const &Record,

+ 148 - 30
apt-pkg/deb/deblistparser.cc

@@ -21,8 +21,17 @@
 #include <apt-pkg/fileutl.h>
 #include <apt-pkg/crc-16.h>
 #include <apt-pkg/md5.h>
+#include <apt-pkg/mmap.h>
+#include <apt-pkg/pkgcache.h>
+#include <apt-pkg/cacheiterators.h>
+#include <apt-pkg/tagfile.h>
 #include <apt-pkg/macros.h>
 
+#include <stddef.h>
+#include <string.h>
+#include <algorithm>
+#include <string>
+#include <vector>
 #include <ctype.h>
 									/*}}}*/
 
@@ -34,7 +43,7 @@ static debListParser::WordList PrioList[] = {
    {"standard",pkgCache::State::Standard},
    {"optional",pkgCache::State::Optional},
    {"extra",pkgCache::State::Extra},
-   {}};
+   {NULL, 0}};
 
 // ListParser::debListParser - Constructor				/*{{{*/
 // ---------------------------------------------------------------------
@@ -95,44 +104,49 @@ string debListParser::Version()
    return Section.FindS("Version");
 }
 									/*}}}*/
-// ListParser::NewVersion - Fill in the version structure		/*{{{*/
-// ---------------------------------------------------------------------
-/* */
-bool debListParser::NewVersion(pkgCache::VerIterator &Ver)
+unsigned char debListParser::ParseMultiArch(bool const showErrors)	/*{{{*/
 {
-   // Parse the section
-   Ver->Section = UniqFindTagWrite("Section");
-
-   // Parse multi-arch
+   unsigned char MA;
    string const MultiArch = Section.FindS("Multi-Arch");
    if (MultiArch.empty() == true)
-      Ver->MultiArch = pkgCache::Version::None;
+      MA = pkgCache::Version::None;
    else if (MultiArch == "same") {
-      // Parse multi-arch
       if (ArchitectureAll() == true)
       {
-	 /* Arch all packages can't be Multi-Arch: same */
-	 _error->Warning("Architecture: all package '%s' can't be Multi-Arch: same",
-			Section.FindS("Package").c_str());
-	 Ver->MultiArch = pkgCache::Version::None;
+	 if (showErrors == true)
+	    _error->Warning("Architecture: all package '%s' can't be Multi-Arch: same",
+		  Section.FindS("Package").c_str());
+	 MA = pkgCache::Version::None;
       }
       else
-	 Ver->MultiArch = pkgCache::Version::Same;
+	 MA = pkgCache::Version::Same;
    }
    else if (MultiArch == "foreign")
-      Ver->MultiArch = pkgCache::Version::Foreign;
+      MA = pkgCache::Version::Foreign;
    else if (MultiArch == "allowed")
-      Ver->MultiArch = pkgCache::Version::Allowed;
+      MA = pkgCache::Version::Allowed;
    else
    {
-      _error->Warning("Unknown Multi-Arch type '%s' for package '%s'",
-			MultiArch.c_str(), Section.FindS("Package").c_str());
-      Ver->MultiArch = pkgCache::Version::None;
+      if (showErrors == true)
+	 _error->Warning("Unknown Multi-Arch type '%s' for package '%s'",
+	       MultiArch.c_str(), Section.FindS("Package").c_str());
+      MA = pkgCache::Version::None;
    }
 
    if (ArchitectureAll() == true)
-      Ver->MultiArch |= pkgCache::Version::All;
+      MA |= pkgCache::Version::All;
 
+   return MA;
+}
+									/*}}}*/
+// ListParser::NewVersion - Fill in the version structure		/*{{{*/
+// ---------------------------------------------------------------------
+/* */
+bool debListParser::NewVersion(pkgCache::VerIterator &Ver)
+{
+   // Parse the section
+   Ver->Section = UniqFindTagWrite("Section");
+   Ver->MultiArch = ParseMultiArch(true);
    // Archive Size
    Ver->Size = Section.FindULL("Size");
    // Unpacked Size (in K)
@@ -354,7 +368,7 @@ bool debListParser::ParseStatus(pkgCache::PkgIterator &Pkg,
                           {"hold",pkgCache::State::Hold},
                           {"deinstall",pkgCache::State::DeInstall},
                           {"purge",pkgCache::State::Purge},
-                          {}};
+                          {NULL, 0}};
    if (GrabWord(string(Start,I-Start),WantList,Pkg->SelectedState) == false)
       return _error->Error("Malformed 1st word in the Status line");
 
@@ -370,7 +384,7 @@ bool debListParser::ParseStatus(pkgCache::PkgIterator &Pkg,
                           {"reinstreq",pkgCache::State::ReInstReq},
                           {"hold",pkgCache::State::HoldInst},
                           {"hold-reinstreq",pkgCache::State::HoldReInstReq},
-                          {}};
+                          {NULL, 0}};
    if (GrabWord(string(Start,I-Start),FlagList,Pkg->InstState) == false)
       return _error->Error("Malformed 2nd word in the Status line");
 
@@ -392,7 +406,7 @@ bool debListParser::ParseStatus(pkgCache::PkgIterator &Pkg,
                             {"triggers-pending",pkgCache::State::TriggersPending},
                             {"post-inst-failed",pkgCache::State::HalfConfigured},
                             {"removal-failed",pkgCache::State::HalfInstalled},
-                            {}};
+                            {NULL, 0}};
    if (GrabWord(string(Start,I-Start),StatusList,Pkg->CurrentState) == false)
       return _error->Error("Malformed 3rd word in the Status line");
 
@@ -474,18 +488,31 @@ const char *debListParser::ConvertRelation(const char *I,unsigned int &Op)
 // ---------------------------------------------------------------------
 /* This parses the dependency elements out of a standard string in place,
    bit by bit. */
+const char *debListParser::ParseDepends(const char *Start,const char *Stop,
+               std::string &Package,std::string &Ver,unsigned int &Op)
+   { return ParseDepends(Start, Stop, Package, Ver, Op, false, true, false); }
+const char *debListParser::ParseDepends(const char *Start,const char *Stop,
+               std::string &Package,std::string &Ver,unsigned int &Op,
+               bool const &ParseArchFlags)
+   { return ParseDepends(Start, Stop, Package, Ver, Op, ParseArchFlags, true, false); }
+const char *debListParser::ParseDepends(const char *Start,const char *Stop,
+               std::string &Package,std::string &Ver,unsigned int &Op,
+               bool const &ParseArchFlags, bool const &StripMultiArch)
+   { return ParseDepends(Start, Stop, Package, Ver, Op, ParseArchFlags, StripMultiArch, false); }
 const char *debListParser::ParseDepends(const char *Start,const char *Stop,
 					string &Package,string &Ver,
 					unsigned int &Op, bool const &ParseArchFlags,
-					bool const &StripMultiArch)
+					bool const &StripMultiArch,
+					bool const &ParseRestrictionsList)
 {
    // Strip off leading space
-   for (;Start != Stop && isspace(*Start) != 0; Start++);
+   for (;Start != Stop && isspace(*Start) != 0; ++Start);
    
    // Parse off the package name
    const char *I = Start;
    for (;I != Stop && isspace(*I) == 0 && *I != '(' && *I != ')' &&
-	*I != ',' && *I != '|' && *I != '[' && *I != ']'; I++);
+	*I != ',' && *I != '|' && *I != '[' && *I != ']' &&
+	*I != '<' && *I != '>'; ++I);
    
    // Malformed, no '('
    if (I != Stop && *I == ')')
@@ -602,6 +629,76 @@ const char *debListParser::ParseDepends(const char *Start,const char *Stop,
       for (;I != Stop && isspace(*I) != 0; I++);
    }
 
+   if (ParseRestrictionsList == true)
+   {
+      // Parse a restrictions list
+      if (I != Stop && *I == '<')
+      {
+	 ++I;
+	 // malformed
+	 if (unlikely(I == Stop))
+	    return 0;
+
+	 std::vector<string> const profiles = APT::Configuration::getBuildProfiles();
+
+	 const char *End = I;
+	 bool Found = false;
+	 bool NegRestriction = false;
+	 while (I != Stop)
+	 {
+	    // look for whitespace or ending '>'
+	    for (;End != Stop && !isspace(*End) && *End != '>'; ++End);
+
+	    if (unlikely(End == Stop))
+	       return 0;
+
+	    if (*I == '!')
+	    {
+	       NegRestriction = true;
+	       ++I;
+	    }
+
+	    std::string restriction(I, End);
+
+	    std::string prefix = "profile.";
+	    // only support for "profile" prefix, ignore others
+	    if (restriction.size() > prefix.size() &&
+		  restriction.substr(0, prefix.size()) == prefix)
+	    {
+	       // get the name of the profile
+	       restriction = restriction.substr(prefix.size());
+
+	       if (restriction.empty() == false && profiles.empty() == false &&
+		     std::find(profiles.begin(), profiles.end(), restriction) != profiles.end())
+	       {
+		  Found = true;
+		  if (I[-1] != '!')
+		     NegRestriction = false;
+		  // we found a match, so fast-forward to the end of the wildcards
+		  for (; End != Stop && *End != '>'; ++End);
+	       }
+	    }
+
+	    if (*End++ == '>') {
+	       I = End;
+	       break;
+	    }
+
+	    I = End;
+	    for (;I != Stop && isspace(*I) != 0; I++);
+	 }
+
+	 if (NegRestriction == true)
+	    Found = !Found;
+
+	 if (Found == false)
+	    Package = ""; /* not for this restriction */
+      }
+
+      // Skip whitespace
+      for (;I != Stop && isspace(*I) != 0; I++);
+   }
+
    if (I != Stop && *I == '|')
       Op |= pkgCache::Dep::Or;
    
@@ -635,7 +732,7 @@ bool debListParser::ParseDepends(pkgCache::VerIterator &Ver,
       string Version;
       unsigned int Op;
 
-      Start = ParseDepends(Start, Stop, Package, Version, Op, false, false);
+      Start = ParseDepends(Start, Stop, Package, Version, Op, false, false, false);
       if (Start == 0)
 	 return _error->Error("Problem parsing dependency %s",Tag);
       size_t const found = Package.rfind(':');
@@ -758,7 +855,7 @@ bool debListParser::GrabWord(string Word,WordList *List,unsigned char &Out)
 									/*}}}*/
 // ListParser::Step - Move to the next section in the file		/*{{{*/
 // ---------------------------------------------------------------------
-/* This has to be carefull to only process the correct architecture */
+/* This has to be careful to only process the correct architecture */
 bool debListParser::Step()
 {
    iOffset = Tags.Offset();
@@ -841,3 +938,24 @@ unsigned char debListParser::GetPrio(string Str)
    return Out;
 }
 									/*}}}*/
+#if (APT_PKG_MAJOR >= 4 && APT_PKG_MINOR >= 13)
+bool debListParser::SameVersion(unsigned short const Hash,		/*{{{*/
+      pkgCache::VerIterator const &Ver)
+{
+   if (pkgCacheGenerator::ListParser::SameVersion(Hash, Ver) == false)
+      return false;
+   // status file has no (Download)Size, but all others are fair game
+   // status file is parsed last, so the first version we encounter is
+   // probably also the version we have downloaded
+   unsigned long long const Size = Section.FindULL("Size");
+   if (Size != 0 && Size != Ver->Size)
+      return false;
+   // available everywhere, but easier to check here than to include in VersionHash
+   unsigned char MultiArch = ParseMultiArch(false);
+   if (MultiArch != Ver->MultiArch)
+      return false;
+   // for all practical proposes (we can check): same version
+   return true;
+}
+									/*}}}*/
+#endif

+ 27 - 4
apt-pkg/deb/deblistparser.h

@@ -13,11 +13,19 @@
 
 #include <apt-pkg/pkgcachegen.h>
 #include <apt-pkg/tagfile.h>
+#include <apt-pkg/md5.h>
+#include <apt-pkg/pkgcache.h>
+#include <apt-pkg/macros.h>
+
+#include <string>
+#include <vector>
 
 #ifndef APT_8_CLEANER_HEADERS
 #include <apt-pkg/indexfile.h>
 #endif
 
+class FileFd;
+
 class debListParser : public pkgCacheGenerator::ListParser
 {
    public:
@@ -63,6 +71,9 @@ class debListParser : public pkgCacheGenerator::ListParser
    virtual std::string DescriptionLanguage();
    virtual MD5SumValue Description_md5();
    virtual unsigned short VersionHash();
+#if (APT_PKG_MAJOR >= 4 && APT_PKG_MINOR >= 13)
+   virtual bool SameVersion(unsigned short const Hash, pkgCache::VerIterator const &Ver);
+#endif
    virtual bool UsePackage(pkgCache::PkgIterator &Pkg,
 			   pkgCache::VerIterator &Ver);
    virtual unsigned long Offset() {return iOffset;};
@@ -72,15 +83,27 @@ class debListParser : public pkgCacheGenerator::ListParser
    
    bool LoadReleaseInfo(pkgCache::PkgFileIterator &FileI,FileFd &File,
 			std::string section);
-   
+
+   static const char *ParseDepends(const char *Start,const char *Stop,
+	 std::string &Package,std::string &Ver,unsigned int &Op);
    static const char *ParseDepends(const char *Start,const char *Stop,
-			    std::string &Package,std::string &Ver,unsigned int &Op,
-			    bool const &ParseArchFlags = false,
-			    bool const &StripMultiArch = true);
+	 std::string &Package,std::string &Ver,unsigned int &Op,
+	 bool const &ParseArchFlags);
+   static const char *ParseDepends(const char *Start,const char *Stop,
+	 std::string &Package,std::string &Ver,unsigned int &Op,
+	 bool const &ParseArchFlags, bool const &StripMultiArch);
+   static const char *ParseDepends(const char *Start,const char *Stop,
+	 std::string &Package,std::string &Ver,unsigned int &Op,
+	 bool const &ParseArchFlags, bool const &StripMultiArch,
+	 bool const &ParseRestrictionsList);
+
    static const char *ConvertRelation(const char *I,unsigned int &Op);
 
    debListParser(FileFd *File, std::string const &Arch = "");
    virtual ~debListParser() {};
+
+   private:
+   APT_HIDDEN unsigned char ParseMultiArch(bool const showErrors);
 };
 
 #endif

+ 9 - 2
apt-pkg/deb/debmetaindex.cc

@@ -9,8 +9,15 @@
 #include <apt-pkg/aptconfiguration.h>
 #include <apt-pkg/indexrecords.h>
 #include <apt-pkg/sourcelist.h>
-#include <apt-pkg/error.h>
-
+#include <apt-pkg/hashes.h>
+#include <apt-pkg/macros.h>
+#include <apt-pkg/metaindex.h>
+
+#include <string.h>
+#include <map>
+#include <string>
+#include <utility>
+#include <vector>
 #include <set>
 #include <algorithm>
 

+ 7 - 1
apt-pkg/deb/debmetaindex.h

@@ -3,7 +3,7 @@
 #define PKGLIB_DEBMETAINDEX_H
 
 #include <apt-pkg/metaindex.h>
-#include <apt-pkg/init.h>
+#include <apt-pkg/macros.h>
 
 #include <map>
 #include <string>
@@ -12,6 +12,12 @@
 #ifndef APT_8_CLEANER_HEADERS
 #include <apt-pkg/sourcelist.h>
 #endif
+#ifndef APT_10_CLEANER_HEADERS
+#include <apt-pkg/init.h>
+#endif
+
+class pkgAcquire;
+class pkgIndexFile;
 
 class debReleaseIndex : public metaIndex {
    public:

+ 7 - 1
apt-pkg/deb/debrecords.cc

@@ -12,10 +12,16 @@
 
 #include <apt-pkg/debrecords.h>
 #include <apt-pkg/strutl.h>
-#include <apt-pkg/error.h>
 #include <apt-pkg/aptconfiguration.h>
 #include <apt-pkg/fileutl.h>
+#include <apt-pkg/cacheiterators.h>
+#include <apt-pkg/pkgcache.h>
+#include <apt-pkg/tagfile.h>
 
+#include <string.h>
+#include <algorithm>
+#include <string>
+#include <vector>
 #include <langinfo.h>
 									/*}}}*/
 

+ 3 - 0
apt-pkg/deb/debrecords.h

@@ -17,6 +17,9 @@
 #include <apt-pkg/pkgrecords.h>
 #include <apt-pkg/tagfile.h>
 #include <apt-pkg/fileutl.h>
+#include <apt-pkg/pkgcache.h>
+
+#include <string>
 
 #ifndef APT_8_CLEANER_HEADERS
 #include <apt-pkg/indexfile.h>

+ 11 - 4
apt-pkg/deb/debsrcrecords.cc

@@ -15,12 +15,19 @@
 #include <apt-pkg/debsrcrecords.h>
 #include <apt-pkg/error.h>
 #include <apt-pkg/strutl.h>
-#include <apt-pkg/configuration.h>
 #include <apt-pkg/aptconfiguration.h>
+#include <apt-pkg/srcrecords.h>
+#include <apt-pkg/tagfile.h>
 
-using std::max;
+#include <ctype.h>
+#include <stdlib.h>
+#include <string.h>
+#include <algorithm>
+#include <string>
+#include <vector>
 									/*}}}*/
 
+using std::max;
 using std::string;
 
 // SrcRecordParser::Binaries - Return the binaries field		/*{{{*/
@@ -57,7 +64,7 @@ const char **debSrcRecordParser::Binaries()
    } while (*bin != '\0');
    StaticBinList.push_back(NULL);
 
-   return (const char **) &StaticBinList[0];
+   return &StaticBinList[0];
 }
 									/*}}}*/
 // SrcRecordParser::BuildDepends - Return the Build-Depends information	/*{{{*/
@@ -90,7 +97,7 @@ bool debSrcRecordParser::BuildDepends(std::vector<pkgSrcRecords::Parser::BuildDe
       while (1)
       {
          Start = debListParser::ParseDepends(Start, Stop, 
-		     rec.Package,rec.Version,rec.Op,true, StripMultiArch);
+		     rec.Package,rec.Version,rec.Op,true,StripMultiArch,true);
 	 
          if (Start == 0) 
             return _error->Error("Problem parsing dependency: %s", fields[I]);

+ 9 - 4
apt-pkg/deb/debsrcrecords.h

@@ -11,11 +11,16 @@
 #ifndef PKGLIB_DEBSRCRECORDS_H
 #define PKGLIB_DEBSRCRECORDS_H
 
-
 #include <apt-pkg/srcrecords.h>
 #include <apt-pkg/tagfile.h>
 #include <apt-pkg/fileutl.h>
 
+#include <stddef.h>
+#include <string>
+#include <vector>
+
+class pkgIndexFile;
+
 class debSrcRecordParser : public pkgSrcRecords::Parser
 {
    /** \brief dpointer placeholder (for later in case we need it) */
@@ -30,7 +35,7 @@ class debSrcRecordParser : public pkgSrcRecords::Parser
    
    public:
 
-   virtual bool Restart() {return Tags.Jump(Sect,0);};
+   virtual bool Restart() {return Jump(0);};
    virtual bool Step() {iOffset = Tags.Offset(); return Tags.Step(Sect);};
    virtual bool Jump(unsigned long const &Off) {iOffset = Off; return Tags.Jump(Sect,Off);};
 
@@ -50,8 +55,8 @@ class debSrcRecordParser : public pkgSrcRecords::Parser
    virtual bool Files(std::vector<pkgSrcRecords::File> &F);
 
    debSrcRecordParser(std::string const &File,pkgIndexFile const *Index) 
-      : Parser(Index), Fd(File,FileFd::ReadOnly, FileFd::Extension), Tags(&Fd,102400), 
-        Buffer(NULL) {}
+      : Parser(Index), Fd(File,FileFd::ReadOnly, FileFd::Extension), Tags(&Fd,102400),
+        iOffset(0), Buffer(NULL) {}
    virtual ~debSrcRecordParser();
 };
 

+ 10 - 3
apt-pkg/deb/debsystem.cc

@@ -19,7 +19,14 @@
 #include <apt-pkg/configuration.h>
 #include <apt-pkg/error.h>
 #include <apt-pkg/fileutl.h>
-#include <sys/types.h>
+#include <apt-pkg/pkgcache.h>
+#include <apt-pkg/cacheiterators.h>
+
+#include <ctype.h>
+#include <stdlib.h>
+#include <string.h>
+#include <string>
+#include <vector>
 #include <unistd.h>
 #include <dirent.h>
 #include <errno.h>
@@ -193,9 +200,9 @@ bool debSystem::Initialize(Configuration &Cnf)
 									/*}}}*/
 // System::ArchiveSupported - Is a file format supported		/*{{{*/
 // ---------------------------------------------------------------------
-/* The standard name for a deb is 'deb'.. There are no seperate versions
+/* The standard name for a deb is 'deb'.. There are no separate versions
    of .deb to worry about.. */
-bool debSystem::ArchiveSupported(const char *Type)
+APT_PURE bool debSystem::ArchiveSupported(const char *Type)
 {
    if (strcmp(Type,"deb") == 0)
       return true;

+ 9 - 1
apt-pkg/deb/debsystem.h

@@ -12,11 +12,19 @@
 
 #include <apt-pkg/pkgsystem.h>
 #include <apt-pkg/pkgcache.h>
+#include <apt-pkg/cacheiterators.h>
 
+#include <vector>
+class Configuration;
+class pkgIndexFile;
+class pkgPackageManager;
 class debSystemPrivate;
-class debStatusIndex;
 class pkgDepCache;
 
+#ifndef APT_10_CLEANER_HEADERS
+class debStatusIndex;
+#endif
+
 class debSystem : public pkgSystem
 {
    // private d-pointer

+ 4 - 2
apt-pkg/deb/debversion.cc

@@ -15,6 +15,8 @@
 #include <apt-pkg/debversion.h>
 #include <apt-pkg/pkgcache.h>
 
+#include <string.h>
+#include <string>
 #include <stdlib.h>
 #include <ctype.h>
 									/*}}}*/
@@ -116,7 +118,7 @@ int debVersioningSystem::CmpFragment(const char *A,const char *AEnd,
       return 1;
    }
 
-   // Shouldnt happen
+   // Shouldn't happen
    return 1;
 }
 									/*}}}*/
@@ -221,7 +223,7 @@ bool debVersioningSystem::CheckDep(const char *PkgVer,
    if (PkgVer == DepVer)
       return Op == pkgCache::Dep::Equals || Op == pkgCache::Dep::LessEq || Op == pkgCache::Dep::GreaterEq;
 
-   // Perform the actual comparision.
+   // Perform the actual comparison.
    int const Res = CmpVersion(PkgVer, DepVer);
    switch (Op)
    {

+ 10 - 10
apt-pkg/deb/debversion.h

@@ -12,26 +12,26 @@
 #ifndef PKGLIB_DEBVERSION_H
 #define PKGLIB_DEBVERSION_H
 
+#include <apt-pkg/version.h>
 
+#include <string>
 
-#include <apt-pkg/version.h>
-    
 class debVersioningSystem : public pkgVersioningSystem
-{     
+{
    public:
-   
+
    static int CmpFragment(const char *A, const char *AEnd, const char *B,
-			  const char *BEnd);
-   
+			  const char *BEnd) APT_PURE;
+
    // Compare versions..
    virtual int DoCmpVersion(const char *A,const char *Aend,
-			  const char *B,const char *Bend);
-   virtual bool CheckDep(const char *PkgVer,int Op,const char *DepVer);
-   virtual int DoCmpReleaseVer(const char *A,const char *Aend,
+			  const char *B,const char *Bend) APT_PURE;
+   virtual bool CheckDep(const char *PkgVer,int Op,const char *DepVer) APT_PURE;
+   virtual APT_PURE int DoCmpReleaseVer(const char *A,const char *Aend,
 			     const char *B,const char *Bend)
    {
       return DoCmpVersion(A,Aend,B,Bend);
-   }   
+   }
    virtual std::string UpstreamVersion(const char *A);
 
    debVersioningSystem();

+ 58 - 57
apt-pkg/deb/dpkgpm.cc

@@ -10,41 +10,45 @@
 // Includes								/*{{{*/
 #include <config.h>
 
-#include <apt-pkg/dpkgpm.h>
-#include <apt-pkg/error.h>
+#include <apt-pkg/cachefile.h>
 #include <apt-pkg/configuration.h>
 #include <apt-pkg/depcache.h>
-#include <apt-pkg/pkgrecords.h>
-#include <apt-pkg/strutl.h>
+#include <apt-pkg/dpkgpm.h>
+#include <apt-pkg/error.h>
 #include <apt-pkg/fileutl.h>
-#include <apt-pkg/cachefile.h>
-#include <apt-pkg/packagemanager.h>
 #include <apt-pkg/install-progress.h>
+#include <apt-pkg/packagemanager.h>
+#include <apt-pkg/pkgrecords.h>
+#include <apt-pkg/strutl.h>
+#include <apt-pkg/cacheiterators.h>
+#include <apt-pkg/macros.h>
+#include <apt-pkg/pkgcache.h>
 
-#include <unistd.h>
-#include <stdlib.h>
+#include <errno.h>
 #include <fcntl.h>
+#include <grp.h>
+#include <pty.h>
+#include <pwd.h>
+#include <signal.h>
+#include <stddef.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <sys/ioctl.h>
 #include <sys/select.h>
 #include <sys/stat.h>
-#include <sys/types.h>
+#include <sys/time.h>
 #include <sys/wait.h>
-#include <signal.h>
-#include <errno.h>
-#include <string.h>
-#include <stdio.h>
-#include <string.h>
-#include <algorithm>
-#include <sstream>
-#include <map>
-#include <pwd.h>
-#include <grp.h>
-#include <iomanip>
-
 #include <termios.h>
+#include <time.h>
 #include <unistd.h>
-#include <sys/ioctl.h>
-#include <pty.h>
-#include <stdio.h>
+#include <algorithm>
+#include <cstring>
+#include <iostream>
+#include <map>
+#include <set>
+#include <string>
+#include <utility>
+#include <vector>
 
 #include <apti18n.h>
 									/*}}}*/
@@ -568,7 +572,6 @@ void pkgDPkgPM::ProcessDpkgStatusLine(char *line)
    std::string prefix = APT::String::Strip(list[0]);
    std::string pkgname;
    std::string action;
-   ostringstream status;
 
    // "processing" has the form "processing: action: pkg or trigger"
    // with action = ["install", "configure", "remove", "purge", "disappear",
@@ -1028,6 +1031,12 @@ bool pkgDPkgPM::Go(int StatusFd)
 
 void pkgDPkgPM::StartPtyMagic()
 {
+   if (_config->FindB("Dpkg::Use-Pty", true) == false)
+   {
+      d->master = d->slave = -1;
+      return;
+   }
+
    // setup the pty and stuff
    struct	winsize win;
 
@@ -1036,10 +1045,9 @@ void pkgDPkgPM::StartPtyMagic()
    _error->PushToStack();
    if (tcgetattr(STDOUT_FILENO, &d->tt) == 0)
    {
-       ioctl(1, TIOCGWINSZ, (char *)&win);
-       if (_config->FindB("Dpkg::Use-Pty", true) == false)
+       if (ioctl(1, TIOCGWINSZ, (char *)&win) < 0)
        {
-           d->master = d->slave = -1;
+           _error->Errno("ioctl", _("ioctl(TIOCGWINSZ) failed"));
        } else if (openpty(&d->master, &d->slave, NULL, &d->tt, &win) < 0)
        {
            _error->Errno("openpty", _("Can not write log (%s)"), _("Is /dev/pts mounted?"));
@@ -1393,12 +1401,17 @@ bool pkgDPkgPM::GoNoABIBreak(APT::Progress::PackageManager *progress)
 	 if(d->slave >= 0 && d->master >= 0) 
 	 {
 	    setsid();
-	    ioctl(d->slave, TIOCSCTTY, 0);
-	    close(d->master);
-	    dup2(d->slave, 0);
-	    dup2(d->slave, 1);
-	    dup2(d->slave, 2);
-	    close(d->slave);
+	    int res = ioctl(d->slave, TIOCSCTTY, 0);
+            if (res < 0) {
+               std::cerr << "ioctl(TIOCSCTTY) failed for fd: " 
+                         << d->slave << std::endl;
+            } else {
+               close(d->master);
+               dup2(d->slave, 0);
+               dup2(d->slave, 1);
+               dup2(d->slave, 2);
+               close(d->slave);
+            }
 	 }
 	 close(fd[0]); // close the read end of the pipe
 
@@ -1517,28 +1530,18 @@ bool pkgDPkgPM::GoNoABIBreak(APT::Progress::PackageManager *progress)
 	 // here but keep the loop going and just report it as a error
 	 // for later
 	 bool const stopOnError = _config->FindB("Dpkg::StopOnError",true);
-	 
-	 if(stopOnError)
-	    RunScripts("DPkg::Post-Invoke");
 
-	 if (WIFSIGNALED(Status) != 0 && WTERMSIG(Status) == SIGSEGV) 
+	 if (WIFSIGNALED(Status) != 0 && WTERMSIG(Status) == SIGSEGV)
 	    strprintf(d->dpkg_error, "Sub-process %s received a segmentation fault.",Args[0]);
 	 else if (WIFEXITED(Status) != 0)
 	    strprintf(d->dpkg_error, "Sub-process %s returned an error code (%u)",Args[0],WEXITSTATUS(Status));
-	 else 
+	 else
 	    strprintf(d->dpkg_error, "Sub-process %s exited unexpectedly",Args[0]);
+	 _error->Error("%s", d->dpkg_error.c_str());
 
-	 if(d->dpkg_error.size() > 0)
-	    _error->Error("%s", d->dpkg_error.c_str());
-
-	 if(stopOnError) 
-	 {
-	    CloseLog();
-            StopPtyMagic();
-            d->progress->Stop();
-	    return false;
-	 }
-      }      
+	 if(stopOnError)
+	    break;
+      }
    }
    // dpkg is done at this point
    d->progress->Stop();
@@ -1569,10 +1572,10 @@ bool pkgDPkgPM::GoNoABIBreak(APT::Progress::PackageManager *progress)
    }
 
    Cache.writeStateFile(NULL);
-   return true;
+   return d->dpkg_error.empty();
 }
 
-void SigINT(int sig) {
+void SigINT(int /*sig*/) {
    pkgPackageManager::SigINTStop = true;
 }
 									/*}}}*/
@@ -1652,7 +1655,7 @@ void pkgDPkgPM::WriteApportReport(const char *pkgpath, const char *errormsg)
    io_errors.push_back(string("failed in write on buffer copy for %s"));
    io_errors.push_back(string("short read on buffer copy for %s"));
 
-   for (vector<string>::iterator I = io_errors.begin(); I != io_errors.end(); I++)
+   for (vector<string>::iterator I = io_errors.begin(); I != io_errors.end(); ++I)
    {
       vector<string> list = VectorizeString(dgettext("dpkg", (*I).c_str()), '%');
       if (list.size() > 1) {
@@ -1767,13 +1770,11 @@ void pkgDPkgPM::WriteApportReport(const char *pkgpath, const char *errormsg)
    string histfile_name = _config->FindFile("Dir::Log::History");
    if (!histfile_name.empty())
    {
-      FILE *log = NULL;
-      char buf[1024];
-
       fprintf(report, "DpkgHistoryLog:\n");
-      log = fopen(histfile_name.c_str(),"r");
+      FILE* log = fopen(histfile_name.c_str(),"r");
       if(log != NULL)
       {
+	 char buf[1024];
 	 while( fgets(buf, sizeof(buf), log) != NULL)
 	    fprintf(report, " %s", buf);
 	 fclose(log);

+ 13 - 4
apt-pkg/deb/dpkgpm.h

@@ -11,11 +11,20 @@
 #define PKGLIB_DPKGPM_H
 
 #include <apt-pkg/packagemanager.h>
+#include <apt-pkg/pkgcache.h>
+#include <apt-pkg/macros.h>
+
 #include <vector>
 #include <map>
 #include <stdio.h>
-#include <apt-pkg/macros.h>
+#include <string>
+
+#ifndef APT_10_CLEANER_HEADERS
 #include <apt-pkg/init.h>
+#endif
+
+class pkgDepCache;
+namespace APT { namespace Progress { class PackageManager; } }
 
 #ifndef APT_8_CLEANER_HEADERS
 using std::vector;
@@ -82,7 +91,7 @@ class pkgDPkgPM : public pkgPackageManager
 
    // Helpers
    bool RunScriptsWithPkgs(const char *Cnf);
-   __deprecated bool SendV2Pkgs(FILE *F);
+   APT_DEPRECATED bool SendV2Pkgs(FILE *F);
    bool SendPkgsInfo(FILE * const F, unsigned int const &Version);
    void WriteHistoryTag(std::string const &tag, std::string value);
    std::string ExpandShortPackageName(pkgDepCache &Cache,
@@ -109,10 +118,10 @@ class pkgDPkgPM : public pkgPackageManager
    void DoDpkgStatusFd(int statusfd);
    void ProcessDpkgStatusLine(char *line);
 #if (APT_PKG_MAJOR >= 4 && APT_PKG_MINOR < 13)
-   void DoDpkgStatusFd(int statusfd, int unused) {
+   void DoDpkgStatusFd(int statusfd, int /*unused*/) {
       DoDpkgStatusFd(statusfd);
    }
-   void ProcessDpkgStatusLine(int unused, char *line) {
+   void ProcessDpkgStatusLine(int /*unused*/, char *line) {
       ProcessDpkgStatusLine(line);
    }
 #endif

+ 92 - 34
apt-pkg/depcache.cc

@@ -11,20 +11,26 @@
 #include<config.h>
 
 #include <apt-pkg/depcache.h>
-#include <apt-pkg/version.h>
 #include <apt-pkg/versionmatch.h>
 #include <apt-pkg/error.h>
 #include <apt-pkg/sptr.h>
-#include <apt-pkg/algorithms.h>
 #include <apt-pkg/fileutl.h>
 #include <apt-pkg/strutl.h>
 #include <apt-pkg/configuration.h>
 #include <apt-pkg/aptconfiguration.h>
-#include <apt-pkg/pkgsystem.h>
 #include <apt-pkg/tagfile.h>
 #include <apt-pkg/progress.h>
 #include <apt-pkg/cacheset.h>
-
+#include <apt-pkg/pkgcache.h>
+#include <apt-pkg/cacheiterators.h>
+#include <apt-pkg/macros.h>
+
+#include <stdio.h>
+#include <string.h>
+#include <list>
+#include <string>
+#include <utility>
+#include <vector>
 #include <algorithm>
 #include <iostream>
 #include <sstream>
@@ -222,7 +228,7 @@ bool pkgDepCache::readStateFile(OpProgress *Prog)			/*{{{*/
    return true;
 }
 									/*}}}*/
-bool pkgDepCache::writeStateFile(OpProgress *prog, bool InstalledOnly)	/*{{{*/
+bool pkgDepCache::writeStateFile(OpProgress * /*prog*/, bool InstalledOnly)	/*{{{*/
 {
    bool const debug_autoremove = _config->FindB("Debug::pkgAutoRemove",false);
    
@@ -789,7 +795,7 @@ bool pkgDepCache::MarkKeep(PkgIterator const &Pkg, bool Soft, bool FromUser,
       // - this makes sense as default when all Garbage dependencies
       //   are automatically marked for removal (as aptitude does).
       //   setting a package for keep then makes it no longer autoinstalled
-      //   for all other use-case this action is rather suprising
+      //   for all other use-case this action is rather surprising
    if(FromUser && !P.Marked)
      P.Flags &= ~Flag::Auto;
 #endif
@@ -868,7 +874,7 @@ bool pkgDepCache::IsDeleteOk(PkgIterator const &Pkg,bool rPurge,
    return IsDeleteOkProtectInstallRequests(Pkg, rPurge, Depth, FromUser);
 }
 bool pkgDepCache::IsDeleteOkProtectInstallRequests(PkgIterator const &Pkg,
-      bool const rPurge, unsigned long const Depth, bool const FromUser)
+      bool const /*rPurge*/, unsigned long const Depth, bool const FromUser)
 {
    if (FromUser == false && Pkg->CurrentVer == 0)
    {
@@ -889,7 +895,7 @@ bool pkgDepCache::IsDeleteOkProtectInstallRequests(PkgIterator const &Pkg,
    and prevents mode changes for packages on hold for example.
    If you want to check Mode specific stuff you can use the virtual public
    Is<Mode>Ok methods instead */
-char const* PrintMode(char const mode)
+static char const* PrintMode(char const mode)
 {
 	 switch (mode)
 	 {
@@ -1053,10 +1059,9 @@ bool pkgDepCache::MarkInstall(PkgIterator const &Pkg,bool AutoInst,
       return true;
    }
 
-   // check if we are allowed to install the package (if we haven't already)
-   if (P.Mode != ModeInstall || P.InstallVer != P.CandidateVer)
-      if (IsInstallOk(Pkg,AutoInst,Depth,FromUser) == false)
-	 return false;
+   // check if we are allowed to install the package
+   if (IsInstallOk(Pkg,AutoInst,Depth,FromUser) == false)
+      return false;
 
    ActionGroup group(*this);
    P.iFlags &= ~AutoKept;
@@ -1117,27 +1122,22 @@ bool pkgDepCache::MarkInstall(PkgIterator const &Pkg,bool AutoInst,
 	 continue;
 
       /* Check if this dep should be consider for install. If it is a user
-         defined important dep and we are installed a new package then 
+         defined important dep and we are installed a new package then
 	 it will be installed. Otherwise we only check for important
-         deps that have changed from the installed version
-      */
+         deps that have changed from the installed version */
       if (IsImportantDep(Start) == false)
 	 continue;
 
-      /* If we are in an or group locate the first or that can 
-         succeed. We have already cached this.. */
+      /* If we are in an or group locate the first or that can
+         succeed. We have already cached this */
       for (; Ors > 1 && (DepState[Start->ID] & DepCVer) != DepCVer; --Ors)
 	 ++Start;
+
+      /* unsatisfiable dependency: IsInstallOkDependenciesSatisfiableByCandidates
+         would have prevented us to get here if not overridden, so just skip
+	 over the problem here as the frontend will know what it is doing */
       if (Ors == 1 && (DepState[Start->ID] &DepCVer) != DepCVer && Start.IsNegative() == false)
-      {
-	 if(DebugAutoInstall == true)
-	    std::clog << OutputInDepth(Depth) << Start << " can't be satisfied!" << std::endl;
-	 if (Start.IsCritical() == false)
-	    continue;
-	 // if the dependency was critical, we can't install it, so remove it again
-	 MarkDelete(Pkg,false,Depth + 1, false);
-	 return false;
-      }
+	 continue;
 
       /* Check if any ImportantDep() (but not Critical) were added
        * since we installed the package.  Also check for deps that
@@ -1190,7 +1190,7 @@ bool pkgDepCache::MarkInstall(PkgIterator const &Pkg,bool AutoInst,
 	 }
       }
 
-      /* This bit is for processing the possibilty of an install/upgrade
+      /* This bit is for processing the possibility of an install/upgrade
          fixing the problem for "positive" dependencies */
       if (Start.IsNegative() == false && (DepState[Start->ID] & DepCVer) == DepCVer)
       {
@@ -1253,6 +1253,11 @@ bool pkgDepCache::MarkInstall(PkgIterator const &Pkg,bool AutoInst,
 	    if (PkgState[Pkg->ID].InstallVer == 0)
 	       continue;
 
+            /* Ignore negative dependencies that we are not going to 
+               get installed */
+            if (PkgState[Pkg->ID].InstallVer != *I)
+               continue;
+
 	    if ((Start->Version != 0 || TrgPkg != Pkg) &&
 		PkgState[Pkg->ID].CandidateVer != PkgState[Pkg->ID].InstallVer &&
 		PkgState[Pkg->ID].CandidateVer != *I &&
@@ -1284,14 +1289,20 @@ bool pkgDepCache::MarkInstall(PkgIterator const &Pkg,bool AutoInst,
 bool pkgDepCache::IsInstallOk(PkgIterator const &Pkg,bool AutoInst,
 			      unsigned long Depth, bool FromUser)
 {
-   return IsInstallOkMultiArchSameVersionSynced(Pkg,AutoInst, Depth, FromUser);
+   return IsInstallOkMultiArchSameVersionSynced(Pkg,AutoInst, Depth, FromUser) &&
+      IsInstallOkDependenciesSatisfiableByCandidates(Pkg,AutoInst, Depth, FromUser);
 }
 bool pkgDepCache::IsInstallOkMultiArchSameVersionSynced(PkgIterator const &Pkg,
-      bool const AutoInst, unsigned long const Depth, bool const FromUser)
+      bool const /*AutoInst*/, unsigned long const Depth, bool const FromUser)
 {
    if (FromUser == true) // as always: user is always right
       return true;
 
+   // if we have checked before and it was okay, it will still be okay
+   if (PkgState[Pkg->ID].Mode == ModeInstall &&
+	 PkgState[Pkg->ID].InstallVer == PkgState[Pkg->ID].CandidateVer)
+      return true;
+
    // ignore packages with none-M-A:same candidates
    VerIterator const CandVer = PkgState[Pkg->ID].CandidateVerIter(*this);
    if (unlikely(CandVer.end() == true) || CandVer == Pkg.CurrentVer() ||
@@ -1305,7 +1316,7 @@ bool pkgDepCache::IsInstallOkMultiArchSameVersionSynced(PkgIterator const &Pkg,
       // (simple string-compare as stuff like '1' == '0:1-0' can't happen here)
       if (P->CurrentVer == 0 || strcmp(Pkg.CandVersion(), P.CandVersion()) == 0)
 	 continue;
-      // packages loosing M-A:same can be out-of-sync
+      // packages losing M-A:same can be out-of-sync
       VerIterator CV = PkgState[P->ID].CandidateVerIter(*this);
       if (unlikely(CV.end() == true) ||
 	    (CV->MultiArch & pkgCache::Version::Same) != pkgCache::Version::Same)
@@ -1322,6 +1333,53 @@ bool pkgDepCache::IsInstallOkMultiArchSameVersionSynced(PkgIterator const &Pkg,
       return false;
    }
 
+   return true;
+}
+bool pkgDepCache::IsInstallOkDependenciesSatisfiableByCandidates(PkgIterator const &Pkg,
+      bool const AutoInst, unsigned long const Depth, bool const /*FromUser*/)
+{
+   if (AutoInst == false)
+      return true;
+
+   VerIterator const CandVer = PkgState[Pkg->ID].CandidateVerIter(*this);
+   if (unlikely(CandVer.end() == true) || CandVer == Pkg.CurrentVer())
+      return true;
+
+   for (DepIterator Dep = CandVer.DependsList(); Dep.end() != true;)
+   {
+      // Grok or groups
+      DepIterator Start = Dep;
+      bool Result = true;
+      unsigned Ors = 0;
+      for (bool LastOR = true; Dep.end() == false && LastOR == true; ++Dep, ++Ors)
+      {
+	 LastOR = (Dep->CompareOp & Dep::Or) == Dep::Or;
+
+	 if ((DepState[Dep->ID] & DepInstall) == DepInstall)
+	    Result = false;
+      }
+
+      if (Start.IsCritical() == false || Start.IsNegative() == true || Result == false)
+	 continue;
+
+      /* If we are in an or group locate the first or that can succeed.
+         We have already cached this… */
+      for (; Ors > 1 && (DepState[Start->ID] & DepCVer) != DepCVer; --Ors)
+	 ++Start;
+
+      if (Ors == 1 && (DepState[Start->ID] &DepCVer) != DepCVer)
+      {
+	 if (DebugAutoInstall == true)
+	    std::clog << OutputInDepth(Depth) << Start << " can't be satisfied!" << std::endl;
+
+	 // the dependency is critical, but can't be installed, so discard the candidate
+	 // as the problemresolver will trip over it otherwise trying to install it (#735967)
+	 if (Pkg->CurrentVer != 0)
+	    SetCandidateVersion(Pkg.CurrentVer());
+	 return false;
+      }
+   }
+
    return true;
 }
 									/*}}}*/
@@ -1675,10 +1733,10 @@ bool pkgDepCache::Policy::IsImportantDep(DepIterator const &Dep)
 }
 									/*}}}*/
 // Policy::GetPriority - Get the priority of the package pin		/*{{{*/
-signed short pkgDepCache::Policy::GetPriority(pkgCache::PkgIterator const &Pkg)
-{ return 0; };
-signed short pkgDepCache::Policy::GetPriority(pkgCache::PkgFileIterator const &File)
-{ return 0; };
+APT_CONST signed short pkgDepCache::Policy::GetPriority(pkgCache::PkgIterator const &/*Pkg*/)
+{ return 0; }
+APT_CONST signed short pkgDepCache::Policy::GetPriority(pkgCache::PkgFileIterator const &/*File*/)
+{ return 0; }
 									/*}}}*/
 pkgDepCache::InRootSetFunc *pkgDepCache::GetRootSetFunc()		/*{{{*/
 {

+ 19 - 8
apt-pkg/depcache.h

@@ -15,7 +15,7 @@
    
    This structure is important to support the readonly status of the cache 
    file. When the data is saved the cache will be refereshed from our 
-   internal rep and written to disk. Then the actual persistant data 
+   internal rep and written to disk. Then the actual persistent data
    files will be put on the disk.
 
    Each dependency is compared against 3 target versions to produce to
@@ -40,18 +40,27 @@
 
 #include <apt-pkg/configuration.h>
 #include <apt-pkg/pkgcache.h>
+#include <apt-pkg/cacheiterators.h>
+#include <apt-pkg/macros.h>
+
+#include <stddef.h>
 
-#include <vector>
 #include <memory>
-#include <set>
 #include <list>
+#include <string>
+#include <utility>
 
 #ifndef APT_8_CLEANER_HEADERS
 #include <apt-pkg/progress.h>
 #include <apt-pkg/error.h>
 #endif
+#ifndef APT_10_CLEANER_HEADERS
+#include <set>
+#include <vector>
+#endif
 
 class OpProgress;
+class pkgVersioningSystem;
 
 class pkgDepCache : protected pkgCache::Namespace
 {
@@ -61,7 +70,7 @@ class pkgDepCache : protected pkgCache::Namespace
    class InRootSetFunc
    {
    public:
-     virtual bool InRootSet(const pkgCache::PkgIterator &pkg) {return false;};
+     virtual bool InRootSet(const pkgCache::PkgIterator &/*pkg*/) {return false;};
      virtual ~InRootSetFunc() {};
    };
 
@@ -231,7 +240,7 @@ class pkgDepCache : protected pkgCache::Namespace
       unsigned char DepState;          // DepState Flags
 
       // Update of candidate version
-      const char *StripEpoch(const char *Ver);
+      const char *StripEpoch(const char *Ver) APT_PURE;
       void Update(PkgIterator Pkg,pkgCache &Cache);
       
       // Various test members for the current status of the package
@@ -381,8 +390,8 @@ class pkgDepCache : protected pkgCache::Namespace
    /** \brief Update the Marked and Garbage fields of all packages.
     *
     *  This routine is implicitly invoked after all state manipulators
-    *  and when an ActionGroup is destroyed.  It invokes #MarkRequired
-    *  and #Sweep to do its dirty work.
+    *  and when an ActionGroup is destroyed.  It invokes the private
+    *  MarkRequired() and Sweep() to do its dirty work.
     *
     *  \param rootFunc A predicate that returns \b true for packages
     *  that should be added to the root set.
@@ -465,7 +474,7 @@ class pkgDepCache : protected pkgCache::Namespace
     *
     *  The parameters are the same as in the calling MarkDelete:
     *  \param Pkg       the package that MarkDelete wants to remove.
-    *  \param Purge     should we purge instead of "only" remove?
+    *  \param MarkPurge should we purge instead of "only" remove?
     *  \param Depth     recursive deep of this Marker call
     *  \param FromUser  was the remove requested by the user?
     */
@@ -497,6 +506,8 @@ class pkgDepCache : protected pkgCache::Namespace
    // methods call by IsInstallOk
    bool IsInstallOkMultiArchSameVersionSynced(PkgIterator const &Pkg,
 	 bool const AutoInst, unsigned long const Depth, bool const FromUser);
+   bool IsInstallOkDependenciesSatisfiableByCandidates(PkgIterator const &Pkg,
+      bool const AutoInst, unsigned long const Depth, bool const FromUser);
 
    // methods call by IsDeleteOk
    bool IsDeleteOkProtectInstallRequests(PkgIterator const &Pkg,

+ 17 - 10
apt-pkg/edsp.cc

@@ -11,16 +11,25 @@
 #include <apt-pkg/error.h>
 #include <apt-pkg/cacheset.h>
 #include <apt-pkg/configuration.h>
-#include <apt-pkg/version.h>
-#include <apt-pkg/policy.h>
 #include <apt-pkg/tagfile.h>
 #include <apt-pkg/fileutl.h>
 #include <apt-pkg/progress.h>
+#include <apt-pkg/depcache.h>
+#include <apt-pkg/pkgcache.h>
+#include <apt-pkg/cacheiterators.h>
+#include <apt-pkg/strutl.h>
 
-#include <limits>
+#include <ctype.h>
+#include <stddef.h>
+#include <string.h>
+#include <time.h>
+#include <unistd.h>
 #include <stdio.h>
-
+#include <iostream>
+#include <vector>
+#include <limits>
 #include <string>
+#include <list>
 
 #include <apti18n.h>
 									/*}}}*/
@@ -44,7 +53,7 @@ bool EDSP::WriteScenario(pkgDepCache &Cache, FILE* output, OpProgress *Progress)
       for (pkgCache::VerIterator Ver = Pkg.VersionList(); Ver.end() == false; ++Ver, ++p)
       {
 	 WriteScenarioVersion(Cache, output, Pkg, Ver);
-	 WriteScenarioDependency(Cache, output, Pkg, Ver);
+	 WriteScenarioDependency(output, Ver);
 	 fprintf(output, "\n");
 	 if (Progress != NULL && p % 100 == 0)
 	    Progress->Progress(p);
@@ -64,7 +73,7 @@ bool EDSP::WriteLimitedScenario(pkgDepCache &Cache, FILE* output,
       for (pkgCache::VerIterator Ver = Pkg.VersionList(); Ver.end() == false; ++Ver)
       {
 	 WriteScenarioVersion(Cache, output, Pkg, Ver);
-	 WriteScenarioLimitedDependency(Cache, output, Pkg, Ver, pkgset);
+	 WriteScenarioLimitedDependency(output, Ver, pkgset);
 	 fprintf(output, "\n");
 	 if (Progress != NULL && p % 100 == 0)
 	    Progress->Progress(p);
@@ -111,8 +120,7 @@ void EDSP::WriteScenarioVersion(pkgDepCache &Cache, FILE* output, pkgCache::PkgI
 }
 									/*}}}*/
 // EDSP::WriteScenarioDependency					/*{{{*/
-void EDSP::WriteScenarioDependency(pkgDepCache &Cache, FILE* output, pkgCache::PkgIterator const &Pkg,
-				pkgCache::VerIterator const &Ver)
+void EDSP::WriteScenarioDependency( FILE* output, pkgCache::VerIterator const &Ver)
 {
    std::string dependencies[pkgCache::Dep::Enhances + 1];
    bool orGroup = false;
@@ -148,8 +156,7 @@ void EDSP::WriteScenarioDependency(pkgDepCache &Cache, FILE* output, pkgCache::P
 }
 									/*}}}*/
 // EDSP::WriteScenarioLimitedDependency					/*{{{*/
-void EDSP::WriteScenarioLimitedDependency(pkgDepCache &Cache, FILE* output,
-					  pkgCache::PkgIterator const &Pkg,
+void EDSP::WriteScenarioLimitedDependency(FILE* output,
 					  pkgCache::VerIterator const &Ver,
 					  APT::PackageSet const &pkgset)
 {

+ 13 - 11
apt-pkg/edsp.h

@@ -2,15 +2,19 @@
 /** Description \file edsp.h						{{{
    ######################################################################
    Set of methods to help writing and reading everything needed for EDSP
-   with the noteable exception of reading a scenario for conversion into
+   with the notable exception of reading a scenario for conversion into
    a Cache as this is handled by edsp interface for listparser and friends
    ##################################################################### */
 									/*}}}*/
 #ifndef PKGLIB_EDSP_H
 #define PKGLIB_EDSP_H
 
-#include <apt-pkg/pkgcache.h>
 #include <apt-pkg/cacheset.h>
+#include <apt-pkg/pkgcache.h>
+#include <apt-pkg/cacheiterators.h>
+#include <apt-pkg/macros.h>
+
+#include <stdio.h>
 
 #include <list>
 #include <string>
@@ -29,17 +33,15 @@ class EDSP								/*{{{*/
 	static const char * const PrioMap[];
 	static const char * const DepMap[];
 
-	bool static ReadLine(int const input, std::string &line);
-	bool static StringToBool(char const *answer, bool const defValue);
+	APT_HIDDEN bool static ReadLine(int const input, std::string &line);
+	APT_HIDDEN bool static StringToBool(char const *answer, bool const defValue);
 
-	void static WriteScenarioVersion(pkgDepCache &Cache, FILE* output,
+	APT_HIDDEN void static WriteScenarioVersion(pkgDepCache &Cache, FILE* output,
 					 pkgCache::PkgIterator const &Pkg,
 					 pkgCache::VerIterator const &Ver);
-	void static WriteScenarioDependency(pkgDepCache &Cache, FILE* output,
-					    pkgCache::PkgIterator const &Pkg,
+	APT_HIDDEN void static WriteScenarioDependency(FILE* output,
 					    pkgCache::VerIterator const &Ver);
-	void static WriteScenarioLimitedDependency(pkgDepCache &Cache, FILE* output,
-						   pkgCache::PkgIterator const &Pkg,
+	APT_HIDDEN void static WriteScenarioLimitedDependency(FILE* output,
 						   pkgCache::VerIterator const &Ver,
 						   APT::PackageSet const &pkgset);
 public:
@@ -182,13 +184,13 @@ public:
 	 *  they were unable to calculate a solution for a given task.
 	 *  Obviously they can't send a solution through, so this
 	 *  methods deals with formatting an error message correctly
-	 *  so that the front-ends can recieve and display it.
+	 *  so that the front-ends can receive and display it.
 	 *
 	 *  The first line of the message should be a short description
 	 *  of the error so it can be used for dialog titles or alike
 	 *
 	 *  \param uuid of this error message
-	 *  \param message is free form text to discribe the error
+	 *  \param message is free form text to describe the error
 	 *  \param output the front-end listens for error messages
 	 */
 	bool static WriteError(char const * const uuid, std::string const &message, FILE* output);

+ 12 - 7
apt-pkg/edsp/edspindexfile.cc

@@ -10,15 +10,20 @@
 
 #include <apt-pkg/edspindexfile.h>
 #include <apt-pkg/edsplistparser.h>
-#include <apt-pkg/sourcelist.h>
-#include <apt-pkg/configuration.h>
-#include <apt-pkg/progress.h>
 #include <apt-pkg/error.h>
-#include <apt-pkg/strutl.h>
 #include <apt-pkg/fileutl.h>
-#include <apt-pkg/acquire-item.h>
+#include <apt-pkg/progress.h>
+#include <apt-pkg/debindexfile.h>
+#include <apt-pkg/indexfile.h>
+#include <apt-pkg/mmap.h>
+#include <apt-pkg/pkgcache.h>
+#include <apt-pkg/cacheiterators.h>
+#include <apt-pkg/pkgcachegen.h>
+#include <apt-pkg/pkgrecords.h>
 
-#include <sys/stat.h>
+#include <stddef.h>
+#include <unistd.h>
+#include <string>
 									/*}}}*/
 
 // edspIndex::edspIndex - Constructor					/*{{{*/
@@ -63,7 +68,7 @@ bool edspIndex::Merge(pkgCacheGenerator &Gen,OpProgress *Prog) const
 class edspIFType: public pkgIndexFile::Type
 {
    public:
-   virtual pkgRecords::Parser *CreatePkgParser(pkgCache::PkgFileIterator File) const
+   virtual pkgRecords::Parser *CreatePkgParser(pkgCache::PkgFileIterator) const
    {
       // we don't have a record parser for this type as the file is not presistent
       return NULL;

+ 5 - 1
apt-pkg/edsp/edspindexfile.h

@@ -9,11 +9,15 @@
 #define PKGLIB_EDSPINDEXFILE_H
 
 #include <apt-pkg/debindexfile.h>
+#include <string>
 
 #ifndef APT_8_CLEANER_HEADERS
 #include <apt-pkg/indexfile.h>
 #endif
 
+class OpProgress;
+class pkgCacheGenerator;
+
 class edspIndex : public debStatusIndex
 {
    /** \brief dpointer placeholder (for later in case we need it) */
@@ -21,7 +25,7 @@ class edspIndex : public debStatusIndex
 
    public:
 
-   virtual const Type *GetType() const;
+   virtual const Type *GetType() const APT_CONST;
 
    virtual bool Merge(pkgCacheGenerator &Gen,OpProgress *Prog) const;
 

+ 8 - 6
apt-pkg/edsp/edsplistparser.cc

@@ -12,11 +12,13 @@
 #include <config.h>
 
 #include <apt-pkg/edsplistparser.h>
-#include <apt-pkg/error.h>
-#include <apt-pkg/configuration.h>
-#include <apt-pkg/strutl.h>
 #include <apt-pkg/md5.h>
-#include <apt-pkg/macros.h>
+#include <apt-pkg/deblistparser.h>
+#include <apt-pkg/pkgcache.h>
+#include <apt-pkg/cacheiterators.h>
+#include <apt-pkg/tagfile.h>
+
+#include <string>
 									/*}}}*/
 
 // ListParser::edspListParser - Constructor				/*{{{*/
@@ -84,8 +86,8 @@ bool edspListParser::ParseStatus(pkgCache::PkgIterator &Pkg,
 }
 									/*}}}*/
 // ListParser::LoadReleaseInfo - Load the release information		/*{{{*/
-bool edspListParser::LoadReleaseInfo(pkgCache::PkgFileIterator &FileI,
-				    FileFd &File, std::string component)
+APT_CONST bool edspListParser::LoadReleaseInfo(pkgCache::PkgFileIterator & /*FileI*/,
+				    FileFd & /*File*/, std::string /*component*/)
 {
    return true;
 }

+ 4 - 0
apt-pkg/edsp/edsplistparser.h

@@ -12,6 +12,10 @@
 #define PKGLIB_EDSPLISTPARSER_H
 
 #include <apt-pkg/deblistparser.h>
+#include <apt-pkg/md5.h>
+#include <apt-pkg/pkgcache.h>
+
+#include <string>
 
 #ifndef APT_8_CLEANER_HEADERS
 #include <apt-pkg/pkgcachegen.h>

+ 11 - 10
apt-pkg/edsp/edspsystem.cc

@@ -11,16 +11,17 @@
 // Include Files							/*{{{*/
 #include <config.h>
 
-#include <apt-pkg/edspsystem.h>
+#include <apt-pkg/configuration.h>
 #include <apt-pkg/debversion.h>
 #include <apt-pkg/edspindexfile.h>
-#include <apt-pkg/configuration.h>
-#include <apt-pkg/error.h>
+#include <apt-pkg/edspsystem.h>
 #include <apt-pkg/fileutl.h>
-#include <sys/types.h>
-#include <unistd.h>
-#include <dirent.h>
-#include <errno.h>
+#include <apt-pkg/pkgcache.h>
+#include <apt-pkg/cacheiterators.h>
+
+#include <stddef.h>
+#include <string>
+#include <vector>
 
 #include <apti18n.h>
 									/*}}}*/
@@ -49,7 +50,7 @@ bool edspSystem::Lock()
 }
 									/*}}}*/
 // System::UnLock - Drop a lock						/*{{{*/
-bool edspSystem::UnLock(bool NoErrors)
+bool edspSystem::UnLock(bool /*NoErrors*/)
 {
    return true;
 }
@@ -58,7 +59,7 @@ bool edspSystem::UnLock(bool NoErrors)
 // ---------------------------------------------------------------------
 /* we can't use edsp input as input for real installations - just a
    simulation can work, but everything else will fail bigtime */
-pkgPackageManager *edspSystem::CreatePM(pkgDepCache *Cache) const
+pkgPackageManager *edspSystem::CreatePM(pkgDepCache * /*Cache*/) const
 {
    return NULL;
 }
@@ -81,7 +82,7 @@ bool edspSystem::Initialize(Configuration &Cnf)
 }
 									/*}}}*/
 // System::ArchiveSupported - Is a file format supported		/*{{{*/
-bool edspSystem::ArchiveSupported(const char *Type)
+bool edspSystem::ArchiveSupported(const char * /*Type*/)
 {
    return false;
 }

+ 13 - 4
apt-pkg/edsp/edspsystem.h

@@ -11,8 +11,17 @@
 #define PKGLIB_EDSPSYSTEM_H
 
 #include <apt-pkg/pkgsystem.h>
+#include <apt-pkg/cacheiterators.h>
+#include <apt-pkg/pkgcache.h>
 
+#include <vector>
+
+class Configuration;
+class pkgDepCache;
+class pkgIndexFile;
+class pkgPackageManager;
 class edspIndex;
+
 class edspSystem : public pkgSystem
 {
    /** \brief dpointer placeholder (for later in case we need it) */
@@ -22,11 +31,11 @@ class edspSystem : public pkgSystem
 
    public:
 
-   virtual bool Lock();
-   virtual bool UnLock(bool NoErrors = false);
-   virtual pkgPackageManager *CreatePM(pkgDepCache *Cache) const;
+   virtual bool Lock() APT_CONST;
+   virtual bool UnLock(bool NoErrors = false) APT_CONST;
+   virtual pkgPackageManager *CreatePM(pkgDepCache *Cache) const APT_CONST;
    virtual bool Initialize(Configuration &Cnf);
-   virtual bool ArchiveSupported(const char *Type);
+   virtual bool ArchiveSupported(const char *Type) APT_CONST;
    virtual signed Score(Configuration const &Cnf);
    virtual bool AddStatusFiles(std::vector<pkgIndexFile *> &List);
    virtual bool FindIndex(pkgCache::PkgFileIterator File,

+ 18 - 20
apt-pkg/indexcopy.cc

@@ -20,17 +20,17 @@
 #include <apt-pkg/configuration.h>
 #include <apt-pkg/tagfile.h>
 #include <apt-pkg/indexrecords.h>
-#include <apt-pkg/md5.h>
 #include <apt-pkg/cdrom.h>
+#include <apt-pkg/gpgv.h>
+#include <apt-pkg/hashes.h>
 
 #include <iostream>
 #include <sstream>
 #include <unistd.h>
 #include <sys/stat.h>
-#include <sys/types.h>
-#include <fcntl.h>
 #include <stdio.h>
 #include <stdlib.h>
+#include <string.h>
 
 #include "indexcopy.h"
 #include <apti18n.h>
@@ -65,7 +65,7 @@ bool IndexCopy::CopyPackages(string CDROM,string Name,vector<string> &List,
       for (std::vector<APT::Configuration::Compressor>::const_iterator c = compressor.begin();
 	   c != compressor.end(); ++c)
       {
-	 if (stat(std::string(file + c->Extension).c_str(), &Buf) != 0)
+	 if (stat((file + c->Extension).c_str(), &Buf) != 0)
 	    continue;
 	 found = true;
 	 break;
@@ -160,7 +160,7 @@ bool IndexCopy::CopyPackages(string CDROM,string Name,vector<string> &List,
 	    
 	    // Get the size
 	    struct stat Buf;
-	    if (stat(string(CDROM + Prefix + File).c_str(),&Buf) != 0 || 
+	    if (stat((CDROM + Prefix + File).c_str(),&Buf) != 0 || 
 		Buf.st_size == 0)
 	    {
 	       bool Mangled = false;
@@ -175,7 +175,7 @@ bool IndexCopy::CopyPackages(string CDROM,string Name,vector<string> &List,
 	       }
 	       
 	       if (Mangled == false ||
-		   stat(string(CDROM + Prefix + File).c_str(),&Buf) != 0)
+		   stat((CDROM + Prefix + File).c_str(),&Buf) != 0)
 	       {
 		  if (Debug == true)
 		     clog << "Missed(2): " << OrigFile << endl;
@@ -286,7 +286,7 @@ bool IndexCopy::ReconstructPrefix(string &Prefix,string OrigPath,string CD,
    while (1)
    {
       struct stat Buf;
-      if (stat(string(CD + MyPrefix + File).c_str(),&Buf) != 0)
+      if (stat((CD + MyPrefix + File).c_str(),&Buf) != 0)
       {
 	 if (Debug == true)
 	    cout << "Failed, " << CD + MyPrefix + File << endl;
@@ -315,7 +315,7 @@ bool IndexCopy::ReconstructChop(unsigned long &Chop,string Dir,string File)
    while (1)
    {
       struct stat Buf;
-      if (stat(string(Dir + File).c_str(),&Buf) != 0)
+      if (stat((Dir + File).c_str(),&Buf) != 0)
       {
 	 File = ChopDirs(File,1);
 	 Depth++;
@@ -436,8 +436,8 @@ bool PackageCopy::GetFile(string &File,unsigned long long &Size)
 /* */
 bool PackageCopy::RewriteEntry(FILE *Target,string File)
 {
-   TFRewriteData Changes[] = {{"Filename",File.c_str()},
-                              {}};
+   TFRewriteData Changes[] = {{ "Filename", File.c_str(), NULL },
+                              { NULL, NULL, NULL }};
    
    if (TFRewrite(Target,*Section,TFRewritePackageOrder,Changes) == false)
       return false;
@@ -482,8 +482,8 @@ bool SourceCopy::GetFile(string &File,unsigned long long &Size)
 bool SourceCopy::RewriteEntry(FILE *Target,string File)
 {
    string Dir(File,0,File.rfind('/'));
-   TFRewriteData Changes[] = {{"Directory",Dir.c_str()},
-                              {}};
+   TFRewriteData Changes[] = {{ "Directory", Dir.c_str(), NULL },
+                              { NULL, NULL, NULL }};
    
    if (TFRewrite(Target,*Section,TFRewriteSourceOrder,Changes) == false)
       return false;
@@ -551,7 +551,7 @@ bool SigVerify::CopyMetaIndex(string CDROM, string CDName,		/*{{{*/
 }
 									/*}}}*/
 bool SigVerify::CopyAndVerify(string CDROM,string Name,vector<string> &SigList,	/*{{{*/
-			      vector<string> PkgList,vector<string> SrcList)
+			      vector<string> /*PkgList*/,vector<string> /*SrcList*/)
 {
    if (SigList.empty() == true)
       return true;
@@ -642,16 +642,14 @@ bool SigVerify::CopyAndVerify(string CDROM,string Name,vector<string> &SigList,
 }
 									/*}}}*/
 // SigVerify::RunGPGV - deprecated wrapper calling ExecGPGV		/*{{{*/
-bool SigVerify::RunGPGV(std::string const &File, std::string const &FileOut,
+APT_NORETURN bool SigVerify::RunGPGV(std::string const &File, std::string const &FileOut,
       int const &statusfd, int fd[2]) {
    ExecGPGV(File, FileOut, statusfd, fd);
-   return false;
-};
-bool SigVerify::RunGPGV(std::string const &File, std::string const &FileOut,
+}
+APT_NORETURN bool SigVerify::RunGPGV(std::string const &File, std::string const &FileOut,
       int const &statusfd) {
    ExecGPGV(File, FileOut, statusfd);
-   return false;
-};
+}
 									/*}}}*/
 bool TranslationsCopy::CopyTranslations(string CDROM,string Name,	/*{{{*/
 				vector<string> &List, pkgCdromStatus *log)
@@ -676,7 +674,7 @@ bool TranslationsCopy::CopyTranslations(string CDROM,string Name,	/*{{{*/
       for (std::vector<APT::Configuration::Compressor>::const_iterator c = compressor.begin();
 	   c != compressor.end(); ++c)
       {
-	 if (stat(std::string(file + c->Extension).c_str(), &Buf) != 0)
+	 if (stat((file + c->Extension).c_str(), &Buf) != 0)
 	    continue;
 	 found = true;
 	 break;

+ 6 - 4
apt-pkg/indexcopy.h

@@ -14,16 +14,18 @@
 #include <string>
 #include <stdio.h>
 
-#include <apt-pkg/gpgv.h>
 #include <apt-pkg/macros.h>
 
+#ifndef APT_10_CLEANER_HEADERS
+#include <apt-pkg/gpgv.h>
+class FileFd;
+#endif
 #ifndef APT_8_CLEANER_HEADERS
 using std::string;
 using std::vector;
 #endif
 
 class pkgTagSection;
-class FileFd;
 class indexRecords;
 class pkgCdromStatus;
 
@@ -99,9 +101,9 @@ class SigVerify								/*{{{*/
    bool CopyAndVerify(std::string CDROM,std::string Name,std::vector<std::string> &SigList,
 		      std::vector<std::string> PkgList,std::vector<std::string> SrcList);
 
-   __deprecated static bool RunGPGV(std::string const &File, std::string const &FileOut,
+   APT_DEPRECATED static bool RunGPGV(std::string const &File, std::string const &FileOut,
 		       int const &statusfd, int fd[2]);
-   __deprecated static bool RunGPGV(std::string const &File, std::string const &FileOut,
+   APT_DEPRECATED static bool RunGPGV(std::string const &File, std::string const &FileOut,
 			      int const &statusfd = -1);
 };
 									/*}}}*/

+ 0 - 0
apt-pkg/indexfile.cc


Some files were not shown because too many files changed in this diff