Procházet zdrojové kódy

Merge remote-tracking branch 'upstream/debian/experimental' into feature/srv-records

Michael Vogt před 11 roky
rodič
revize
b53c9cea29
100 změnil soubory, kde provedl 7057 přidání a 6310 odebrání
  1. 6 0
      .travis.yml
  2. 13 2
      Makefile
  3. 0 4
      apt-inst/contrib/arfile.h
  4. 0 5
      apt-inst/contrib/extracttar.cc
  5. 0 8
      apt-inst/contrib/extracttar.h
  6. 0 8
      apt-inst/deb/debfile.cc
  7. 3 11
      apt-inst/deb/debfile.h
  8. 1 11
      apt-inst/dirstream.h
  9. 3 3
      apt-inst/extract.h
  10. 1 1
      apt-inst/makefile
  11. 2219 1943
      apt-pkg/acquire-item.cc
  12. 431 442
      apt-pkg/acquire-item.h
  13. 16 11
      apt-pkg/acquire-method.cc
  14. 11 3
      apt-pkg/acquire-method.h
  15. 254 155
      apt-pkg/acquire-worker.cc
  16. 5 3
      apt-pkg/acquire-worker.h
  17. 136 27
      apt-pkg/acquire.cc
  18. 36 24
      apt-pkg/acquire.h
  19. 13 29
      apt-pkg/algorithms.cc
  20. 11 21
      apt-pkg/algorithms.h
  21. 1 2
      apt-pkg/aptconfiguration.cc
  22. 11 12
      apt-pkg/aptconfiguration.h
  23. 26 15
      apt-pkg/cachefile.cc
  24. 15 15
      apt-pkg/cachefile.h
  25. 30 30
      apt-pkg/cachefilter.h
  26. 129 72
      apt-pkg/cacheiterators.h
  27. 134 1
      apt-pkg/cacheset.cc
  28. 364 163
      apt-pkg/cacheset.h
  29. 10 3
      apt-pkg/cdrom.cc
  30. 9 2
      apt-pkg/cdrom.h
  31. 2 1
      apt-pkg/clean.cc
  32. 3 1
      apt-pkg/clean.h
  33. 2 0
      apt-pkg/contrib/cdromutl.cc
  34. 4 4
      apt-pkg/contrib/cmndline.cc
  35. 2 8
      apt-pkg/contrib/configuration.cc
  36. 2 9
      apt-pkg/contrib/configuration.h
  37. 62 19
      apt-pkg/contrib/fileutl.cc
  38. 11 21
      apt-pkg/contrib/fileutl.h
  39. 18 1
      apt-pkg/contrib/gpgv.cc
  40. 4 1
      apt-pkg/contrib/gpgv.h
  41. 34 18
      apt-pkg/contrib/hashes.cc
  42. 17 1
      apt-pkg/contrib/hashes.h
  43. 1 1
      apt-pkg/contrib/hashsum_template.h
  44. 8 2
      apt-pkg/contrib/macros.h
  45. 1 1
      apt-pkg/contrib/md5.h
  46. 3 2
      apt-pkg/contrib/progress.h
  47. 1 1
      apt-pkg/contrib/sha1.h
  48. 3 3
      apt-pkg/contrib/sha2.h
  49. 10 2
      apt-pkg/contrib/sptr.h
  50. 13 6
      apt-pkg/contrib/strutl.cc
  51. 1 0
      apt-pkg/contrib/strutl.h
  52. 113 666
      apt-pkg/deb/debindexfile.cc
  53. 71 134
      apt-pkg/deb/debindexfile.h
  54. 28 134
      apt-pkg/deb/deblistparser.cc
  55. 25 31
      apt-pkg/deb/deblistparser.h
  56. 623 385
      apt-pkg/deb/debmetaindex.cc
  57. 33 65
      apt-pkg/deb/debmetaindex.h
  58. 12 1
      apt-pkg/deb/debrecords.cc
  59. 22 19
      apt-pkg/deb/debrecords.h
  60. 4 0
      apt-pkg/deb/debsrcrecords.cc
  61. 14 16
      apt-pkg/deb/debsrcrecords.h
  62. 1 4
      apt-pkg/deb/debsystem.cc
  63. 9 9
      apt-pkg/deb/debsystem.h
  64. 22 26
      apt-pkg/deb/debversion.cc
  65. 4 5
      apt-pkg/deb/debversion.h
  66. 9 18
      apt-pkg/deb/dpkgpm.cc
  67. 7 7
      apt-pkg/deb/dpkgpm.h
  68. 161 115
      apt-pkg/depcache.cc
  69. 22 19
      apt-pkg/depcache.h
  70. 71 83
      apt-pkg/edsp.cc
  71. 14 30
      apt-pkg/edsp.h
  72. 43 40
      apt-pkg/edsp/edspindexfile.cc
  73. 17 10
      apt-pkg/edsp/edspindexfile.h
  74. 5 4
      apt-pkg/edsp/edsplistparser.cc
  75. 9 7
      apt-pkg/edsp/edsplistparser.h
  76. 5 16
      apt-pkg/edsp/edspsystem.cc
  77. 12 10
      apt-pkg/edsp/edspsystem.h
  78. 21 10
      apt-pkg/indexcopy.cc
  79. 33 16
      apt-pkg/indexcopy.h
  80. 280 8
      apt-pkg/indexfile.cc
  81. 126 19
      apt-pkg/indexfile.h
  82. 0 296
      apt-pkg/indexrecords.cc
  83. 0 96
      apt-pkg/indexrecords.h
  84. 24 4
      apt-pkg/init.cc
  85. 14 9
      apt-pkg/install-progress.cc
  86. 27 18
      apt-pkg/install-progress.h
  87. 72 13
      apt-pkg/metaindex.cc
  88. 67 16
      apt-pkg/metaindex.h
  89. 12 14
      apt-pkg/orderlist.cc
  90. 3 3
      apt-pkg/orderlist.h
  91. 13 38
      apt-pkg/packagemanager.cc
  92. 2 12
      apt-pkg/packagemanager.h
  93. 160 144
      apt-pkg/pkgcache.cc
  94. 149 115
      apt-pkg/pkgcache.h
  95. 562 445
      apt-pkg/pkgcachegen.cc
  96. 32 39
      apt-pkg/pkgcachegen.h
  97. 3 0
      apt-pkg/pkgrecords.cc
  98. 7 12
      apt-pkg/pkgrecords.h
  99. 4 1
      apt-pkg/pkgsystem.cc
  100. 0 0
      apt-pkg/pkgsystem.h

+ 6 - 0
.travis.yml

@@ -1,5 +1,11 @@
 language: cpp
 before_install:
+ - sudo add-apt-repository ppa:ubuntu-toolchain-r/test -y
  - sudo apt-get update -q
+install:
  - sudo ./prepare-release travis-ci
+ - sudo add-apt-repository -y ppa:ubuntu-toolchain-r/test
+ - sudo apt-get -qq update
+ - sudo apt-get -qq install g++-4.8
+ - export CXX=g++-4.8
 script: make && make test && test/integration/run-tests

+ 13 - 2
Makefile

@@ -9,7 +9,7 @@ endif
 .PHONY: default
 default: startup all
 
-.PHONY: headers library clean veryclean all binary program doc test update-po
+.PHONY: fast headers library clean veryclean all binary program doc test update-po
 all headers library clean veryclean binary program doc manpages docbook test update-po startup dirs:
 	$(MAKE) -C vendor $@
 	$(MAKE) -C apt-pkg $@
@@ -21,7 +21,18 @@ all headers library clean veryclean binary program doc manpages docbook test upd
 	$(MAKE) -C dselect $@
 	$(MAKE) -C doc $@
 	$(MAKE) -C po $@
-	$(MAKE) -C test $@
+	# FIXME: -C test has issue swith parallel builds, investigate!
+	-$(MAKE) -C test $@
+
+fast:
+	$(MAKE) -C vendor all
+	$(MAKE) -C apt-pkg all
+	$(MAKE) -C apt-inst all
+	$(MAKE) -C apt-private all
+	$(MAKE) -C methods all
+	$(MAKE) -C cmdline all
+	$(MAKE) -C ftparchive all
+	$(MAKE) -C test all
 
 all headers library clean veryclean binary program doc manpages docbook test update-po: startup dirs
 

+ 0 - 4
apt-inst/contrib/arfile.h

@@ -62,11 +62,7 @@ struct ARArchive::Member
    unsigned long long Size;
    
    // Location of the data.
-#if APT_PKG_ABI >= 413
    unsigned long long Start;
-#else
-   unsigned long Start;
-#endif
    Member *Next;
    
    Member() : Start(0), Next(0) {};

+ 0 - 5
apt-inst/contrib/extracttar.cc

@@ -60,13 +60,8 @@ struct ExtractTar::TarHeader
 // ExtractTar::ExtractTar - Constructor					/*{{{*/
 // ---------------------------------------------------------------------
 /* */
-#if APT_PKG_ABI >= 413
 ExtractTar::ExtractTar(FileFd &Fd,unsigned long long Max,string DecompressionProgram)
 	: File(Fd), MaxInSize(Max), DecompressProg(DecompressionProgram)
-#else
-ExtractTar::ExtractTar(FileFd &Fd,unsigned long Max,string DecompressionProgram)
-	: File(Fd), MaxInSize(Max), DecompressProg(DecompressionProgram)
-#endif
 {
    GZPid = -1;
    Eof = false;

+ 0 - 8
apt-inst/contrib/extracttar.h

@@ -40,11 +40,7 @@ class ExtractTar
                   GNU_LongLink = 'K',GNU_LongName = 'L'};
 
    FileFd &File;
-#if APT_PKG_ABI >= 413
    unsigned long long MaxInSize;
-#else
-   unsigned long MaxInSize;
-#endif
    int GZPid;
    FileFd InFd;
    bool Eof;
@@ -58,11 +54,7 @@ class ExtractTar
 
    bool Go(pkgDirStream &Stream);
 
-#if APT_PKG_ABI >= 413
    ExtractTar(FileFd &Fd,unsigned long long Max,std::string DecompressionProgram);
-#else
-   ExtractTar(FileFd &Fd,unsigned long Max,std::string DecompressionProgram);
-#endif
    virtual ~ExtractTar();
 };
 

+ 0 - 8
apt-inst/deb/debfile.cc

@@ -203,11 +203,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,
-#if APT_PKG_ABI >= 413
 			     unsigned long long Size,unsigned long long Pos)
-#else
-			     unsigned long Size,unsigned long Pos)
-#endif
 {
    memcpy(Control + Pos, Data,Size);
    return true;
@@ -236,11 +232,7 @@ bool debDebFile::MemControlExtract::Read(debDebFile &Deb)
 // ---------------------------------------------------------------------
 /* The given memory block is loaded into the parser and parsed as a control
    record. */
-#if APT_PKG_ABI >= 413
 bool debDebFile::MemControlExtract::TakeControl(const void *Data,unsigned long long Size)
-#else
-bool debDebFile::MemControlExtract::TakeControl(const void *Data,unsigned long Size)
-#endif
 {
    delete [] Control;
    Control = new char[Size+2];

+ 3 - 11
apt-inst/deb/debfile.h

@@ -65,7 +65,7 @@ class debDebFile::ControlExtract : public pkgDirStream
 {
    public:
    
-   virtual bool DoItem(Item &Itm,int &Fd);
+   virtual bool DoItem(Item &Itm,int &Fd) APT_OVERRIDE;
 };
 
 class debDebFile::MemControlExtract : public pkgDirStream
@@ -80,21 +80,13 @@ class debDebFile::MemControlExtract : public pkgDirStream
    std::string Member;
    
    // Members from DirStream
-   virtual bool DoItem(Item &Itm,int &Fd);
+   virtual bool DoItem(Item &Itm,int &Fd) APT_OVERRIDE;
    virtual bool Process(Item &Itm,const unsigned char *Data,
-#if APT_PKG_ABI >= 413
-			unsigned long long Size,unsigned long long Pos);
-#else
-			unsigned long Size,unsigned long Pos);
-#endif
+			unsigned long long Size,unsigned long long Pos) APT_OVERRIDE;
 
    // Helpers
    bool Read(debDebFile &Deb);
-#if APT_PKG_ABI >= 413
    bool TakeControl(const void *Data,unsigned long long Size);
-#else
-   bool TakeControl(const void *Data,unsigned long Size);
-#endif
 
    MemControlExtract() : IsControl(false), Control(0), Length(0), Member("control") {};
    MemControlExtract(std::string Member) : IsControl(false), Control(0), Length(0), Member(Member) {};

+ 1 - 11
apt-inst/dirstream.h

@@ -38,15 +38,10 @@ class pkgDirStream
 	           Directory, FIFO} Type;
       char *Name;
       char *LinkTarget;
-#if APT_PKG_ABI >= 413
-      unsigned long long Size;
-#endif
       unsigned long Mode;
       unsigned long UID;
       unsigned long GID;
-#if APT_PKG_ABI < 413
-      unsigned long Size;
-#endif
+      unsigned long long Size;
       unsigned long MTime;
       unsigned long Major;
       unsigned long Minor;
@@ -55,13 +50,8 @@ class pkgDirStream
    virtual bool DoItem(Item &Itm,int &Fd);
    virtual bool Fail(Item &Itm,int Fd);
    virtual bool FinishedFile(Item &Itm,int Fd);
-#if APT_PKG_ABI >= 413
    virtual bool Process(Item &/*Itm*/,const unsigned char * /*Data*/,
 			unsigned long long /*Size*/,unsigned long long /*Pos*/) {return true;};
-#else
-   virtual bool Process(Item &/*Itm*/,const unsigned char * /*Data*/,
-			unsigned long /*Size*/,unsigned long /*Pos*/) {return true;};
-#endif
    virtual ~pkgDirStream() {};   
 };
 

+ 3 - 3
apt-inst/extract.h

@@ -38,9 +38,9 @@ class pkgExtract : public pkgDirStream
    
    public:
    
-   virtual bool DoItem(Item &Itm,int &Fd);
-   virtual bool Fail(Item &Itm,int Fd);
-   virtual bool FinishedFile(Item &Itm,int Fd);
+   virtual bool DoItem(Item &Itm,int &Fd) APT_OVERRIDE;
+   virtual bool Fail(Item &Itm,int Fd) APT_OVERRIDE;
+   virtual bool FinishedFile(Item &Itm,int Fd) APT_OVERRIDE;
 
    bool Finished();
    bool Aborted();

+ 1 - 1
apt-inst/makefile

@@ -14,7 +14,7 @@ include ../buildlib/libversion.mak
 
 # The library name
 LIBRARY=apt-inst
-MAJOR=1.6
+MAJOR=2.0
 MINOR=0
 SLIBS=$(PTHREADLIB) -lapt-pkg
 APT_DOMAIN:=libapt-inst$(MAJOR)

Rozdílová data souboru nebyla zobrazena, protože soubor je příliš velký
+ 2219 - 1943
apt-pkg/acquire-item.cc


Rozdílová data souboru nebyla zobrazena, protože soubor je příliš velký
+ 431 - 442
apt-pkg/acquire-item.h


+ 16 - 11
apt-pkg/acquire-method.cc

@@ -376,7 +376,10 @@ int pkgAcqMethod::Run(bool Single)
 		  Tmp->ExpectedHashes.push_back(HashString(*t, hash));
 	    }
             char *End;
-            Tmp->MaximumSize = strtoll(LookupTag(Message, "Maximum-Size", "0").c_str(), &End, 10);
+	    if (Tmp->ExpectedHashes.FileSize() > 0)
+	       Tmp->MaximumSize = Tmp->ExpectedHashes.FileSize();
+	    else
+	       Tmp->MaximumSize = strtoll(LookupTag(Message, "Maximum-Size", "0").c_str(), &End, 10);
 	    Tmp->Next = 0;
 	    
 	    // Append it to the list
@@ -385,14 +388,14 @@ int pkgAcqMethod::Run(bool Single)
 	    *I = Tmp;
 	    if (QueueBack == 0)
 	       QueueBack = Tmp;
-	    
+
 	    // Notify that this item is to be fetched.
-	    if (Fetch(Tmp) == false)
+	    if (URIAcquire(Message, Tmp) == false)
 	       Fail();
-	    
-	    break;					     
-	 }   
-      }      
+
+	    break;
+	 }
+      }
    }
 
    Exit();
@@ -400,8 +403,6 @@ int pkgAcqMethod::Run(bool Single)
 }
 									/*}}}*/
 // AcqMethod::PrintStatus - privately really send a log/status message	/*{{{*/
-// ---------------------------------------------------------------------
-/* */
 void pkgAcqMethod::PrintStatus(char const * const header, const char* Format,
 			       va_list &args) const
 {
@@ -456,7 +457,7 @@ void pkgAcqMethod::Redirect(const string &NewURI)
 // ---------------------------------------------------------------------
 /* */
 pkgAcqMethod::FetchResult::FetchResult() : LastModified(0),
-                                   IMSHit(false), Size(0), ResumePoint(0)
+                                   IMSHit(false), Size(0), ResumePoint(0), d(NULL)
 {
 }
 									/*}}}*/
@@ -477,5 +478,9 @@ void pkgAcqMethod::Dequeue() {						/*{{{*/
    delete Tmp;
 }
 									/*}}}*/
-
 pkgAcqMethod::~pkgAcqMethod() {}
+
+pkgAcqMethod::FetchItem::FetchItem() : d(NULL) {}
+pkgAcqMethod::FetchItem::~FetchItem() {}
+
+pkgAcqMethod::FetchResult::~FetchResult() {}

+ 11 - 3
apt-pkg/acquire-method.h

@@ -1,6 +1,5 @@
 // -*- mode: cpp; mode: fold -*-
 // Description								/*{{{*/
-// $Id: acquire-method.h,v 1.15.2.1 2003/12/24 23:09:17 mdz Exp $
 /* ######################################################################
 
    Acquire Method - Method helper class + functions
@@ -53,6 +52,11 @@ class pkgAcqMethod
       // for when we know it or a arbitrary limit when we don't know the
       // filesize (like a InRelease file)
       unsigned long long MaximumSize;
+
+      FetchItem();
+      virtual ~FetchItem();
+      private:
+      void * const d;
    };
    
    struct FetchResult
@@ -67,6 +71,9 @@ class pkgAcqMethod
       
       void TakeHashes(class Hashes &Hash);
       FetchResult();
+      virtual ~FetchResult();
+      private:
+      void * const d;
    };
 
    // State
@@ -76,11 +83,12 @@ class pkgAcqMethod
    std::string FailReason;
    std::string UsedMirror;
    std::string IP;
-   
+
    // Handlers for messages
    virtual bool Configuration(std::string Message);
    virtual bool Fetch(FetchItem * /*Item*/) {return true;};
-   
+   virtual bool URIAcquire(std::string const &/*Message*/, FetchItem *Itm) { return Fetch(Itm); };
+
    // Outgoing messages
    void Fail(bool Transient = false);
    inline void Fail(const char *Why, bool Transient = false) {Fail(std::string(Why),Transient);};

+ 254 - 155
apt-pkg/acquire-worker.cc

@@ -26,7 +26,6 @@
 #include <string>
 #include <vector>
 #include <iostream>
-#include <sstream>
 
 #include <sys/stat.h>
 #include <stdlib.h>
@@ -34,9 +33,7 @@
 #include <signal.h>
 #include <stdio.h>
 #include <errno.h>
-#include <sys/types.h>
-#include <pwd.h>
-#include <grp.h>
+#include <sstream>
 
 #include <apti18n.h>
 									/*}}}*/
@@ -47,7 +44,7 @@ using namespace std;
 // ---------------------------------------------------------------------
 /* */
 pkgAcquire::Worker::Worker(Queue *Q,MethodConfig *Cnf,
-			   pkgAcquireStatus *Log) : Log(Log)
+			   pkgAcquireStatus *log) : d(NULL), Log(log)
 {
    OwnerQ = Q;
    Config = Cnf;
@@ -55,23 +52,18 @@ pkgAcquire::Worker::Worker(Queue *Q,MethodConfig *Cnf,
    CurrentItem = 0;
    TotalSize = 0;
    CurrentSize = 0;
-   
-   Construct();   
+
+   Construct();
 }
 									/*}}}*/
 // Worker::Worker - Constructor for method config startup		/*{{{*/
 // ---------------------------------------------------------------------
 /* */
-pkgAcquire::Worker::Worker(MethodConfig *Cnf)
+pkgAcquire::Worker::Worker(MethodConfig *Cnf) : d(NULL), OwnerQ(NULL), Config(Cnf),
+						Access(Cnf->Access), CurrentItem(NULL),
+						CurrentSize(0), TotalSize(0)
 {
-   OwnerQ = 0;
-   Config = Cnf;
-   Access = Cnf->Access;
-   CurrentItem = 0;
-   TotalSize = 0;
-   CurrentSize = 0;
-   
-   Construct();   
+   Construct();
 }
 									/*}}}*/
 // Worker::Construct - Constructor helper				/*{{{*/
@@ -136,7 +128,7 @@ bool pkgAcquire::Worker::Start()
    }
    for (int I = 0; I != 4; I++)
       SetCloseExec(Pipes[I],true);
-   
+
    // Fork off the process
    Process = ExecFork();
    if (Process == 0)
@@ -145,9 +137,9 @@ bool pkgAcquire::Worker::Start()
       dup2(Pipes[1],STDOUT_FILENO);
       dup2(Pipes[2],STDIN_FILENO);
       SetCloseExec(STDOUT_FILENO,false);
-      SetCloseExec(STDIN_FILENO,false);      
+      SetCloseExec(STDIN_FILENO,false);
       SetCloseExec(STDERR_FILENO,false);
-      
+
       const char *Args[2];
       Args[0] = Method.c_str();
       Args[1] = 0;
@@ -165,7 +157,7 @@ bool pkgAcquire::Worker::Start()
    close(Pipes[2]);
    OutReady = false;
    InReady = true;
-   
+
    // Read the configuration data
    if (WaitFd(InFd) == false ||
        ReadMessages() == false)
@@ -174,7 +166,7 @@ bool pkgAcquire::Worker::Start()
    RunMessages();
    if (OwnerQ != 0)
       SendConfiguration();
-   
+
    return true;
 }
 									/*}}}*/
@@ -201,7 +193,7 @@ bool pkgAcquire::Worker::RunMessages()
 
       if (Debug == true)
 	 clog << " <- " << Access << ':' << QuoteString(Message,"\n") << endl;
-      
+
       // Fetch the message number
       char *End;
       int Number = strtol(Message.c_str(),&End,10);
@@ -209,21 +201,24 @@ bool pkgAcquire::Worker::RunMessages()
 	 return _error->Error("Invalid message from method %s: %s",Access.c_str(),Message.c_str());
 
       string URI = LookupTag(Message,"URI");
-      pkgAcquire::Queue::QItem *Itm = 0;
+      pkgAcquire::Queue::QItem *Itm = NULL;
       if (URI.empty() == false)
 	 Itm = OwnerQ->FindItem(URI,this);
 
-      // update used mirror
-      string UsedMirror = LookupTag(Message,"UsedMirror", "");
-      if (!UsedMirror.empty() && 
-          Itm && 
-          Itm->Description.find(" ") != string::npos) 
+      if (Itm != NULL)
       {
-         Itm->Description.replace(0, Itm->Description.find(" "), UsedMirror);
-         // FIXME: will we need this as well?
-         //Itm->ShortDesc = UsedMirror;
+	 // update used mirror
+	 string UsedMirror = LookupTag(Message,"UsedMirror", "");
+	 if (UsedMirror.empty() == false)
+	 {
+	    for (pkgAcquire::Queue::QItem::owner_iterator O = Itm->Owners.begin(); O != Itm->Owners.end(); ++O)
+	       (*O)->UsedMirror = UsedMirror;
+
+	    if (Itm->Description.find(" ") != string::npos)
+	       Itm->Description.replace(0, Itm->Description.find(" "), UsedMirror);
+	 }
       }
-      
+
       // Determine the message number and dispatch
       switch (Number)
       {
@@ -232,18 +227,18 @@ bool pkgAcquire::Worker::RunMessages()
 	 if (Capabilities(Message) == false)
 	    return _error->Error("Unable to process Capabilities message from %s",Access.c_str());
 	 break;
-	 
+
 	 // 101 Log
 	 case 101:
 	 if (Debug == true)
 	    clog << " <- (log) " << LookupTag(Message,"Message") << endl;
 	 break;
-	 
+
 	 // 102 Status
 	 case 102:
 	 Status = LookupTag(Message,"Message");
 	 break;
-	    
+
          // 103 Redirect
          case 103:
          {
@@ -252,27 +247,49 @@ bool pkgAcquire::Worker::RunMessages()
                _error->Error("Method gave invalid 103 Redirect message");
                break;
             }
- 
-            string NewURI = LookupTag(Message,"New-URI",URI.c_str());
+
+	    std::string const NewURI = LookupTag(Message,"New-URI",URI.c_str());
             Itm->URI = NewURI;
 
 	    ItemDone();
 
-	    pkgAcquire::Item *Owner = Itm->Owner;
-	    pkgAcquire::ItemDesc Desc = *Itm;
-
 	    // Change the status so that it can be dequeued
-	    Owner->Status = pkgAcquire::Item::StatIdle;
+	    for (pkgAcquire::Queue::QItem::owner_iterator O = Itm->Owners.begin(); O != Itm->Owners.end(); ++O)
+	       (*O)->Status = pkgAcquire::Item::StatIdle;
 	    // Mark the item as done (taking care of all queues)
 	    // and then put it in the main queue again
+	    std::vector<Item*> const ItmOwners = Itm->Owners;
 	    OwnerQ->ItemDone(Itm);
-	    OwnerQ->Owner->Enqueue(Desc);
-
-	    if (Log != 0)
-	       Log->Done(Desc);
+	    Itm = NULL;
+	    for (pkgAcquire::Queue::QItem::owner_iterator O = ItmOwners.begin(); O != ItmOwners.end(); ++O)
+	    {
+	       pkgAcquire::Item *Owner = *O;
+	       pkgAcquire::ItemDesc &desc = Owner->GetItemDesc();
+	       // if we change site, treat it as a mirror change
+	       if (URI::SiteOnly(NewURI) != URI::SiteOnly(desc.URI))
+	       {
+		  std::string const OldSite = desc.Description.substr(0, desc.Description.find(" "));
+		  if (likely(APT::String::Startswith(desc.URI, OldSite)))
+		  {
+		     std::string const OldExtra = desc.URI.substr(OldSite.length() + 1);
+		     if (likely(APT::String::Endswith(NewURI, OldExtra)))
+		     {
+			std::string const NewSite = NewURI.substr(0, NewURI.length() - OldExtra.length());
+			Owner->UsedMirror = URI::ArchiveOnly(NewSite);
+			if (desc.Description.find(" ") != string::npos)
+			   desc.Description.replace(0, desc.Description.find(" "), Owner->UsedMirror);
+		     }
+		  }
+	       }
+	       desc.URI = NewURI;
+	       OwnerQ->Owner->Enqueue(desc);
+
+	       if (Log != 0)
+		  Log->Done(desc);
+	    }
             break;
          }
-   
+
 	 // 200 URI Start
 	 case 200:
 	 {
@@ -281,23 +298,27 @@ bool pkgAcquire::Worker::RunMessages()
 	       _error->Error("Method gave invalid 200 URI Start message");
 	       break;
 	    }
-	    
+
 	    CurrentItem = Itm;
 	    CurrentSize = 0;
 	    TotalSize = strtoull(LookupTag(Message,"Size","0").c_str(), NULL, 10);
 	    ResumePoint = strtoull(LookupTag(Message,"Resume-Point","0").c_str(), NULL, 10);
-	    Itm->Owner->Start(Message,strtoull(LookupTag(Message,"Size","0").c_str(), NULL, 10));
+	    for (pkgAcquire::Queue::QItem::owner_iterator O = Itm->Owners.begin(); O != Itm->Owners.end(); ++O)
+	    {
+	       (*O)->Start(Message, TotalSize);
 
-	    // Display update before completion
-	    if (Log != 0 && Log->MorePulses == true)
-	       Log->Pulse(Itm->Owner->GetOwner());
-	    
-	    if (Log != 0)
-	       Log->Fetch(*Itm);
+	       // Display update before completion
+	       if (Log != 0)
+	       {
+		  if (Log->MorePulses == true)
+		     Log->Pulse((*O)->GetOwner());
+		  Log->Fetch((*O)->GetItemDesc());
+	       }
+	    }
 
 	    break;
 	 }
-	 
+
 	 // 201 URI Done
 	 case 201:
 	 {
@@ -306,72 +327,114 @@ bool pkgAcquire::Worker::RunMessages()
 	       _error->Error("Method gave invalid 201 URI Done message");
 	       break;
 	    }
-	    
-	    pkgAcquire::Item *Owner = Itm->Owner;
-	    pkgAcquire::ItemDesc Desc = *Itm;
 
-	    if (RealFileExists(Owner->DestFile))
-	       ChangeOwnerAndPermissionOfFile("201::URIDone", Owner->DestFile.c_str(), "root", "root", 0644);
+	    PrepareFiles("201::URIDone", Itm);
 
 	    // Display update before completion
 	    if (Log != 0 && Log->MorePulses == true)
-	       Log->Pulse(Owner->GetOwner());
-	    
-	    OwnerQ->ItemDone(Itm);
-	    unsigned long long const ServerSize = strtoull(LookupTag(Message,"Size","0").c_str(), NULL, 10);
-            bool isHit = StringToBool(LookupTag(Message,"IMS-Hit"),false) ||
-                         StringToBool(LookupTag(Message,"Alt-IMS-Hit"),false);
-            // Using the https method the server might return 200, but the
-            // If-Modified-Since condition is not satsified, libcurl will
-            // discard the download. In this case, however, TotalSize will be
-            // set to the actual size of the file, while ServerSize will be set
-            // to 0. Therefore, if the item is marked as a hit and the
-            // downloaded size (ServerSize) is 0, we ignore TotalSize.
-	    if (TotalSize != 0 && (!isHit || ServerSize != 0) && ServerSize != TotalSize)
-	       _error->Warning("Size of file %s is not what the server reported %s %llu",
-			       Owner->DestFile.c_str(), LookupTag(Message,"Size","0").c_str(),TotalSize);
-
-	    // see if there is a hash to verify
+	       for (pkgAcquire::Queue::QItem::owner_iterator O = Itm->Owners.begin(); O != Itm->Owners.end(); ++O)
+		  Log->Pulse((*O)->GetOwner());
+
+	    std::string const filename = LookupTag(Message, "Filename", Itm->Owner->DestFile.c_str());
 	    HashStringList ReceivedHashes;
-	    for (char const * const * type = HashString::SupportedHashes(); *type != NULL; ++type)
 	    {
-	       std::string const tagname = std::string(*type) + "-Hash";
-	       std::string const hashsum = LookupTag(Message, tagname.c_str());
-	       if (hashsum.empty() == false)
-		  ReceivedHashes.push_back(HashString(*type, hashsum));
+	       // see if we got hashes to verify
+	       for (char const * const * type = HashString::SupportedHashes(); *type != NULL; ++type)
+	       {
+		  std::string const tagname = std::string(*type) + "-Hash";
+		  std::string const hashsum = LookupTag(Message, tagname.c_str());
+		  if (hashsum.empty() == false)
+		     ReceivedHashes.push_back(HashString(*type, hashsum));
+	       }
+	       // not all methods always sent Hashes our way
+	       if (ReceivedHashes.usable() == false)
+	       {
+		  HashStringList const ExpectedHashes = Itm->GetExpectedHashes();
+		  if (ExpectedHashes.usable() == true && RealFileExists(filename))
+		  {
+		     Hashes calc(ExpectedHashes);
+		     FileFd file(filename, FileFd::ReadOnly, FileFd::None);
+		     calc.AddFD(file);
+		     ReceivedHashes = calc.GetHashStringList();
+		  }
+	       }
 	    }
 
-	    if(_config->FindB("Debug::pkgAcquire::Auth", false) == true)
-	    {
-	       std::clog << "201 URI Done: " << Owner->DescURI() << endl
-		  << "ReceivedHash:" << endl;
-	       for (HashStringList::const_iterator hs = ReceivedHashes.begin(); hs != ReceivedHashes.end(); ++hs)
-		  std::clog <<  "\t- " << hs->toStr() << std::endl;
-	       std::clog << "ExpectedHash:" << endl;
-	       HashStringList expectedHashes = Owner->HashSums();
-	       for (HashStringList::const_iterator hs = expectedHashes.begin(); hs != expectedHashes.end(); ++hs)
-		  std::clog <<  "\t- " << hs->toStr() << std::endl;
-	       std::clog << endl;
-	    }
-	    Owner->Done(Message, ServerSize, ReceivedHashes, Config);
-	    ItemDone();
+	    // only local files can refer other filenames and counting them as fetched would be unfair
+	    if (Log !=  NULL && filename != Itm->Owner->DestFile)
+	       Log->Fetched(ReceivedHashes.FileSize(),atoi(LookupTag(Message,"Resume-Point","0").c_str()));
+
+	    std::vector<Item*> const ItmOwners = Itm->Owners;
+	    OwnerQ->ItemDone(Itm);
+	    Itm = NULL;
 
-	    // Log that we are done
-	    if (Log != 0)
+	    bool const isIMSHit = StringToBool(LookupTag(Message,"IMS-Hit"),false) ||
+	       StringToBool(LookupTag(Message,"Alt-IMS-Hit"),false);
+	    for (pkgAcquire::Queue::QItem::owner_iterator O = ItmOwners.begin(); O != ItmOwners.end(); ++O)
 	    {
-	       if (isHit)
+	       pkgAcquire::Item * const Owner = *O;
+	       HashStringList const ExpectedHashes = Owner->GetExpectedHashes();
+	       if(_config->FindB("Debug::pkgAcquire::Auth", false) == true)
+	       {
+		  std::clog << "201 URI Done: " << Owner->DescURI() << endl
+		     << "ReceivedHash:" << endl;
+		  for (HashStringList::const_iterator hs = ReceivedHashes.begin(); hs != ReceivedHashes.end(); ++hs)
+		     std::clog <<  "\t- " << hs->toStr() << std::endl;
+		  std::clog << "ExpectedHash:" << endl;
+		  for (HashStringList::const_iterator hs = ExpectedHashes.begin(); hs != ExpectedHashes.end(); ++hs)
+		     std::clog <<  "\t- " << hs->toStr() << std::endl;
+		  std::clog << endl;
+	       }
+
+	       // decide if what we got is what we expected
+	       bool consideredOkay = false;
+	       if (ExpectedHashes.usable())
 	       {
-		  /* Hide 'hits' for local only sources - we also manage to
-		     hide gets */
-		  if (Config->LocalOnly == false)
-		     Log->IMSHit(Desc);
-	       }	       
+		  if (ReceivedHashes.usable() == false)
+		  {
+		     /* IMS-Hits can't be checked here as we will have uncompressed file,
+			but the hashes for the compressed file. What we have was good through
+			so all we have to ensure later is that we are not stalled. */
+		     consideredOkay = isIMSHit;
+		  }
+		  else if (ReceivedHashes == ExpectedHashes)
+		     consideredOkay = true;
+		  else
+		     consideredOkay = false;
+
+	       }
+	       else if (Owner->HashesRequired() == true)
+		  consideredOkay = false;
 	       else
-		  Log->Done(Desc);
+		  consideredOkay = true;
+
+	       if (consideredOkay == true)
+		  consideredOkay = Owner->VerifyDone(Message, Config);
+	       else // hashsum mismatch
+		  Owner->Status = pkgAcquire::Item::StatAuthError;
+
+	       if (consideredOkay == true)
+	       {
+		  Owner->Done(Message, ReceivedHashes, Config);
+		  if (Log != 0)
+		  {
+		     if (isIMSHit)
+			Log->IMSHit(Owner->GetItemDesc());
+		     else
+			Log->Done(Owner->GetItemDesc());
+		  }
+	       }
+	       else
+	       {
+		  Owner->Failed(Message,Config);
+		  if (Log != 0)
+		     Log->Fail(Owner->GetItemDesc());
+	       }
 	    }
+	    ItemDone();
 	    break;
-	 }	 
-	 
+	 }
+
 	 // 400 URI Failure
 	 case 400:
 	 {
@@ -382,44 +445,46 @@ bool pkgAcquire::Worker::RunMessages()
 	       break;
 	    }
 
+	    PrepareFiles("400::URIFailure", Itm);
+
 	    // Display update before completion
 	    if (Log != 0 && Log->MorePulses == true)
-	       Log->Pulse(Itm->Owner->GetOwner());
-
-	    pkgAcquire::Item *Owner = Itm->Owner;
-	    pkgAcquire::ItemDesc Desc = *Itm;
-
-	    if (RealFileExists(Owner->DestFile))
-	       ChangeOwnerAndPermissionOfFile("400::URIFailure", Owner->DestFile.c_str(), "root", "root", 0644);
+	       for (pkgAcquire::Queue::QItem::owner_iterator O = Itm->Owners.begin(); O != Itm->Owners.end(); ++O)
+		  Log->Pulse((*O)->GetOwner());
 
+	    std::vector<Item*> const ItmOwners = Itm->Owners;
 	    OwnerQ->ItemDone(Itm);
+	    Itm = NULL;
 
-	    // set some status
-	    if(LookupTag(Message,"FailReason") == "Timeout" || 
-	       LookupTag(Message,"FailReason") == "TmpResolveFailure" ||
-	       LookupTag(Message,"FailReason") == "ResolveFailure" ||
-	       LookupTag(Message,"FailReason") == "ConnectionRefused") 
-	       Owner->Status = pkgAcquire::Item::StatTransientNetworkError;
+	    for (pkgAcquire::Queue::QItem::owner_iterator O = ItmOwners.begin(); O != ItmOwners.end(); ++O)
+	    {
+	       // set some status
+	       if(LookupTag(Message,"FailReason") == "Timeout" ||
+		     LookupTag(Message,"FailReason") == "TmpResolveFailure" ||
+		     LookupTag(Message,"FailReason") == "ResolveFailure" ||
+		     LookupTag(Message,"FailReason") == "ConnectionRefused")
+		  (*O)->Status = pkgAcquire::Item::StatTransientNetworkError;
 
-	    Owner->Failed(Message,Config);
-	    ItemDone();
+	       (*O)->Failed(Message,Config);
 
-	    if (Log != 0)
-	       Log->Fail(Desc);
+	       if (Log != 0)
+		  Log->Fail((*O)->GetItemDesc());
+	    }
+	    ItemDone();
 
 	    break;
-	 }	 
-	 
+	 }
+
 	 // 401 General Failure
 	 case 401:
 	 _error->Error("Method %s General failure: %s",Access.c_str(),LookupTag(Message,"Message").c_str());
 	 break;
-	 
+
 	 // 403 Media Change
 	 case 403:
-	 MediaChange(Message); 
+	 MediaChange(Message);
 	 break;
-      }      
+      }
    }
    return true;
 }
@@ -432,7 +497,7 @@ bool pkgAcquire::Worker::Capabilities(string Message)
 {
    if (Config == 0)
       return true;
-   
+
    Config->Version = LookupTag(Message,"Version");
    Config->SingleInstance = StringToBool(LookupTag(Message,"Single-Instance"),false);
    Config->Pipeline = StringToBool(LookupTag(Message,"Pipeline"),false);
@@ -447,13 +512,13 @@ bool pkgAcquire::Worker::Capabilities(string Message)
       clog << "Configured access method " << Config->Access << endl;
       clog << "Version:" << Config->Version <<
 	      " SingleInstance:" << Config->SingleInstance <<
-	      " Pipeline:" << Config->Pipeline << 
-	      " SendConfig:" << Config->SendConfig << 
-	      " LocalOnly: " << Config->LocalOnly << 
-	      " NeedsCleanup: " << Config->NeedsCleanup << 
+	      " Pipeline:" << Config->Pipeline <<
+	      " SendConfig:" << Config->SendConfig <<
+	      " LocalOnly: " << Config->LocalOnly <<
+	      " NeedsCleanup: " << Config->NeedsCleanup <<
 	      " Removable: " << Config->Removable << endl;
    }
-   
+
    return true;
 }
 									/*}}}*/
@@ -463,14 +528,14 @@ bool pkgAcquire::Worker::Capabilities(string Message)
 bool pkgAcquire::Worker::MediaChange(string Message)
 {
    int status_fd = _config->FindI("APT::Status-Fd",-1);
-   if(status_fd > 0) 
+   if(status_fd > 0)
    {
       string Media = LookupTag(Message,"Media");
-      string Drive = LookupTag(Message,"Drive"); 
+      string Drive = LookupTag(Message,"Drive");
       ostringstream msg,status;
       ioprintf(msg,_("Please insert the disc labeled: "
 		     "'%s' "
-		     "in the drive '%s' and press enter."),
+		     "in the drive '%s' and press [Enter]."),
 	       Media.c_str(),Drive.c_str());
       status << "media-change: "  // message
 	     << Media  << ":"     // media
@@ -536,21 +601,29 @@ bool pkgAcquire::Worker::QueueItem(pkgAcquire::Queue::QItem *Item)
 {
    if (OutFd == -1)
       return false;
-   
+
    string Message = "600 URI Acquire\n";
    Message.reserve(300);
    Message += "URI: " + Item->URI;
    Message += "\nFilename: " + Item->Owner->DestFile;
-   HashStringList const hsl = Item->Owner->HashSums();
+
+   HashStringList const hsl = Item->GetExpectedHashes();
    for (HashStringList::const_iterator hs = hsl.begin(); hs != hsl.end(); ++hs)
       Message += "\nExpected-" + hs->HashType() + ": " + hs->HashValue();
-   if(Item->Owner->FileSize > 0)
+
+   if (hsl.FileSize() == 0)
    {
-      string MaximumSize;
-      strprintf(MaximumSize, "%llu", Item->Owner->FileSize);
-      Message += "\nMaximum-Size: " + MaximumSize;
+      unsigned long long FileSize = Item->GetMaximumSize();
+      if(FileSize > 0)
+      {
+	 string MaximumSize;
+	 strprintf(MaximumSize, "%llu", FileSize);
+	 Message += "\nMaximum-Size: " + MaximumSize;
+      }
    }
-   Message += Item->Owner->Custom600Headers();
+
+   Item->SyncDestinationFiles();
+   Message += Item->Custom600Headers();
    Message += "\n\n";
 
    if (RealFileExists(Item->Owner->DestFile))
@@ -564,7 +637,7 @@ bool pkgAcquire::Worker::QueueItem(pkgAcquire::Queue::QItem *Item)
       clog << " -> " << Access << ':' << QuoteString(Message,"\n") << endl;
    OutQueue += Message;
    OutReady = true;
-   
+
    return true;
 }
 									/*}}}*/
@@ -586,7 +659,7 @@ bool pkgAcquire::Worker::OutFdReady()
    OutQueue.erase(0,Res);
    if (OutQueue.empty() == true)
       OutReady = false;
-   
+
    return true;
 }
 									/*}}}*/
@@ -608,7 +681,7 @@ bool pkgAcquire::Worker::InFdReady()
 bool pkgAcquire::Worker::MethodFailure()
 {
    _error->Error("Method %s has died unexpectedly!",Access.c_str());
-   
+
    // do not reap the child here to show meaningfull error to the user
    ExecWait(Process,Access.c_str(),false);
    Process = -1;
@@ -620,26 +693,22 @@ bool pkgAcquire::Worker::MethodFailure()
    InReady = false;
    OutQueue = string();
    MessageQueue.erase(MessageQueue.begin(),MessageQueue.end());
-   
+
    return false;
 }
 									/*}}}*/
-// Worker::Pulse - Called periodically 					/*{{{*/
+// Worker::Pulse - Called periodically					/*{{{*/
 // ---------------------------------------------------------------------
 /* */
 void pkgAcquire::Worker::Pulse()
 {
    if (CurrentItem == 0)
       return;
- 
+
    struct stat Buf;
    if (stat(CurrentItem->Owner->DestFile.c_str(),&Buf) != 0)
       return;
    CurrentSize = Buf.st_size;
-   
-   // Hmm? Should not happen...
-   if (CurrentSize > TotalSize && TotalSize != 0)
-      TotalSize = CurrentSize;
 }
 									/*}}}*/
 // Worker::ItemDone - Called when the current item is finished		/*{{{*/
@@ -653,3 +722,33 @@ void pkgAcquire::Worker::ItemDone()
    Status = string();
 }
 									/*}}}*/
+void pkgAcquire::Worker::PrepareFiles(char const * const caller, pkgAcquire::Queue::QItem const * const Itm)/*{{{*/
+{
+   if (RealFileExists(Itm->Owner->DestFile))
+   {
+      ChangeOwnerAndPermissionOfFile(caller, Itm->Owner->DestFile.c_str(), "root", "root", 0644);
+      std::string const filename = Itm->Owner->DestFile;
+      for (pkgAcquire::Queue::QItem::owner_iterator O = Itm->Owners.begin(); O != Itm->Owners.end(); ++O)
+      {
+	 pkgAcquire::Item const * const Owner = *O;
+	 if (Owner->DestFile == filename)
+	    continue;
+	 unlink(Owner->DestFile.c_str());
+	 if (link(filename.c_str(), Owner->DestFile.c_str()) != 0)
+	 {
+	    // different mounts can't happen for us as we download to lists/ by default,
+	    // but if the system is reused by others the locations can potentially be on
+	    // different disks, so use symlink as poor-men replacement.
+	    // FIXME: Real copying as last fallback, but that is costly, so offload to a method preferable
+	    if (symlink(filename.c_str(), Owner->DestFile.c_str()) != 0)
+	       _error->Error("Can't create (sym)link of file %s to %s", filename.c_str(), Owner->DestFile.c_str());
+	 }
+      }
+   }
+   else
+   {
+      for (pkgAcquire::Queue::QItem::owner_iterator O = Itm->Owners.begin(); O != Itm->Owners.end(); ++O)
+	 unlink((*O)->DestFile.c_str());
+   }
+}
+									/*}}}*/

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

@@ -1,6 +1,5 @@
 // -*- mode: cpp; mode: fold -*-
 // Description								/*{{{*/
-// $Id: acquire-worker.h,v 1.12 2001/02/20 07:03:17 jgg Exp $
 /* ######################################################################
 
    Acquire Worker - Worker process manager
@@ -48,7 +47,7 @@
 class pkgAcquire::Worker : public WeakPointable
 {
    /** \brief dpointer placeholder (for later in case we need it) */
-   void *d;
+   void * const d;
   
    friend class pkgAcquire;
    
@@ -318,7 +317,7 @@ class pkgAcquire::Worker : public WeakPointable
     *  \param Config A location in which to store information about
     *  the fetch method.
     */
-   Worker(MethodConfig *Config);
+   explicit Worker(MethodConfig *Config);
 
    /** \brief Clean up this worker.
     *
@@ -326,6 +325,9 @@ class pkgAcquire::Worker : public WeakPointable
     *  \b false, also rudely interrupts the worker with a SIGINT.
     */
    virtual ~Worker();
+
+private:
+   APT_HIDDEN void PrepareFiles(char const * const caller, pkgAcquire::Queue::QItem const * const Itm);
 };
 
 /** @} */

+ 136 - 27
apt-pkg/acquire.cc

@@ -23,6 +23,7 @@
 #include <apt-pkg/strutl.h>
 #include <apt-pkg/fileutl.h>
 
+#include <algorithm>
 #include <string>
 #include <vector>
 #include <iostream>
@@ -40,7 +41,6 @@
 #include <sys/select.h>
 #include <errno.h>
 #include <sys/stat.h>
-#include <sys/types.h>
 
 #include <apti18n.h>
 									/*}}}*/
@@ -50,13 +50,13 @@ using namespace std;
 // Acquire::pkgAcquire - Constructor					/*{{{*/
 // ---------------------------------------------------------------------
 /* We grab some runtime state from the configuration space */
-pkgAcquire::pkgAcquire() : LockFD(-1), Queues(0), Workers(0), Configs(0), Log(NULL), ToFetch(0),
+pkgAcquire::pkgAcquire() : LockFD(-1), d(NULL), Queues(0), Workers(0), Configs(0), Log(NULL), ToFetch(0),
 			   Debug(_config->FindB("Debug::pkgAcquire",false)),
 			   Running(false)
 {
    Initialize();
 }
-pkgAcquire::pkgAcquire(pkgAcquireStatus *Progress) : LockFD(-1), Queues(0), Workers(0),
+pkgAcquire::pkgAcquire(pkgAcquireStatus *Progress) : LockFD(-1), d(NULL), Queues(0), Workers(0),
 			   Configs(0), Log(NULL), ToFetch(0),
 			   Debug(_config->FindB("Debug::pkgAcquire",false)),
 			   Running(false)
@@ -652,8 +652,8 @@ pkgAcquire::MethodConfig::MethodConfig() : d(NULL), Next(0), SingleInstance(fals
 // Queue::Queue - Constructor						/*{{{*/
 // ---------------------------------------------------------------------
 /* */
-pkgAcquire::Queue::Queue(string Name,pkgAcquire *Owner) : d(NULL), Next(0),
-   Name(Name), Items(0), Workers(0), Owner(Owner), PipeDepth(0), MaxPipeDepth(1)
+pkgAcquire::Queue::Queue(string const &name,pkgAcquire * const owner) : d(NULL), Next(0),
+   Name(name), Items(0), Workers(0), Owner(owner), PipeDepth(0), MaxPipeDepth(1)
 {
 }
 									/*}}}*/
@@ -679,10 +679,14 @@ bool pkgAcquire::Queue::Enqueue(ItemDesc &Item)
 {
    QItem **I = &Items;
    // move to the end of the queue and check for duplicates here
+   HashStringList const hsl = Item.Owner->GetExpectedHashes();
    for (; *I != 0; I = &(*I)->Next)
-      if (Item.URI == (*I)->URI) 
+      if (Item.URI == (*I)->URI || hsl == (*I)->Owner->GetExpectedHashes())
       {
-	 Item.Owner->Status = Item::StatDone;
+	 if (_config->FindB("Debug::pkgAcquire::Worker",false) == true)
+	    std::cerr << " @ Queue: Action combined for " << Item.URI << " and " << (*I)->URI << std::endl;
+	 (*I)->Owners.push_back(Item.Owner);
+	 Item.Owner->Status = (*I)->Owner->Status;
 	 return false;
       }
 
@@ -705,13 +709,13 @@ bool pkgAcquire::Queue::Dequeue(Item *Owner)
 {
    if (Owner->Status == pkgAcquire::Item::StatFetching)
       return _error->Error("Tried to dequeue a fetching object");
-       
+
    bool Res = false;
-   
+
    QItem **I = &Items;
    for (; *I != 0;)
    {
-      if ((*I)->Owner == Owner)
+      if (Owner == (*I)->Owner)
       {
 	 QItem *Jnk= *I;
 	 *I = (*I)->Next;
@@ -722,7 +726,7 @@ bool pkgAcquire::Queue::Dequeue(Item *Owner)
       else
 	 I = &(*I)->Next;
    }
-   
+
    return Res;
 }
 									/*}}}*/
@@ -799,9 +803,12 @@ pkgAcquire::Queue::QItem *pkgAcquire::Queue::FindItem(string URI,pkgAcquire::Wor
 bool pkgAcquire::Queue::ItemDone(QItem *Itm)
 {
    PipeDepth--;
-   if (Itm->Owner->Status == pkgAcquire::Item::StatFetching)
-      Itm->Owner->Status = pkgAcquire::Item::StatDone;
-   
+   for (QItem::owner_iterator O = Itm->Owners.begin(); O != Itm->Owners.end(); ++O)
+   {
+      if ((*O)->Status == pkgAcquire::Item::StatFetching)
+	 (*O)->Status = pkgAcquire::Item::StatDone;
+   }
+
    if (Itm->Owner->QueueCounter <= 1)
       Owner->Dequeue(Itm->Owner);
    else
@@ -809,7 +816,7 @@ bool pkgAcquire::Queue::ItemDone(QItem *Itm)
       Dequeue(Itm->Owner);
       Owner->Bump();
    }
-   
+
    return Cycle();
 }
 									/*}}}*/
@@ -824,7 +831,7 @@ bool pkgAcquire::Queue::Cycle()
 
    if (PipeDepth < 0)
       return _error->Error("Pipedepth failure");
-			   
+
    // Look for a queable item
    QItem *I = Items;
    while (PipeDepth < (signed)MaxPipeDepth)
@@ -832,18 +839,19 @@ bool pkgAcquire::Queue::Cycle()
       for (; I != 0; I = I->Next)
 	 if (I->Owner->Status == pkgAcquire::Item::StatIdle)
 	    break;
-      
+
       // Nothing to do, queue is idle.
       if (I == 0)
 	 return true;
-      
+
       I->Worker = Workers;
-      I->Owner->Status = pkgAcquire::Item::StatFetching;
+      for (QItem::owner_iterator O = I->Owners.begin(); O != I->Owners.end(); ++O)
+	 (*O)->Status = pkgAcquire::Item::StatFetching;
       PipeDepth++;
       if (Workers->QueueItem(I) == false)
 	 return false;
    }
-   
+
    return true;
 }
 									/*}}}*/
@@ -855,10 +863,98 @@ void pkgAcquire::Queue::Bump()
    Cycle();
 }
 									/*}}}*/
+HashStringList pkgAcquire::Queue::QItem::GetExpectedHashes() const	/*{{{*/
+{
+   /* each Item can have multiple owners and each owner might have different
+      hashes, even if that is unlikely in practice and if so at least some
+      owners will later fail. There is one situation through which is not a
+      failure and still needs this handling: Two owners who expect the same
+      file, but one owner only knows the SHA1 while the other only knows SHA256. */
+   HashStringList superhsl;
+   for (pkgAcquire::Queue::QItem::owner_iterator O = Owners.begin(); O != Owners.end(); ++O)
+   {
+      HashStringList const hsl = (*O)->GetExpectedHashes();
+      if (hsl.usable() == false)
+	 continue;
+      if (superhsl.usable() == false)
+	 superhsl = hsl;
+      else
+      {
+	 // we merge both lists - if we find disagreement send no hashes
+	 HashStringList::const_iterator hs = hsl.begin();
+	 for (; hs != hsl.end(); ++hs)
+	    if (superhsl.push_back(*hs) == false)
+	       break;
+	 if (hs != hsl.end())
+	 {
+	    superhsl.clear();
+	    break;
+	 }
+      }
+   }
+   return superhsl;
+}
+									/*}}}*/
+APT_PURE unsigned long long pkgAcquire::Queue::QItem::GetMaximumSize() const	/*{{{*/
+{
+   unsigned long long Maximum = std::numeric_limits<unsigned long long>::max();
+   for (pkgAcquire::Queue::QItem::owner_iterator O = Owners.begin(); O != Owners.end(); ++O)
+   {
+      if ((*O)->FileSize == 0)
+	 continue;
+      Maximum = std::min(Maximum, (*O)->FileSize);
+   }
+   if (Maximum == std::numeric_limits<unsigned long long>::max())
+      return 0;
+   return Maximum;
+}
+									/*}}}*/
+void pkgAcquire::Queue::QItem::SyncDestinationFiles() const		/*{{{*/
+{
+   /* ensure that the first owner has the best partial file of all and
+      the rest have (potentially dangling) symlinks to it so that
+      everything (like progress reporting) finds it easily */
+   std::string superfile = Owner->DestFile;
+   off_t supersize = 0;
+   for (pkgAcquire::Queue::QItem::owner_iterator O = Owners.begin(); O != Owners.end(); ++O)
+   {
+      if ((*O)->DestFile == superfile)
+	 continue;
+      struct stat file;
+      if (lstat((*O)->DestFile.c_str(),&file) == 0)
+      {
+	 if ((file.st_mode & S_IFREG) == 0)
+	    unlink((*O)->DestFile.c_str());
+	 else if (supersize < file.st_size)
+	 {
+	    supersize = file.st_size;
+	    unlink(superfile.c_str());
+	    rename((*O)->DestFile.c_str(), superfile.c_str());
+	 }
+	 else
+	    unlink((*O)->DestFile.c_str());
+	 if (symlink(superfile.c_str(), (*O)->DestFile.c_str()) != 0)
+	 {
+	    ; // not a problem per-se and no real alternative
+	 }
+      }
+   }
+}
+									/*}}}*/
+std::string pkgAcquire::Queue::QItem::Custom600Headers() const		/*{{{*/
+{
+   /* The others are relatively easy to merge, but this one?
+      Lets not merge and see how far we can run with it…
+      Likely, nobody will ever notice as all the items will
+      be of the same class and hence generate the same headers. */
+   return Owner->Custom600Headers();
+}
+									/*}}}*/
+
 // AcquireStatus::pkgAcquireStatus - Constructor			/*{{{*/
 // ---------------------------------------------------------------------
 /* */
-pkgAcquireStatus::pkgAcquireStatus() : d(NULL), Percent(0), Update(true), MorePulses(false)
+pkgAcquireStatus::pkgAcquireStatus() : d(NULL), Percent(-1), Update(true), MorePulses(false)
 {
    Start();
 }
@@ -914,9 +1010,9 @@ bool pkgAcquireStatus::Pulse(pkgAcquire *Owner)
       {
 	 CurrentBytes += I->CurrentSize;
 	 ResumeSize += I->ResumePoint;
-	 
+
 	 // Files with unknown size always have 100% completion
-	 if (I->CurrentItem->Owner->FileSize == 0 && 
+	 if (I->CurrentItem->Owner->FileSize == 0 &&
 	     I->CurrentItem->Owner->Complete == false)
 	    TotalBytes += I->CurrentSize;
       }
@@ -957,13 +1053,17 @@ bool pkgAcquireStatus::Pulse(pkgAcquire *Owner)
       Time = NewTime;
    }
 
+   double const OldPercent = Percent;
    // calculate the percentage, if we have too little data assume 1%
    if (TotalBytes > 0 && UnfetchedReleaseFiles)
       Percent = 0;
-   else 
+   else
       // use both files and bytes because bytes can be unreliable
-      Percent = (0.8 * (CurrentBytes/float(TotalBytes)*100.0) + 
+      Percent = (0.8 * (CurrentBytes/float(TotalBytes)*100.0) +
                  0.2 * (CurrentItems/float(TotalItems)*100.0));
+   double const DiffPercent = Percent - OldPercent;
+   if (DiffPercent < 0.001 && _config->FindB("Acquire::Progress::Diffpercent", false) == true)
+      return true;
 
    int fd = _config->FindI("APT::Status-Fd",-1);
    if(fd > 0) 
@@ -981,11 +1081,11 @@ bool pkgAcquireStatus::Pulse(pkgAcquire *Owner)
 	 snprintf(msg,sizeof(msg), _("Retrieving file %li of %li (%s remaining)"), i, TotalItems, TimeToStr(ETA).c_str());
       else
 	 snprintf(msg,sizeof(msg), _("Retrieving file %li of %li"), i, TotalItems);
-	 
+
       // build the status str
       status << "dlstatus:" << i
              << ":"  << std::setprecision(3) << Percent
-             << ":" << msg 
+             << ":" << msg
              << endl;
 
       std::string const dlstatus = status.str();
@@ -1042,6 +1142,15 @@ void pkgAcquireStatus::Fetched(unsigned long long Size,unsigned long long Resume
 }
 									/*}}}*/
 
+pkgAcquire::UriIterator::UriIterator(pkgAcquire::Queue *Q) : d(NULL), CurQ(Q), CurItem(0)
+{
+   while (CurItem == 0 && CurQ != 0)
+   {
+      CurItem = CurQ->Items;
+      CurQ = CurQ->Next;
+   }
+}
+
 APT_CONST pkgAcquire::UriIterator::~UriIterator() {}
 APT_CONST pkgAcquire::MethodConfig::~MethodConfig() {}
 APT_CONST pkgAcquireStatus::~pkgAcquireStatus() {}

+ 36 - 24
apt-pkg/acquire.h

@@ -1,6 +1,5 @@
 // -*- mode: cpp; mode: fold -*-
 // Description								/*{{{*/
-// $Id: acquire.h,v 1.29.2.1 2003/12/24 23:09:17 mdz Exp $
 /* ######################################################################
 
    Acquire - File Acquiration
@@ -68,9 +67,10 @@
 
 #include <apt-pkg/macros.h>
 #include <apt-pkg/weakptr.h>
+#include <apt-pkg/hashes.h>
 
-#include <vector>
 #include <string>
+#include <vector>
 
 #include <stddef.h>
 #include <sys/time.h>
@@ -101,7 +101,7 @@ class pkgAcquire
    /** \brief FD of the Lock file we acquire in Setup (if any) */
    int LockFD;
    /** \brief dpointer placeholder (for later in case we need it) */
-   void *d;
+   void * const d;
 
    public:
    
@@ -369,7 +369,7 @@ class pkgAcquire
    bool GetLock(std::string const &Lock);
 
    /** \brief Construct a new pkgAcquire. */
-   pkgAcquire(pkgAcquireStatus *Log);
+   explicit pkgAcquire(pkgAcquireStatus *Log);
    pkgAcquire();
 
    /** \brief Destroy this pkgAcquire object.
@@ -390,13 +390,13 @@ class pkgAcquire
  */
 struct pkgAcquire::ItemDesc : public WeakPointable
 {
-   /** \brief The URI from which to download this item. */
+   /** \brief URI from which to download this item. */
    std::string URI;
-   /** brief A description of this item. */
+   /** \brief description of this item. */
    std::string Description;
-   /** brief A shorter description of this item. */
+   /** \brief shorter description of this item. */
    std::string ShortDesc;
-   /** brief The underlying item which is to be downloaded. */
+   /** \brief underlying item which is to be downloaded. */
    Item *Owner;
 };
 									/*}}}*/
@@ -411,7 +411,7 @@ class pkgAcquire::Queue
    friend class pkgAcquire::Worker;
 
    /** \brief dpointer placeholder (for later in case we need it) */
-   void *d;
+   void * const d;
 
    /** \brief The next queue in the pkgAcquire object's list of queues. */
    Queue *Next;
@@ -419,13 +419,18 @@ class pkgAcquire::Queue
    protected:
 
    /** \brief A single item placed in this queue. */
-   struct QItem : pkgAcquire::ItemDesc
+   struct QItem : public ItemDesc
    {
       /** \brief The next item in the queue. */
       QItem *Next;
       /** \brief The worker associated with this item, if any. */
       pkgAcquire::Worker *Worker;
 
+      /** \brief The underlying items interested in the download */
+      std::vector<Item*> Owners;
+
+      typedef std::vector<Item*>::const_iterator owner_iterator;
+
       /** \brief Assign the ItemDesc portion of this QItem from
        *  another ItemDesc
        */
@@ -434,10 +439,24 @@ class pkgAcquire::Queue
 	 URI = I.URI;
 	 Description = I.Description;
 	 ShortDesc = I.ShortDesc;
+	 Owners.clear();
+	 Owners.push_back(I.Owner);
 	 Owner = I.Owner;
       };
+
+      /** @return the sum of all expected hashes by all owners */
+      HashStringList GetExpectedHashes() const;
+
+      /** @return smallest maximum size of all owners */
+      unsigned long long GetMaximumSize() const;
+
+      /** \brief get partial files in order */
+      void SyncDestinationFiles() const;
+
+      /** @return the custom headers to use for this item */
+      std::string Custom600Headers() const;
    };
-   
+
    /** \brief The name of this queue. */
    std::string Name;
 
@@ -557,7 +576,7 @@ class pkgAcquire::Queue
     *  \param Name The name of the new queue.
     *  \param Owner The download process that owns the new queue.
     */
-   Queue(std::string Name,pkgAcquire *Owner);
+   Queue(std::string const &Name,pkgAcquire * const Owner);
 
    /** Shut down all the worker processes associated with this queue
     *  and empty the queue.
@@ -569,7 +588,7 @@ class pkgAcquire::Queue
 class pkgAcquire::UriIterator
 {
    /** \brief dpointer placeholder (for later in case we need it) */
-   void *d;
+   void * const d;
 
    /** The next queue to iterate over. */
    pkgAcquire::Queue *CurQ;
@@ -590,7 +609,7 @@ class pkgAcquire::UriIterator
       }
    };
    
-   inline pkgAcquire::ItemDesc const *operator ->() const {return CurItem;};
+   inline pkgAcquire::Queue::QItem const *operator ->() const {return CurItem;};
    inline bool operator !=(UriIterator const &rhs) const {return rhs.CurQ != CurQ || rhs.CurItem != CurItem;};
    inline bool operator ==(UriIterator const &rhs) const {return rhs.CurQ == CurQ && rhs.CurItem == CurItem;};
    
@@ -598,14 +617,7 @@ class pkgAcquire::UriIterator
     *
     *  \param Q The queue over which this UriIterator should iterate.
     */
-   UriIterator(pkgAcquire::Queue *Q) : d(NULL), CurQ(Q), CurItem(0)
-   {
-      while (CurItem == 0 && CurQ != 0)
-      {
-	 CurItem = CurQ->Items;
-	 CurQ = CurQ->Next;
-      }
-   }   
+   explicit UriIterator(pkgAcquire::Queue *Q);
    virtual ~UriIterator();
 };
 									/*}}}*/
@@ -613,7 +625,7 @@ class pkgAcquire::UriIterator
 struct pkgAcquire::MethodConfig
 {
    /** \brief dpointer placeholder (for later in case we need it) */
-   void *d;
+   void * const d;
    
    /** \brief The next link on the acquire method list.
     *
@@ -674,7 +686,7 @@ struct pkgAcquire::MethodConfig
 class pkgAcquireStatus
 {
    /** \brief dpointer placeholder (for later in case we need it) */
-   void *d;
+   void * const d;
 
    protected:
    

+ 13 - 29
apt-pkg/algorithms.cc

@@ -19,9 +19,7 @@
 #include <apt-pkg/algorithms.h>
 #include <apt-pkg/error.h>
 #include <apt-pkg/configuration.h>
-#include <apt-pkg/sptr.h>
 #include <apt-pkg/edsp.h>
-#include <apt-pkg/progress.h>
 #include <apt-pkg/depcache.h>
 #include <apt-pkg/packagemanager.h>
 #include <apt-pkg/pkgcache.h>
@@ -43,7 +41,7 @@ pkgProblemResolver *pkgProblemResolver::This = 0;
 /* The legacy translations here of input Pkg iterators is obsolete, 
    this is not necessary since the pkgCaches are fully shared now. */
 pkgSimulate::pkgSimulate(pkgDepCache *Cache) : pkgPackageManager(Cache),
-		            iPolicy(Cache),
+		            d(NULL), iPolicy(Cache),
 			    Sim(&Cache->GetCache(),&iPolicy),
 			    group(Sim)
 {
@@ -476,8 +474,8 @@ void pkgProblemResolver::MakeScores()
    }
 
    // Copy the scores to advoid additive looping
-   SPtrArray<int> OldScores = new int[Size];
-   memcpy(OldScores,Scores,sizeof(*Scores)*Size);
+   std::unique_ptr<int[]> OldScores(new int[Size]);
+   memcpy(OldScores.get(),Scores,sizeof(*Scores)*Size);
       
    /* Now we cause 1 level of dependency inheritance, that is we add the 
       score of the packages that depend on the target Package. This 
@@ -638,14 +636,6 @@ bool pkgProblemResolver::DoUpgrade(pkgCache::PkgIterator Pkg)
 }
 									/*}}}*/
 // ProblemResolver::Resolve - calls a resolver to fix the situation	/*{{{*/
-// ---------------------------------------------------------------------
-/* */
-#if APT_PKG_ABI < 413
-bool pkgProblemResolver::Resolve(bool BrokenFix)
-{
-   return Resolve(BrokenFix, NULL);
-}
-#endif
 bool pkgProblemResolver::Resolve(bool BrokenFix, OpProgress * const Progress)
 {
    std::string const solver = _config->Find("APT::Solver", "internal");
@@ -710,17 +700,17 @@ bool pkgProblemResolver::ResolveInternal(bool const BrokenFix)
       operates from highest score to lowest. This prevents problems when
       high score packages cause the removal of lower score packages that
       would cause the removal of even lower score packages. */
-   SPtrArray<pkgCache::Package *> PList = new pkgCache::Package *[Size];
-   pkgCache::Package **PEnd = PList;
+   std::unique_ptr<pkgCache::Package *[]> PList(new pkgCache::Package *[Size]);
+   pkgCache::Package **PEnd = PList.get();
    for (pkgCache::PkgIterator I = Cache.PkgBegin(); I.end() == false; ++I)
       *PEnd++ = I;
    This = this;
-   qsort(PList,PEnd - PList,sizeof(*PList),&ScoreSort);
+   qsort(PList.get(),PEnd - PList.get(),sizeof(PList[0]),&ScoreSort);
 
    if (_config->FindB("Debug::pkgProblemResolver::ShowScores",false) == true)
    {
       clog << "Show Scores" << endl;
-      for (pkgCache::Package **K = PList; K != PEnd; K++)
+      for (pkgCache::Package **K = PList.get(); K != PEnd; K++)
          if (Scores[(*K)->ID] != 0)
          {
            pkgCache::PkgIterator Pkg(Cache,*K);
@@ -742,7 +732,7 @@ bool pkgProblemResolver::ResolveInternal(bool const BrokenFix)
    for (int Counter = 0; Counter != 10 && Change == true; Counter++)
    {
       Change = false;
-      for (pkgCache::Package **K = PList; K != PEnd; K++)
+      for (pkgCache::Package **K = PList.get(); K != PEnd; K++)
       {
 	 pkgCache::PkgIterator I(Cache,*K);
 
@@ -853,8 +843,8 @@ 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 can't be found */
-	    SPtrArray<pkgCache::Version *> VList = Start.AllTargets();
-	    if (*VList == 0 && (Flags[I->ID] & Protected) != Protected &&
+	    std::unique_ptr<pkgCache::Version *[]> VList(Start.AllTargets());
+	    if (VList[0] == 0 && (Flags[I->ID] & Protected) != Protected &&
 		Start.IsNegative() == false &&
 		Cache[I].NowBroken() == false)
 	    {	       
@@ -871,7 +861,7 @@ bool pkgProblemResolver::ResolveInternal(bool const BrokenFix)
 	    }
 	    
 	    bool Done = false;
-	    for (pkgCache::Version **V = VList; *V != 0; V++)
+	    for (pkgCache::Version **V = VList.get(); *V != 0; V++)
 	    {
 	       pkgCache::VerIterator Ver(Cache,*V);
 	       pkgCache::PkgIterator Pkg = Ver.ParentPkg();
@@ -1144,12 +1134,6 @@ bool pkgProblemResolver::InstOrNewPolicyBroken(pkgCache::PkgIterator I)
 /* This is the work horse of the soft upgrade routine. It is very gental 
    in that it does not install or remove any packages. It is assumed that the
    system was non-broken previously. */
-#if APT_PKG_ABI < 413
-bool pkgProblemResolver::ResolveByKeep()
-{
-   return ResolveByKeep(NULL);
-}
-#endif
 bool pkgProblemResolver::ResolveByKeep(OpProgress * const Progress)
 {
    std::string const solver = _config->Find("APT::Solver", "internal");
@@ -1247,8 +1231,8 @@ bool pkgProblemResolver::ResolveByKeepInternal()
 	       clog << "Package " << I.FullName(false) << " " << Start << endl;
 
 	    // Look at all the possible provides on this package
-	    SPtrArray<pkgCache::Version *> VList = Start.AllTargets();
-	    for (pkgCache::Version **V = VList; *V != 0; V++)
+	    std::unique_ptr<pkgCache::Version *[]> VList(Start.AllTargets());
+	    for (pkgCache::Version **V = VList.get(); *V != 0; V++)
 	    {
 	       pkgCache::VerIterator Ver(Cache,*V);
 	       pkgCache::PkgIterator Pkg = Ver.ParentPkg();

+ 11 - 21
apt-pkg/algorithms.h

@@ -1,6 +1,5 @@
 // -*- mode: cpp; mode: fold -*-
 // Description								/*{{{*/
-// $Id: algorithms.h,v 1.10 2001/05/22 04:17:41 jgg Exp $
 /* ######################################################################
 
    Algorithms - A set of misc algorithms
@@ -55,6 +54,7 @@ using std::ostream;
 
 class pkgSimulate : public pkgPackageManager				/*{{{*/
 {
+   void * const d;
    protected:
 
    class Policy : public pkgDepCache::Policy
@@ -62,12 +62,12 @@ class pkgSimulate : public pkgPackageManager				/*{{{*/
       pkgDepCache *Cache;
       public:
       
-      virtual VerIterator GetCandidateVer(PkgIterator const &Pkg)
+      virtual VerIterator GetCandidateVer(PkgIterator const &Pkg) APT_OVERRIDE
       {
 	 return (*Cache)[Pkg].CandidateVerIter(*Cache);
       }
       
-      Policy(pkgDepCache *Cache) : Cache(Cache) {};
+      explicit Policy(pkgDepCache *Cache) : Cache(Cache) {};
    };
    
    unsigned char *Flags;
@@ -77,9 +77,9 @@ class pkgSimulate : public pkgPackageManager				/*{{{*/
    pkgDepCache::ActionGroup group;
    
    // The Actuall installation implementation
-   virtual bool Install(PkgIterator Pkg,std::string File);
-   virtual bool Configure(PkgIterator Pkg);
-   virtual bool Remove(PkgIterator Pkg,bool Purge);
+   virtual bool Install(PkgIterator Pkg,std::string File) APT_OVERRIDE;
+   virtual bool Configure(PkgIterator Pkg) APT_OVERRIDE;
+   virtual bool Remove(PkgIterator Pkg,bool Purge) APT_OVERRIDE;
 
 private:
    APT_HIDDEN void ShortBreaks();
@@ -87,15 +87,15 @@ private:
 
    public:
 
-   pkgSimulate(pkgDepCache *Cache);
-   ~pkgSimulate();
+   explicit pkgSimulate(pkgDepCache *Cache);
+   virtual ~pkgSimulate();
 };
 									/*}}}*/
 class pkgProblemResolver						/*{{{*/
 {
  private:
    /** \brief dpointer placeholder (for later in case we need it) */
-   void *d;
+   void * const d;
 
    pkgDepCache &Cache;
    typedef pkgCache::PkgIterator PkgIterator;
@@ -138,25 +138,15 @@ class pkgProblemResolver						/*{{{*/
    inline void Clear(pkgCache::PkgIterator Pkg) {Flags[Pkg->ID] &= ~(Protected | ToRemove);};
 
    // Try to intelligently resolve problems by installing and removing packages
-#if APT_PKG_ABI >= 413
    bool Resolve(bool BrokenFix = false, OpProgress * const Progress = NULL);
-#else
-   bool Resolve(bool BrokenFix = false);
-   bool Resolve(bool BrokenFix, OpProgress * const Progress);
-#endif
 
    // Try to resolve problems only by using keep
-#if APT_PKG_ABI >= 413
    bool ResolveByKeep(OpProgress * const Progress = NULL);
-#else
-   bool ResolveByKeep();
-   bool ResolveByKeep(OpProgress * const Progress);
-#endif
 
    APT_DEPRECATED void InstallProtect();
 
-   pkgProblemResolver(pkgDepCache *Cache);
-   ~pkgProblemResolver();
+   explicit pkgProblemResolver(pkgDepCache *Cache);
+   virtual ~pkgProblemResolver();
 };
 									/*}}}*/
 bool pkgApplyStatus(pkgDepCache &Cache);

+ 1 - 2
apt-pkg/aptconfiguration.cc

@@ -29,7 +29,6 @@
 #include <string>
 #include <vector>
 
-#include <apti18n.h>
 									/*}}}*/
 namespace APT {
 // setDefaultConfigurationForCompressors				/*{{{*/
@@ -222,7 +221,7 @@ std::vector<std::string> const Configuration::getLanguages(bool const &All,
 	// get the environment language codes: LC_MESSAGES (and later LANGUAGE)
 	// we extract both, a long and a short code and then we will
 	// check if we actually need both (rare) or if the short is enough
-	string const envMsg = string(Locale == 0 ? std::setlocale(LC_MESSAGES, NULL) : *Locale);
+	string const envMsg = string(Locale == 0 ? ::setlocale(LC_MESSAGES, NULL) : *Locale);
 	size_t const lenShort = (envMsg.find('_') != string::npos) ? envMsg.find('_') : 2;
 	size_t const lenLong = (envMsg.find_first_of(".@") != string::npos) ? envMsg.find_first_of(".@") : (lenShort + 3);
 

+ 11 - 12
apt-pkg/aptconfiguration.h

@@ -16,8 +16,7 @@
 #include <limits>
 									/*}}}*/
 namespace APT {
-class Configuration {							/*{{{*/
-public:									/*{{{*/
+namespace Configuration {							/*{{{*/
 	/** \brief Returns a vector of usable Compression Types
 	 *
 	 *  Files can be compressed in various ways to decrease the size of the
@@ -39,7 +38,7 @@ public:									/*{{{*/
 	 *
 	 *  \return a vector of the compression types in the preferred usage order
 	 */
-	std::vector<std::string> static const getCompressionTypes(bool const &Cached = true);
+	std::vector<std::string> const getCompressionTypes(bool const &Cached = true);
 
 	/** \brief Returns a vector of Language Codes
 	 *
@@ -64,7 +63,7 @@ public:									/*{{{*/
 	 *
 	 *  \return a vector of (all) Language Codes in the preferred usage order
 	 */
-	std::vector<std::string> static const getLanguages(bool const &All = false,
+	std::vector<std::string> const getLanguages(bool const &All = false,
 			bool const &Cached = true, char const ** const Locale = 0);
 
 	/** \brief Are we interested in the given Language?
@@ -73,7 +72,7 @@ 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 checkLanguage(std::string Lang, bool const All = false);
+	bool checkLanguage(std::string Lang, bool const All = false);
 
 	/** \brief Returns a vector of Architectures we support
 	 *
@@ -82,14 +81,14 @@ public:									/*{{{*/
 	 *
 	 *  \return a vector of Architectures in preferred order
 	 */
-	std::vector<std::string> static const getArchitectures(bool const &Cached = true);
+	std::vector<std::string> const getArchitectures(bool const &Cached = true);
 
 	/** \brief Are we interested in the given Architecture?
 	 *
 	 *  \param Arch we want to check
 	 *  \return true if we are interested, false otherwise
 	 */
-	bool static checkArchitecture(std::string const &Arch);
+	bool checkArchitecture(std::string const &Arch);
 
 	/** \brief Representation of supported compressors */
 	struct Compressor {
@@ -113,17 +112,17 @@ public:									/*{{{*/
 	 *
 	 *  \return a vector of Compressors
 	 */
-	std::vector<Compressor> static const getCompressors(bool const Cached = true);
+	std::vector<Compressor> const getCompressors(bool const Cached = true);
 
 	/** \brief Return a vector of extensions supported for data.tar's */
-	std::vector<std::string> static const getCompressorExtensions();
+	std::vector<std::string> const getCompressorExtensions();
 
 	/** \return Return a vector of enabled build profile specifications */
-	std::vector<std::string> static const getBuildProfiles();
+	std::vector<std::string> const getBuildProfiles();
 	/** \return Return a comma-separated list of enabled build profile specifications */
-	std::string static const getBuildProfilesString();
+	std::string const getBuildProfilesString();
 									/*}}}*/
-};
+}
 									/*}}}*/
 }
 #endif

+ 26 - 15
apt-pkg/cachefile.cc

@@ -35,10 +35,13 @@
 #include <apti18n.h>
 									/*}}}*/
 // CacheFile::CacheFile - Constructor					/*{{{*/
-// ---------------------------------------------------------------------
-/* */
-pkgCacheFile::pkgCacheFile() : d(NULL), Map(NULL), Cache(NULL), DCache(NULL),
-				SrcList(NULL), Policy(NULL)
+pkgCacheFile::pkgCacheFile() : d(NULL), ExternOwner(false), Map(NULL), Cache(NULL),
+				DCache(NULL), SrcList(NULL), Policy(NULL)
+{
+}
+pkgCacheFile::pkgCacheFile(pkgDepCache * const Owner) : d(NULL), ExternOwner(true),
+   Map(&Owner->GetCache().GetMap()), Cache(&Owner->GetCache()),
+   DCache(Owner), SrcList(NULL), Policy(NULL)
 {
 }
 									/*}}}*/
@@ -47,12 +50,16 @@ pkgCacheFile::pkgCacheFile() : d(NULL), Map(NULL), Cache(NULL), DCache(NULL),
 /* */
 pkgCacheFile::~pkgCacheFile()
 {
-   delete DCache;
+   if (ExternOwner == false)
+   {
+      delete DCache;
+      delete Cache;
+      delete Map;
+   }
    delete Policy;
    delete SrcList;
-   delete Cache;
-   delete Map;
-   _system->UnLock(true);
+   if (ExternOwner == false)
+      _system->UnLock(true);
 }
 									/*}}}*/
 // CacheFile::BuildCaches - Open and build the cache files		/*{{{*/
@@ -65,8 +72,8 @@ bool pkgCacheFile::BuildCaches(OpProgress *Progress, bool WithLock)
 
    if (_config->FindB("pkgCacheFile::Generate", true) == false)
    {
-      Map = new MMap(*new FileFd(_config->FindFile("Dir::Cache::pkgcache"),
-		     FileFd::ReadOnly),MMap::Public|MMap::ReadOnly);
+      FileFd file(_config->FindFile("Dir::Cache::pkgcache"), FileFd::ReadOnly);
+      Map = new MMap(file, MMap::Public|MMap::ReadOnly);
       Cache = new pkgCache(Map);
       if (_error->PendingError() == true)
          return false;
@@ -150,8 +157,7 @@ bool pkgCacheFile::BuildDepCache(OpProgress *Progress)
    if (_error->PendingError() == true)
       return false;
 
-   DCache->Init(Progress);
-   return true;
+   return DCache->Init(Progress);
 }
 									/*}}}*/
 // CacheFile::Open - Open the cache files, creating if necessary	/*{{{*/
@@ -229,11 +235,16 @@ void pkgCacheFile::RemoveCaches()
 /* */
 void pkgCacheFile::Close()
 {
-   delete DCache;
+   if (ExternOwner == false)
+   {
+      delete DCache;
+      delete Cache;
+      delete Map;
+   }
+   else
+      ExternOwner = false;
    delete Policy;
-   delete Cache;
    delete SrcList;
-   delete Map;
    _system->UnLock(true);
 
    Map = NULL;

+ 15 - 15
apt-pkg/cachefile.h

@@ -1,6 +1,5 @@
 // -*- mode: cpp; mode: fold -*-
 // Description								/*{{{*/
-// $Id: cachefile.h,v 1.5 2002/04/27 04:28:04 jgg Exp $
 /* ######################################################################
    
    CacheFile - Simple wrapper class for opening, generating and whatnot
@@ -38,10 +37,10 @@ class OpProgress;
 class pkgCacheFile
 {
    /** \brief dpointer placeholder (for later in case we need it) */
-   void *d;
+   void * const d;
+   bool ExternOwner;
 
    protected:
-   
    MMap *Map;
    pkgCache *Cache;
    pkgDepCache *DCache;
@@ -51,18 +50,18 @@ class pkgCacheFile
    pkgPolicy *Policy;
 
    // We look pretty much exactly like a pointer to a dep cache
-   inline operator pkgCache &() {return *Cache;};
-   inline operator pkgCache *() {return Cache;};
-   inline operator pkgDepCache &() {return *DCache;};
-   inline operator pkgDepCache *() {return DCache;};
-   inline operator pkgPolicy &() {return *Policy;};
-   inline operator pkgPolicy *() {return Policy;};
-   inline operator pkgSourceList &() {return *SrcList;};
-   inline operator pkgSourceList *() {return SrcList;};
-   inline pkgDepCache *operator ->() {return DCache;};
-   inline pkgDepCache &operator *() {return *DCache;};
-   inline pkgDepCache::StateCache &operator [](pkgCache::PkgIterator const &I) {return (*DCache)[I];};
-   inline unsigned char &operator [](pkgCache::DepIterator const &I) {return (*DCache)[I];};
+   inline operator pkgCache &() const {return *Cache;};
+   inline operator pkgCache *() const {return Cache;};
+   inline operator pkgDepCache &() const {return *DCache;};
+   inline operator pkgDepCache *() const {return DCache;};
+   inline operator pkgPolicy &() const {return *Policy;};
+   inline operator pkgPolicy *() const {return Policy;};
+   inline operator pkgSourceList &() const {return *SrcList;};
+   inline operator pkgSourceList *() const {return SrcList;};
+   inline pkgDepCache *operator ->() const {return DCache;};
+   inline pkgDepCache &operator *() const {return *DCache;};
+   inline pkgDepCache::StateCache &operator [](pkgCache::PkgIterator const &I) const {return (*DCache)[I];};
+   inline unsigned char &operator [](pkgCache::DepIterator const &I) const {return (*DCache)[I];};
 
    bool BuildCaches(OpProgress *Progress = NULL,bool WithLock = true);
    APT_DEPRECATED bool BuildCaches(OpProgress &Progress,bool const &WithLock = true) { return BuildCaches(&Progress, WithLock); };
@@ -86,6 +85,7 @@ class pkgCacheFile
    inline bool IsSrcListBuilt() const { return (SrcList != NULL); };
 
    pkgCacheFile();
+   explicit pkgCacheFile(pkgDepCache * const Owner);
    virtual ~pkgCacheFile();
 };
 

+ 30 - 30
apt-pkg/cachefilter.h

@@ -29,34 +29,34 @@ public:
 
 class PackageMatcher : public Matcher {
 public:
-   virtual bool operator() (pkgCache::PkgIterator const &Pkg) = 0;
-   virtual bool operator() (pkgCache::VerIterator const &Ver) { return (*this)(Ver.ParentPkg()); }
-   virtual bool operator() (pkgCache::GrpIterator const &/*Grp*/) { return false; }
+   virtual bool operator() (pkgCache::PkgIterator const &Pkg) APT_OVERRIDE = 0;
+   virtual bool operator() (pkgCache::VerIterator const &Ver) APT_OVERRIDE { return (*this)(Ver.ParentPkg()); }
+   virtual bool operator() (pkgCache::GrpIterator const &/*Grp*/) APT_OVERRIDE { return false; }
    virtual ~PackageMatcher();
 };
 
 // Generica like True, False, NOT, AND, OR				/*{{{*/
 class TrueMatcher : public Matcher {
 public:
-   virtual bool operator() (pkgCache::PkgIterator const &Pkg);
-   virtual bool operator() (pkgCache::GrpIterator const &Grp);
-   virtual bool operator() (pkgCache::VerIterator const &Ver);
+   virtual bool operator() (pkgCache::PkgIterator const &Pkg) APT_OVERRIDE;
+   virtual bool operator() (pkgCache::GrpIterator const &Grp) APT_OVERRIDE;
+   virtual bool operator() (pkgCache::VerIterator const &Ver) APT_OVERRIDE;
 };
 
 class FalseMatcher : public Matcher {
 public:
-   virtual bool operator() (pkgCache::PkgIterator const &Pkg);
-   virtual bool operator() (pkgCache::GrpIterator const &Grp);
-   virtual bool operator() (pkgCache::VerIterator const &Ver);
+   virtual bool operator() (pkgCache::PkgIterator const &Pkg) APT_OVERRIDE;
+   virtual bool operator() (pkgCache::GrpIterator const &Grp) APT_OVERRIDE;
+   virtual bool operator() (pkgCache::VerIterator const &Ver) APT_OVERRIDE;
 };
 
 class NOTMatcher : public Matcher {
    Matcher * const matcher;
 public:
-   NOTMatcher(Matcher * const matcher);
-   virtual bool operator() (pkgCache::PkgIterator const &Pkg);
-   virtual bool operator() (pkgCache::GrpIterator const &Grp);
-   virtual bool operator() (pkgCache::VerIterator const &Ver);
+   explicit NOTMatcher(Matcher * const matcher);
+   virtual bool operator() (pkgCache::PkgIterator const &Pkg) APT_OVERRIDE;
+   virtual bool operator() (pkgCache::GrpIterator const &Grp) APT_OVERRIDE;
+   virtual bool operator() (pkgCache::VerIterator const &Ver) APT_OVERRIDE;
    virtual ~NOTMatcher();
 };
 
@@ -65,15 +65,15 @@ class ANDMatcher : public Matcher {
 public:
    // 5 ought to be enough for everybody… c++11 variadic templates would be nice
    ANDMatcher();
-   ANDMatcher(Matcher * const matcher1);
+   explicit ANDMatcher(Matcher * const matcher1);
    ANDMatcher(Matcher * const matcher1, Matcher * const matcher2);
    ANDMatcher(Matcher * const matcher1, Matcher * const matcher2, Matcher * const matcher3);
    ANDMatcher(Matcher * const matcher1, Matcher * const matcher2, Matcher * const matcher3, Matcher * const matcher4);
    ANDMatcher(Matcher * const matcher1, Matcher * const matcher2, Matcher * const matcher3, Matcher * const matcher4, Matcher * const matcher5);
    ANDMatcher& AND(Matcher * const matcher);
-   virtual bool operator() (pkgCache::PkgIterator const &Pkg);
-   virtual bool operator() (pkgCache::GrpIterator const &Grp);
-   virtual bool operator() (pkgCache::VerIterator const &Ver);
+   virtual bool operator() (pkgCache::PkgIterator const &Pkg) APT_OVERRIDE;
+   virtual bool operator() (pkgCache::GrpIterator const &Grp) APT_OVERRIDE;
+   virtual bool operator() (pkgCache::VerIterator const &Ver) APT_OVERRIDE;
    virtual ~ANDMatcher();
 };
 class ORMatcher : public Matcher {
@@ -81,33 +81,33 @@ class ORMatcher : public Matcher {
 public:
    // 5 ought to be enough for everybody… c++11 variadic templates would be nice
    ORMatcher();
-   ORMatcher(Matcher * const matcher1);
+   explicit ORMatcher(Matcher * const matcher1);
    ORMatcher(Matcher * const matcher1, Matcher * const matcher2);
    ORMatcher(Matcher * const matcher1, Matcher * const matcher2, Matcher * const matcher3);
    ORMatcher(Matcher * const matcher1, Matcher * const matcher2, Matcher * const matcher3, Matcher * const matcher4);
    ORMatcher(Matcher * const matcher1, Matcher * const matcher2, Matcher * const matcher3, Matcher * const matcher4, Matcher * const matcher5);
    ORMatcher& OR(Matcher * const matcher);
-   virtual bool operator() (pkgCache::PkgIterator const &Pkg);
-   virtual bool operator() (pkgCache::GrpIterator const &Grp);
-   virtual bool operator() (pkgCache::VerIterator const &Ver);
+   virtual bool operator() (pkgCache::PkgIterator const &Pkg) APT_OVERRIDE;
+   virtual bool operator() (pkgCache::GrpIterator const &Grp) APT_OVERRIDE;
+   virtual bool operator() (pkgCache::VerIterator const &Ver) APT_OVERRIDE;
    virtual ~ORMatcher();
 };
 									/*}}}*/
 class PackageNameMatchesRegEx : public PackageMatcher {			/*{{{*/
 	regex_t* pattern;
 public:
-	PackageNameMatchesRegEx(std::string const &Pattern);
-	virtual bool operator() (pkgCache::PkgIterator const &Pkg);
-	virtual bool operator() (pkgCache::GrpIterator const &Grp);
+	explicit PackageNameMatchesRegEx(std::string const &Pattern);
+	virtual bool operator() (pkgCache::PkgIterator const &Pkg) APT_OVERRIDE;
+	virtual bool operator() (pkgCache::GrpIterator const &Grp) APT_OVERRIDE;
 	virtual ~PackageNameMatchesRegEx();
 };
 									/*}}}*/
 class PackageNameMatchesFnmatch : public PackageMatcher {		/*{{{*/
 	const std::string Pattern;
 public:
-	PackageNameMatchesFnmatch(std::string const &Pattern);
-	virtual bool operator() (pkgCache::PkgIterator const &Pkg);
-	virtual bool operator() (pkgCache::GrpIterator const &Grp);
+	explicit PackageNameMatchesFnmatch(std::string const &Pattern);
+	virtual bool operator() (pkgCache::PkgIterator const &Pkg) APT_OVERRIDE;
+	virtual bool operator() (pkgCache::GrpIterator const &Grp) APT_OVERRIDE;
 	virtual ~PackageNameMatchesFnmatch() {};
 };
 									/*}}}*/
@@ -133,15 +133,15 @@ public:
 	 */
 	PackageArchitectureMatchesSpecification(std::string const &pattern, bool const isPattern = true);
 	bool operator() (char const * const &arch);
-	virtual bool operator() (pkgCache::PkgIterator const &Pkg);
+	virtual bool operator() (pkgCache::PkgIterator const &Pkg) APT_OVERRIDE;
 	virtual ~PackageArchitectureMatchesSpecification();
 };
 									/*}}}*/
 class PackageIsNewInstall : public PackageMatcher {			/*{{{*/
 	pkgCacheFile * const Cache;
 public:
-	PackageIsNewInstall(pkgCacheFile * const Cache);
-	virtual bool operator() (pkgCache::PkgIterator const &Pkg);
+	explicit PackageIsNewInstall(pkgCacheFile * const Cache);
+	virtual bool operator() (pkgCache::PkgIterator const &Pkg) APT_OVERRIDE;
 	virtual ~PackageIsNewInstall();
 };
 									/*}}}*/

+ 129 - 72
apt-pkg/cacheiterators.h

@@ -43,10 +43,6 @@
    need to have for doing some walk-over-the-cache magic */
 template<typename Str, typename Itr> class pkgCache::Iterator :
 			public std::iterator<std::forward_iterator_tag, Str> {
-	protected:
-	Str *S;
-	pkgCache *Owner;
-
 	/** \brief Returns the Pointer for this struct in the owner
 	 *  The implementation of this method should be pretty short
 	 *  as it will only return the Pointer into the mmap stored
@@ -55,12 +51,14 @@ template<typename Str, typename Itr> class pkgCache::Iterator :
 	 *  basic methods from the actual structure.
 	 *  \return Pointer to the first structure of this type
 	 */
-	virtual Str* OwnerPointer() const = 0;
+	Str* OwnerPointer() const { return static_cast<Itr const*>(this)->OwnerPointer(); }
+
+	protected:
+	Str *S;
+	pkgCache *Owner;
 
 	public:
 	// Iteration
-	virtual void operator ++(int) = 0;
-	virtual void operator ++() = 0; // Should be {operator ++(0);}
 	inline bool end() const {return Owner == 0 || S == OwnerPointer();}
 
 	// Comparison
@@ -77,7 +75,6 @@ template<typename Str, typename Itr> class pkgCache::Iterator :
 	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();}
 
@@ -100,20 +97,19 @@ template<typename Str, typename Itr> class pkgCache::Iterator :
 class pkgCache::GrpIterator: public Iterator<Group, GrpIterator> {
 	long HashIndex;
 
-	protected:
+	public:
 	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) {
+	explicit inline GrpIterator(pkgCache &Owner) : Iterator<Group, GrpIterator>(Owner), HashIndex(-1) {
 		S = OwnerPointer();
-		operator ++(0);
+		operator++();
 	}
 
-	virtual void operator ++(int);
-	virtual void operator ++() {operator ++(0);}
+	GrpIterator& operator++();
+	inline GrpIterator operator++(int) { GrpIterator const tmp(*this); operator++(); return tmp; }
 
 	inline const char *Name() const {return S->Name == 0?0:Owner->StrP + S->Name;}
 	inline PkgIterator PackageList() const;
@@ -141,20 +137,19 @@ class pkgCache::GrpIterator: public Iterator<Group, GrpIterator> {
 class pkgCache::PkgIterator: public Iterator<Package, PkgIterator> {
 	long HashIndex;
 
-	protected:
+	public:
 	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) {
+	explicit inline PkgIterator(pkgCache &Owner) : Iterator<Package, PkgIterator>(Owner), HashIndex(-1) {
 		S = OwnerPointer();
-		operator ++(0);
+		operator++();
 	}
 
-	virtual void operator ++(int);
-	virtual void operator ++() {operator ++(0);}
+	PkgIterator& operator++();
+	inline PkgIterator operator++(int) { PkgIterator const tmp(*this); operator++(); return tmp; }
 
 	enum OkState {NeedsNothing,NeedsUnpack,NeedsConfigure};
 
@@ -162,11 +157,7 @@ class pkgCache::PkgIterator: public Iterator<Package, PkgIterator> {
 	inline const char *Name() const { return Group().Name(); }
 	// Versions have sections - and packages can have different versions with different sections
 	// so this interface is broken by design. Run as fast as you can to Version.Section().
-	APT_DEPRECATED inline const char *Section() const {
-	   APT_IGNORE_DEPRECATED_PUSH
-	   return S->Section == 0?0:Owner->StrP + S->Section;
-	   APT_IGNORE_DEPRECATED_POP
-	}
+	APT_DEPRECATED inline const char *Section() const;
 	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;}
@@ -194,15 +185,14 @@ class pkgCache::PkgIterator: public Iterator<Package, PkgIterator> {
 									/*}}}*/
 // Version Iterator							/*{{{*/
 class pkgCache::VerIterator : public Iterator<Version, VerIterator> {
-	protected:
+	public:
 	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);}
+	inline VerIterator& operator++() {if (S != Owner->VerP) S = Owner->VerP + S->NextVer; return *this;}
+	inline VerIterator operator++(int) { VerIterator const tmp(*this); operator++(); return tmp; }
 
 	// Comparison
 	int CompareVer(const VerIterator &B) const;
@@ -217,14 +207,12 @@ class pkgCache::VerIterator : public Iterator<Version, VerIterator> {
 	// 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;}
-#if APT_PKG_ABI >= 413
 	/** \brief source package name this version comes from
 	   Always contains the name, even if it is the same as the binary name */
 	inline const char *SourcePkgName() const {return Owner->StrP + S->SourcePkgName;}
 	/** \brief source version this version comes from
 	   Always contains the version string, even if it is the same as the binary version */
 	inline const char *SourceVerStr() const {return Owner->StrP + S->SourceVerStr;}
-#endif
 	inline const char *Arch() const {
 		if ((S->MultiArch & pkgCache::Version::All) == pkgCache::Version::All)
 			return "all";
@@ -254,15 +242,14 @@ class pkgCache::VerIterator : public Iterator<Version, VerIterator> {
 									/*}}}*/
 // Description Iterator							/*{{{*/
 class pkgCache::DescIterator : public Iterator<Description, DescIterator> {
-	protected:
+	public:
 	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);}
+	inline DescIterator& operator++() {if (S != Owner->DescP) S = Owner->DescP + S->NextDesc; return *this;}
+	inline DescIterator operator++(int) { DescIterator const tmp(*this); operator++(); return tmp; }
 
 	// Comparison
 	int CompareDesc(const DescIterator &B) const;
@@ -282,21 +269,20 @@ class pkgCache::DescIterator : public Iterator<Description, DescIterator> {
 // Dependency iterator							/*{{{*/
 class pkgCache::DepIterator : public Iterator<Dependency, DepIterator> {
 	enum {DepVer, DepRev} Type;
+	DependencyData * S2;
 
-	protected:
+	public:
 	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);}
+	DepIterator& operator++();
+	inline DepIterator operator++(int) { DepIterator const tmp(*this); operator++(); return tmp; }
 
 	// 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 const char *TargetVer() const {return S2->Version == 0?0:Owner->StrP + S2->Version;}
+	inline PkgIterator TargetPkg() const {return PkgIterator(*Owner,Owner->PkgP + S2->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);}
@@ -305,45 +291,79 @@ class pkgCache::DepIterator : public Iterator<Dependency, DepIterator> {
 	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;
+	/* MultiArch can be translated to SingleArch for an resolver and we did so,
+	   by adding dependencies to help the resolver understand the problem, but
+	   sometimes it is needed to identify these to ignore them… */
+	inline bool IsMultiArchImplicit() const APT_PURE {
+		return (S2->CompareOp & pkgCache::Dep::MultiArchImplicit) == pkgCache::Dep::MultiArchImplicit;
+	}
+	/* This covers additionally negative dependencies, which aren't arch-specific,
+	   but change architecture nontheless as a Conflicts: foo does applies for all archs */
+	bool IsImplicit() 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(S2->CompareOp);}
+	inline const char *DepType() const {return Owner->DepType(S2->Type);}
+
+	// overrides because we are special
+	struct DependencyProxy
+	{
+	   map_stringitem_t &Version;
+	   map_pointer_t &Package;
+	   map_id_t &ID;
+	   unsigned char &Type;
+	   unsigned char &CompareOp;
+	   map_pointer_t &ParentVer;
+	   map_pointer_t &DependencyData;
+	   map_pointer_t &NextRevDepends;
+	   map_pointer_t &NextDepends;
+	   map_pointer_t &NextData;
+	   DependencyProxy const * operator->() const { return this; }
+	   DependencyProxy * operator->() { return this; }
+	};
+	inline DependencyProxy operator->() const {return (DependencyProxy) { S2->Version, S2->Package, S->ID, S2->Type, S2->CompareOp, S->ParentVer, S->DependencyData, S->NextRevDepends, S->NextDepends, S2->NextData };}
+	inline DependencyProxy operator->() {return (DependencyProxy) { S2->Version, S2->Package, S->ID, S2->Type, S2->CompareOp, S->ParentVer, S->DependencyData, S->NextRevDepends, S->NextDepends, S2->NextData };}
+	void ReMap(void const * const oldMap, void const * const newMap)
+	{
+		Iterator<Dependency, DepIterator>::ReMap(oldMap, newMap);
+		if (Owner == 0 || S == 0 || S2 == 0)
+			return;
+		S2 += (DependencyData const * const)(newMap) - (DependencyData const * const)(oldMap);
+	}
 
 	//Nice printable representation
 	friend std::ostream& operator <<(std::ostream& out, DepIterator D);
 
 	inline DepIterator(pkgCache &Owner, Dependency *Trg, Version* = 0) :
-		Iterator<Dependency, DepIterator>(Owner, Trg), Type(DepVer) {
+		Iterator<Dependency, DepIterator>(Owner, Trg), Type(DepVer), S2(Trg == 0 ? Owner.DepDataP : (Owner.DepDataP + Trg->DependencyData)) {
 		if (S == 0)
 			S = Owner.DepP;
 	}
 	inline DepIterator(pkgCache &Owner, Dependency *Trg, Package*) :
-		Iterator<Dependency, DepIterator>(Owner, Trg), Type(DepRev) {
+		Iterator<Dependency, DepIterator>(Owner, Trg), Type(DepRev), S2(Trg == 0 ? Owner.DepDataP : (Owner.DepDataP + Trg->DependencyData)) {
 		if (S == 0)
 			S = Owner.DepP;
 	}
-	inline DepIterator() : Iterator<Dependency, DepIterator>(), Type(DepVer) {}
+	inline DepIterator() : Iterator<Dependency, DepIterator>(), Type(DepVer), S2(0) {}
 };
 									/*}}}*/
 // Provides iterator							/*{{{*/
 class pkgCache::PrvIterator : public Iterator<Provides, PrvIterator> {
 	enum {PrvVer, PrvPkg} Type;
 
-	protected:
+	public:
 	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);}
+	inline PrvIterator& operator ++() {if (S != Owner->ProvideP) S = Owner->ProvideP +
+	   (Type == PrvVer?S->NextPkgProv:S->NextProvides); return *this;}
+	inline PrvIterator operator++(int) { PrvIterator const tmp(*this); operator++(); return tmp; }
 
 	// Accessors
 	inline const char *Name() const {return ParentPkg().Name();}
@@ -352,7 +372,12 @@ class pkgCache::PrvIterator : public Iterator<Provides, PrvIterator> {
 	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 APT_PURE;
+	/* MultiArch can be translated to SingleArch for an resolver and we did so,
+	   by adding provides to help the resolver understand the problem, but
+	   sometimes it is needed to identify these to ignore them… */
+	bool IsMultiArchImplicit() const APT_PURE
+	{ return (S->Flags & pkgCache::Flag::MultiArchImplicit) == pkgCache::Flag::MultiArchImplicit; }
+
 
 	inline PrvIterator() : Iterator<Provides, PrvIterator>(), Type(PrvVer) {}
 	inline PrvIterator(pkgCache &Owner, Provides *Trg, Version*) :
@@ -367,27 +392,59 @@ class pkgCache::PrvIterator : public Iterator<Provides, PrvIterator> {
 	}
 };
 									/*}}}*/
-// Package file								/*{{{*/
-class pkgCache::PkgFileIterator : public Iterator<PackageFile, PkgFileIterator> {
-	protected:
-	inline PackageFile* OwnerPointer() const {
-		return (Owner != 0) ? Owner->PkgFileP : 0;
+// Release file								/*{{{*/
+class pkgCache::RlsFileIterator : public Iterator<ReleaseFile, RlsFileIterator> {
+	public:
+	inline ReleaseFile* OwnerPointer() const {
+		return (Owner != 0) ? Owner->RlsFileP : 0;
 	}
 
-	public:
 	// Iteration
-	void operator ++(int) {if (S != Owner->PkgFileP) S = Owner->PkgFileP + S->NextFile;}
-	inline void operator ++() {operator ++(0);}
+	inline RlsFileIterator& operator++() {if (S != Owner->RlsFileP) S = Owner->RlsFileP + S->NextFile;return *this;}
+	inline RlsFileIterator operator++(int) { RlsFileIterator const tmp(*this); operator++(); return tmp; }
 
 	// 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 bool Flagged(pkgCache::Flag::ReleaseFileFlags const flag) const {return (S->Flags & flag) == flag; }
+
+	bool IsOk();
+	std::string RelStr();
+
+	// Constructors
+	inline RlsFileIterator() : Iterator<ReleaseFile, RlsFileIterator>() {}
+	explicit inline RlsFileIterator(pkgCache &Owner) : Iterator<ReleaseFile, RlsFileIterator>(Owner, Owner.RlsFileP) {}
+	inline RlsFileIterator(pkgCache &Owner,ReleaseFile *Trg) : Iterator<ReleaseFile, RlsFileIterator>(Owner, Trg) {}
+};
+									/*}}}*/
+// Package file								/*{{{*/
+class pkgCache::PkgFileIterator : public Iterator<PackageFile, PkgFileIterator> {
+	public:
+	inline PackageFile* OwnerPointer() const {
+		return (Owner != 0) ? Owner->PkgFileP : 0;
+	}
+
+	// Iteration
+	inline PkgFileIterator& operator++() {if (S != Owner->PkgFileP) S = Owner->PkgFileP + S->NextFile; return *this;}
+	inline PkgFileIterator operator++(int) { PkgFileIterator const tmp(*this); operator++(); return tmp; }
+
+	// Accessors
+	inline const char *FileName() const {return S->FileName == 0?0:Owner->StrP + S->FileName;}
+	inline pkgCache::RlsFileIterator ReleaseFile() const {return RlsFileIterator(*Owner, Owner->RlsFileP + S->Release);}
+	inline const char *Archive() const {return S->Release == 0 ? Component() : ReleaseFile().Archive();}
+	inline const char *Version() const {return S->Release == 0 ? NULL : ReleaseFile().Version();}
+	inline const char *Origin() const {return S->Release == 0 ? NULL : ReleaseFile().Origin();}
+	inline const char *Codename() const {return S->Release == 0 ? NULL : ReleaseFile().Codename();}
+	inline const char *Label() const {return S->Release == 0 ? NULL : ReleaseFile().Label();}
+	inline const char *Site() const {return S->Release == 0 ? NULL : ReleaseFile().Site();}
+	inline bool Flagged(pkgCache::Flag::ReleaseFileFlags const flag) const {return S->Release== 0 ? false : ReleaseFile().Flagged(flag);}
+	inline bool Flagged(pkgCache::Flag::PkgFFlags const flag) const {return (S->Flags & flag) == flag;}
+	inline const char *Component() const {return S->Component == 0?0:Owner->StrP + S->Component;}
 	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;}
 
@@ -396,21 +453,20 @@ class pkgCache::PkgFileIterator : public Iterator<PackageFile, PkgFileIterator>
 
 	// Constructors
 	inline PkgFileIterator() : Iterator<PackageFile, PkgFileIterator>() {}
-	inline PkgFileIterator(pkgCache &Owner) : Iterator<PackageFile, PkgFileIterator>(Owner, Owner.PkgFileP) {}
+	explicit inline PkgFileIterator(pkgCache &Owner) : Iterator<PackageFile, PkgFileIterator>(Owner, Owner.PkgFileP) {}
 	inline PkgFileIterator(pkgCache &Owner,PackageFile *Trg) : Iterator<PackageFile, PkgFileIterator>(Owner, Trg) {}
 };
 									/*}}}*/
 // Version File								/*{{{*/
 class pkgCache::VerFileIterator : public pkgCache::Iterator<VerFile, VerFileIterator> {
-	protected:
+	public:
 	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);}
+	inline VerFileIterator& operator++() {if (S != Owner->VerFileP) S = Owner->VerFileP + S->NextFile; return *this;}
+	inline VerFileIterator operator++(int) { VerFileIterator const tmp(*this); operator++(); return tmp; }
 
 	// Accessors
 	inline PkgFileIterator File() const {return PkgFileIterator(*Owner,S->File + Owner->PkgFileP);}
@@ -421,15 +477,14 @@ class pkgCache::VerFileIterator : public pkgCache::Iterator<VerFile, VerFileIter
 									/*}}}*/
 // Description File							/*{{{*/
 class pkgCache::DescFileIterator : public Iterator<DescFile, DescFileIterator> {
-	protected:
+	public:
 	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);}
+	inline DescFileIterator& operator++() {if (S != Owner->DescFileP) S = Owner->DescFileP + S->NextFile; return *this;}
+	inline DescFileIterator operator++(int) { DescFileIterator const tmp(*this); operator++(); return tmp; }
 
 	// Accessors
 	inline PkgFileIterator File() const {return PkgFileIterator(*Owner,S->File + Owner->PkgFileP);}
@@ -459,5 +514,7 @@ inline pkgCache::VerFileIterator pkgCache::VerIterator::FileList() const
        {return VerFileIterator(*Owner,Owner->VerFileP + S->FileList);}
 inline pkgCache::DescFileIterator pkgCache::DescIterator::FileList() const
        {return DescFileIterator(*Owner,Owner->DescFileP + S->FileList);}
+APT_DEPRECATED inline const char * pkgCache::PkgIterator::Section() const
+       {return S->VersionList == 0 ? 0 : VersionList().Section();}
 									/*}}}*/
 #endif

+ 134 - 1
apt-pkg/cacheset.cc

@@ -37,7 +37,6 @@
 #include <apti18n.h>
 									/*}}}*/
 namespace APT {
-
 // PackageFrom - selecting the appropriate method for package selection	/*{{{*/
 bool CacheSetHelper::PackageFrom(enum PkgSelector const select, PackageContainerInterface * const pci,
       pkgCacheFile &Cache, std::string const &pattern) {
@@ -583,6 +582,116 @@ bool VersionContainerInterface::FromPackage(VersionContainerInterface * const vc
 	return found;
 }
 									/*}}}*/
+// FromDependency - versions satisfying a given dependency		/*{{{*/
+bool VersionContainerInterface::FromDependency(VersionContainerInterface * const vci,
+					       pkgCacheFile &Cache,
+					       pkgCache::DepIterator const &D,
+					       CacheSetHelper::VerSelector const selector,
+					       CacheSetHelper &helper)
+{
+	bool found = false;
+	switch(selector) {
+	case CacheSetHelper::ALL:
+	{
+		pkgCache::PkgIterator const T = D.TargetPkg();
+		for (pkgCache::VerIterator Ver = T.VersionList(); Ver.end() == false; ++Ver)
+		{
+		   if (D.IsSatisfied(Ver) == true)
+		   {
+		      vci->insert(Ver);
+		      found = true;
+		   }
+		   for (pkgCache::PrvIterator Prv = T.ProvidesList(); Prv.end() != true; ++Prv)
+		   {
+		      pkgCache::VerIterator const V = Prv.OwnerVer();
+		      if (unlikely(V.end() == true) || D.IsSatisfied(Prv) == false)
+			 continue;
+		      vci->insert(V);
+		      found = true;
+		   }
+		}
+		return found;
+	}
+	case CacheSetHelper::CANDANDINST:
+	{
+		found = FromDependency(vci, Cache, D, CacheSetHelper::CANDIDATE, helper);
+		found &= FromDependency(vci, Cache, D, CacheSetHelper::INSTALLED, helper);
+		return found;
+	}
+	case CacheSetHelper::CANDIDATE:
+	{
+		pkgCache::PkgIterator const T = D.TargetPkg();
+		pkgCache::VerIterator const Cand = Cache[T].CandidateVerIter(Cache);
+		if (Cand.end() == false && D.IsSatisfied(Cand) == true)
+		{
+		   vci->insert(Cand);
+		   found = true;
+		}
+		for (pkgCache::PrvIterator Prv = T.ProvidesList(); Prv.end() != true; ++Prv)
+		{
+		   pkgCache::VerIterator const V = Prv.OwnerVer();
+		   pkgCache::VerIterator const Cand = Cache[Prv.OwnerPkg()].CandidateVerIter(Cache);
+		   if (Cand.end() == true || V != Cand || D.IsSatisfied(Prv) == false)
+		      continue;
+		   vci->insert(Cand);
+		   found = true;
+		}
+		return found;
+	}
+	case CacheSetHelper::INSTALLED:
+	{
+		pkgCache::PkgIterator const T = D.TargetPkg();
+		pkgCache::VerIterator const Cand = T.CurrentVer();
+		if (Cand.end() == false && D.IsSatisfied(Cand) == true)
+		{
+		   vci->insert(Cand);
+		   found = true;
+		}
+		for (pkgCache::PrvIterator Prv = T.ProvidesList(); Prv.end() != true; ++Prv)
+		{
+		   pkgCache::VerIterator const V = Prv.OwnerVer();
+		   pkgCache::VerIterator const Cand = Prv.OwnerPkg().CurrentVer();
+		   if (Cand.end() == true || V != Cand || D.IsSatisfied(Prv) == false)
+		      continue;
+		   vci->insert(Cand);
+		   found = true;
+		}
+		return found;
+	}
+	case CacheSetHelper::CANDINST:
+		return FromDependency(vci, Cache, D, CacheSetHelper::CANDIDATE, helper) ||
+		   FromDependency(vci, Cache, D, CacheSetHelper::INSTALLED, helper);
+	case CacheSetHelper::INSTCAND:
+		return FromDependency(vci, Cache, D, CacheSetHelper::INSTALLED, helper) ||
+		   FromDependency(vci, Cache, D, CacheSetHelper::CANDIDATE, helper);
+	case CacheSetHelper::NEWEST:
+	{
+		pkgCache::PkgIterator const T = D.TargetPkg();
+		pkgCache::VerIterator const Cand = T.VersionList();
+		if (Cand.end() == false && D.IsSatisfied(Cand) == true)
+		{
+		   vci->insert(Cand);
+		   found = true;
+		}
+		for (pkgCache::PrvIterator Prv = T.ProvidesList(); Prv.end() != true; ++Prv)
+		{
+		   pkgCache::VerIterator const V = Prv.OwnerVer();
+		   pkgCache::VerIterator const Cand = Prv.OwnerPkg().VersionList();
+		   if (Cand.end() == true || V != Cand || D.IsSatisfied(Prv) == false)
+		      continue;
+		   vci->insert(Cand);
+		   found = true;
+		}
+		return found;
+	}
+	case CacheSetHelper::RELEASE:
+	case CacheSetHelper::VERSIONNUMBER:
+		// both make no sense here, so always false
+		return false;
+	}
+	return found;
+}
+									/*}}}*/
 // getCandidateVer - Returns the candidate version of the given package	/*{{{*/
 pkgCache::VerIterator VersionContainerInterface::getCandidateVer(pkgCacheFile &Cache,
 		pkgCache::PkgIterator const &Pkg, CacheSetHelper &helper) {
@@ -812,4 +921,28 @@ APT_CONST void CacheSetHelper::showSelectedVersion(pkgCache::PkgIterator const &
 					 bool const /*verIsRel*/) {
 }
 									/*}}}*/
+
+CacheSetHelper::CacheSetHelper(bool const ShowError, GlobalError::MsgType ErrorType) :
+   ShowError(ShowError), ErrorType(ErrorType), d(NULL) {}
+CacheSetHelper::~CacheSetHelper() {}
+
+PackageContainerInterface::PackageContainerInterface() : ConstructedBy(CacheSetHelper::UNKNOWN), d(NULL) {}
+PackageContainerInterface::PackageContainerInterface(CacheSetHelper::PkgSelector const by) : ConstructedBy(by), d(NULL) {}
+PackageContainerInterface& PackageContainerInterface::operator=(PackageContainerInterface const &other) {
+   if (this != &other)
+      this->ConstructedBy = other.ConstructedBy;
+   return *this;
+}
+PackageContainerInterface::~PackageContainerInterface() {}
+
+PackageUniverse::PackageUniverse(pkgCache * const Owner) : _cont(Owner), d(NULL) {}
+PackageUniverse::PackageUniverse(pkgCacheFile * const Owner) : _cont(Owner->GetPkgCache()), d(NULL) {}
+PackageUniverse::~PackageUniverse() {}
+
+VersionContainerInterface::VersionContainerInterface() : d(NULL) {}
+VersionContainerInterface& VersionContainerInterface::operator=(VersionContainerInterface const &) {
+   return *this;
+}
+
+VersionContainerInterface::~VersionContainerInterface() {}
 }

+ 364 - 163
apt-pkg/cacheset.h

@@ -12,7 +12,12 @@
 #include <fstream>
 #include <map>
 #include <set>
+#if __cplusplus >= 201103L
+#include <unordered_set>
+#include <forward_list>
+#endif
 #include <list>
+#include <deque>
 #include <vector>
 #include <string>
 #include <iterator>
@@ -50,9 +55,8 @@ class CacheSetHelper {							/*{{{*/
 */
 public:									/*{{{*/
 	CacheSetHelper(bool const ShowError = true,
-		GlobalError::MsgType ErrorType = GlobalError::ERROR) :
-			ShowError(ShowError), ErrorType(ErrorType) {}
-	virtual ~CacheSetHelper() {}
+		GlobalError::MsgType ErrorType = GlobalError::ERROR);
+	virtual ~CacheSetHelper();
 
 	enum PkgSelector { UNKNOWN, REGEX, TASK, FNMATCH, PACKAGENAME, STRING };
 
@@ -203,8 +207,92 @@ protected:
 	bool PackageFromFnmatch(PackageContainerInterface * const pci, pkgCacheFile &Cache, std::string pattern);
 	bool PackageFromPackageName(PackageContainerInterface * const pci, pkgCacheFile &Cache, std::string pattern);
 	bool PackageFromString(PackageContainerInterface * const pci, pkgCacheFile &Cache, std::string const &pattern);
+private:
+	void * const d;
 };									/*}}}*/
+// Iterator templates for our Containers				/*{{{*/
+template<typename Interface, typename Master, typename iterator_type, typename container_iterator, typename container_value> class Container_iterator_base :
+   public std::iterator<typename std::iterator_traits<container_iterator>::iterator_category, container_iterator>,
+   public Interface::template iterator_base<iterator_type>
+{
+protected:
+	container_iterator _iter;
+public:
+	explicit Container_iterator_base(container_iterator i) : _iter(i) {}
+	inline container_value operator*(void) const { return static_cast<iterator_type const*>(this)->getType(); };
+	operator container_iterator(void) const { return _iter; }
+	inline iterator_type& operator++() { ++_iter; return static_cast<iterator_type&>(*this); }
+	inline iterator_type operator++(int) { iterator_type tmp(*this); operator++(); return tmp; }
+	inline iterator_type operator+(typename container_iterator::difference_type const &n) { return iterator_type(_iter + n); }
+	inline iterator_type operator+=(typename container_iterator::difference_type const &n) { _iter += n; return static_cast<iterator_type&>(*this); }
+	inline iterator_type& operator--() { --_iter;; return static_cast<iterator_type&>(*this); }
+	inline iterator_type operator--(int) { iterator_type tmp(*this); operator--(); return tmp; }
+	inline iterator_type operator-(typename container_iterator::difference_type const &n) { return iterator_type(_iter - n); }
+	inline iterator_type operator-=(typename container_iterator::difference_type const &n) { _iter -= n; return static_cast<iterator_type&>(*this); }
+	inline bool operator!=(iterator_type const &i) const { return _iter != i._iter; }
+	inline bool operator==(iterator_type const &i) const { return _iter == i._iter; }
+	inline bool operator<(iterator_type const &i) const { return _iter < i._iter; }
+	inline bool operator>(iterator_type const &i) const { return _iter > i._iter; }
+	inline bool operator<=(iterator_type const &i) const { return _iter <= i._iter; }
+	inline bool operator>=(iterator_type const &i) const { return _iter >= i._iter; }
+	inline typename container_iterator::reference operator[](typename container_iterator::difference_type const &n) const { return _iter[n]; }
+
+	friend std::ostream& operator<<(std::ostream& out, iterator_type i) { return operator<<(out, *i); }
+	friend Master;
+};
+template<class Interface, class Container, class Master> class Container_const_iterator :
+   public Container_iterator_base<Interface, Master, Container_const_iterator<Interface, Container, Master>, typename Container::const_iterator, typename Container::value_type>
+{
+	typedef Container_const_iterator<Interface, Container, Master> iterator_type;
+	typedef typename Container::const_iterator container_iterator;
+public:
+	explicit Container_const_iterator(container_iterator i) :
+	   Container_iterator_base<Interface, Master, iterator_type, container_iterator, typename Container::value_type>(i) {}
+
+	inline typename Container::value_type getType(void) const { return *this->_iter; }
+};
+template<class Interface, class Container, class Master> class Container_iterator :
+   public Container_iterator_base<Interface, Master, Container_iterator<Interface, Container, Master>, typename Container::iterator, typename Container::value_type>
+{
+	typedef Container_iterator<Interface, Container, Master> iterator_type;
+	typedef typename Container::iterator container_iterator;
+public:
+	explicit Container_iterator(container_iterator i) :
+	   Container_iterator_base<Interface, Master, iterator_type, container_iterator, typename Container::value_type>(i) {}
+
+	operator typename Master::const_iterator() { return typename Master::const_iterator(this->_iter); }
+	inline iterator_type& operator=(iterator_type const &i) { this->_iter = i._iter; return static_cast<iterator_type&>(*this); }
+	inline iterator_type& operator=(container_iterator const &i) { this->_iter = i; return static_cast<iterator_type&>(*this); }
+
+	inline typename Container::value_type getType(void) const { return *this->_iter; }
+};
+template<class Interface, class Container, class Master> class Container_const_reverse_iterator :
+   public Container_iterator_base<Interface, Master, Container_const_reverse_iterator<Interface, Container, Master>, typename Container::const_reverse_iterator, typename Container::value_type>
+{
+	typedef Container_const_reverse_iterator<Interface, Container, Master> iterator_type;
+	typedef typename Container::const_reverse_iterator container_iterator;
+public:
+	explicit Container_const_reverse_iterator(container_iterator i) :
+	   Container_iterator_base<Interface, Master, iterator_type, container_iterator, typename Container::value_type>(i) {}
+
+	inline typename Container::value_type getType(void) const { return *this->_iter; }
+};
+template<class Interface, class Container, class Master> class Container_reverse_iterator :
+   public Container_iterator_base<Interface, Master, Container_reverse_iterator<Interface, Container, Master>, typename Container::reverse_iterator, typename Container::value_type>
+{
+	typedef Container_reverse_iterator<Interface, Container, Master> iterator_type;
+	typedef typename Container::reverse_iterator container_iterator;
+public:
+	explicit Container_reverse_iterator(container_iterator i) :
+	   Container_iterator_base<Interface, Master, iterator_type, container_iterator, typename Container::value_type>(i) {}
+
+	operator typename Master::const_iterator() { return typename Master::const_iterator(this->_iter); }
+	inline iterator_type& operator=(iterator_type const &i) { this->_iter = i._iter; return static_cast<iterator_type&>(*this); }
+	inline iterator_type& operator=(container_iterator const &i) { this->_iter = i; return static_cast<iterator_type&>(*this); }
 
+	inline typename Container::value_type getType(void) const { return *this->_iter; }
+};
+									/*}}}*/
 class PackageContainerInterface {					/*{{{*/
 /** \class PackageContainerInterface
 
@@ -216,41 +304,42 @@ class PackageContainerInterface {					/*{{{*/
  * This class mostly protects use from the need to write all implementation
  * of the methods working on containers in the template */
 public:
-	class const_iterator {						/*{{{*/
+	template<class Itr> class iterator_base {			/*{{{*/
+		pkgCache::PkgIterator getType() const { return static_cast<Itr const*>(this)->getType(); };
 	public:
-		virtual pkgCache::PkgIterator getPkg() const = 0;
-		operator pkgCache::PkgIterator(void) const { return getPkg(); }
+		operator pkgCache::PkgIterator(void) const { return getType(); }
 
-		inline const char *Name() const {return getPkg().Name(); }
-		inline std::string FullName(bool const Pretty) const { return getPkg().FullName(Pretty); }
-		inline std::string FullName() const { return getPkg().FullName(); }
+		inline const char *Name() const {return getType().Name(); }
+		inline std::string FullName(bool const Pretty) const { return getType().FullName(Pretty); }
+		inline std::string FullName() const { return getType().FullName(); }
 		APT_DEPRECATED inline const char *Section() const {
 		   APT_IGNORE_DEPRECATED_PUSH
-		      return getPkg().Section();
+		      return getType().Section();
 		   APT_IGNORE_DEPRECATED_POP
 		}
-		inline bool Purge() const {return getPkg().Purge(); }
-		inline const char *Arch() const {return getPkg().Arch(); }
-		inline pkgCache::GrpIterator Group() const { return getPkg().Group(); }
-		inline pkgCache::VerIterator VersionList() const { return getPkg().VersionList(); }
-		inline pkgCache::VerIterator CurrentVer() const { return getPkg().CurrentVer(); }
-		inline pkgCache::DepIterator RevDependsList() const { return getPkg().RevDependsList(); }
-		inline pkgCache::PrvIterator ProvidesList() const { return getPkg().ProvidesList(); }
-		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 bool Purge() const {return getType().Purge(); }
+		inline const char *Arch() const {return getType().Arch(); }
+		inline pkgCache::GrpIterator Group() const { return getType().Group(); }
+		inline pkgCache::VerIterator VersionList() const { return getType().VersionList(); }
+		inline pkgCache::VerIterator CurrentVer() const { return getType().CurrentVer(); }
+		inline pkgCache::DepIterator RevDependsList() const { return getType().RevDependsList(); }
+		inline pkgCache::PrvIterator ProvidesList() const { return getType().ProvidesList(); }
+		inline pkgCache::PkgIterator::OkState State() const { return getType().State(); }
+		inline const char *CandVersion() const { return getType().CandVersion(); }
+		inline const char *CurVersion() const { return getType().CurVersion(); }
+		inline pkgCache *Cache() const { return getType().Cache(); }
+		inline unsigned long Index() const {return getType().Index();}
 		// we have only valid iterators here
 		inline bool end() const { return false; }
 
-		inline pkgCache::Package const * operator->() const {return &*getPkg();}
+		inline pkgCache::Package const * operator->() const {return &*getType();}
 	};
 									/*}}}*/
 
 	virtual bool insert(pkgCache::PkgIterator const &P) = 0;
 	virtual bool empty() const = 0;
 	virtual void clear() = 0;
+	virtual size_t size() const = 0;
 
 	// FIXME: This is a bloody hack removed soon. Use CacheSetHelper::PkgSelector !
 	enum APT_DEPRECATED Constructor { UNKNOWN = CacheSetHelper::UNKNOWN,
@@ -263,8 +352,10 @@ APT_IGNORE_DEPRECATED_POP
 
 	void setConstructor(CacheSetHelper::PkgSelector const by) { ConstructedBy = by; }
 	CacheSetHelper::PkgSelector getConstructor() const { return ConstructedBy; }
-	PackageContainerInterface() : ConstructedBy(CacheSetHelper::UNKNOWN) {}
-	PackageContainerInterface(CacheSetHelper::PkgSelector const by) : ConstructedBy(by) {}
+	PackageContainerInterface();
+	explicit PackageContainerInterface(CacheSetHelper::PkgSelector const by);
+	PackageContainerInterface& operator=(PackageContainerInterface const &other);
+	virtual ~PackageContainerInterface();
 
 	APT_DEPRECATED static bool FromTask(PackageContainerInterface * const pci, pkgCacheFile &Cache, std::string pattern, CacheSetHelper &helper) {
 	   return helper.PackageFrom(CacheSetHelper::TASK, pci, Cache, pattern); }
@@ -292,6 +383,7 @@ APT_IGNORE_DEPRECATED_POP
 
 private:
 	CacheSetHelper::PkgSelector ConstructedBy;
+	void * const d;
 };
 									/*}}}*/
 template<class Container> class PackageContainer : public PackageContainerInterface {/*{{{*/
@@ -303,60 +395,43 @@ template<class Container> class PackageContainer : public PackageContainerInterf
 	Container _cont;
 public:									/*{{{*/
 	/** \brief smell like a pkgCache::PkgIterator */
-	class const_iterator : public PackageContainerInterface::const_iterator,/*{{{*/
-			       public std::iterator<std::forward_iterator_tag, typename Container::const_iterator> {
-		typename Container::const_iterator _iter;
-	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; }
-		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; }
-		friend std::ostream& operator<<(std::ostream& out, const_iterator i) { return operator<<(out, *i); }
-	};
-	class iterator : public PackageContainerInterface::const_iterator,
-			 public std::iterator<std::forward_iterator_tag, typename Container::iterator> {
-		typename Container::iterator _iter;
-	public:
-		iterator(typename Container::iterator i) : _iter(i) {}
-		pkgCache::PkgIterator getPkg(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; }
-		friend std::ostream& operator<<(std::ostream& out, iterator i) { return operator<<(out, *i); }
-	};
-									/*}}}*/
+	typedef Container_const_iterator<PackageContainerInterface, Container, PackageContainer> const_iterator;
+	typedef Container_iterator<PackageContainerInterface, Container, PackageContainer> iterator;
+	typedef Container_const_reverse_iterator<PackageContainerInterface, Container, PackageContainer> const_reverse_iterator;
+	typedef Container_reverse_iterator<PackageContainerInterface, Container, PackageContainer> reverse_iterator;
 
-	bool insert(pkgCache::PkgIterator const &P) { if (P.end() == true) return false; _cont.insert(P); return true; }
+	bool insert(pkgCache::PkgIterator const &P) APT_OVERRIDE { 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(); }
-	//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(); }
-
+	bool empty() const APT_OVERRIDE { return _cont.empty(); }
+	void clear() APT_OVERRIDE { return _cont.clear(); }
+	size_t size() const APT_OVERRIDE { return _cont.size(); }
+#if __GNUC__ >= 5 || (__GNUC_MINOR__ >= 9 && __GNUC__ >= 4)
+	iterator erase( const_iterator pos ) { return iterator(_cont.erase(pos._iter)); }
+	iterator erase( const_iterator first, const_iterator last ) { return iterator(_cont.erase(first._iter, last._iter)); }
+#else
+	iterator erase( iterator pos ) { return iterator(_cont.erase(pos._iter)); }
+	iterator erase( iterator first, iterator last ) { return iterator(_cont.erase(first._iter, last._iter)); }
+#endif
 	const_iterator begin() const { return const_iterator(_cont.begin()); }
 	const_iterator end() const { return const_iterator(_cont.end()); }
+	const_reverse_iterator rbegin() const { return const_reverse_iterator(_cont.rbegin()); }
+	const_reverse_iterator rend() const { return const_reverse_iterator(_cont.rend()); }
+#if __cplusplus >= 201103L
+	const_iterator cbegin() const { return const_iterator(_cont.cbegin()); }
+	const_iterator cend() const { return const_iterator(_cont.cend()); }
+	const_reverse_iterator crbegin() const { return const_reverse_iterator(_cont.crbegin()); }
+	const_reverse_iterator crend() const { return const_reverse_iterator(_cont.crend()); }
+#endif
 	iterator begin() { return iterator(_cont.begin()); }
 	iterator end() { return iterator(_cont.end()); }
+	reverse_iterator rbegin() { return reverse_iterator(_cont.rbegin()); }
+	reverse_iterator rend() { return reverse_iterator(_cont.rend()); }
 	const_iterator find(pkgCache::PkgIterator const &P) const { return const_iterator(_cont.find(P)); }
 
-	PackageContainer() : PackageContainerInterface() {}
-	PackageContainer(CacheSetHelper::PkgSelector const &by) : PackageContainerInterface(by) {}
+	PackageContainer() : PackageContainerInterface(CacheSetHelper::UNKNOWN) {}
+	explicit PackageContainer(CacheSetHelper::PkgSelector const &by) : PackageContainerInterface(by) {}
 APT_IGNORE_DEPRECATED_PUSH
 	APT_DEPRECATED PackageContainer(Constructor const &by) : PackageContainerInterface((CacheSetHelper::PkgSelector)by) {}
 APT_IGNORE_DEPRECATED_POP
@@ -504,16 +579,26 @@ APT_IGNORE_DEPRECATED_POP
 	}
 									/*}}}*/
 };									/*}}}*/
-// specialisations for push_back containers: std::list & std::vector	/*{{{*/
+// various specialisations for PackageContainer				/*{{{*/
 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);
 }
+#if __cplusplus >= 201103L
+template<> template<class Cont> void PackageContainer<std::forward_list<pkgCache::PkgIterator> >::insert(PackageContainer<Cont> const &pkgcont) {
+	for (typename PackageContainer<Cont>::const_iterator p = pkgcont.begin(); p != pkgcont.end(); ++p)
+		_cont.push_front(*p);
+}
+#endif
+template<> template<class Cont> void PackageContainer<std::deque<pkgCache::PkgIterator> >::insert(PackageContainer<Cont> const &pkgcont) {
+	for (typename PackageContainer<Cont>::const_iterator p = pkgcont.begin(); p != pkgcont.end(); ++p)
+		_cont.push_back(*p);
+}
 template<> template<class Cont> void PackageContainer<std::vector<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
+// these 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) {
 	if (P.end() == true)
@@ -521,6 +606,20 @@ template<> inline bool PackageContainer<std::list<pkgCache::PkgIterator> >::inse
 	_cont.push_back(P);
 	return true;
 }
+#if __cplusplus >= 201103L
+template<> inline bool PackageContainer<std::forward_list<pkgCache::PkgIterator> >::insert(pkgCache::PkgIterator const &P) {
+	if (P.end() == true)
+		return false;
+	_cont.push_front(P);
+	return true;
+}
+#endif
+template<> inline bool PackageContainer<std::deque<pkgCache::PkgIterator> >::insert(pkgCache::PkgIterator const &P) {
+	if (P.end() == true)
+		return false;
+	_cont.push_back(P);
+	return true;
+}
 template<> inline bool PackageContainer<std::vector<pkgCache::PkgIterator> >::insert(pkgCache::PkgIterator const &P) {
 	if (P.end() == true)
 		return false;
@@ -531,16 +630,49 @@ template<> inline void PackageContainer<std::list<pkgCache::PkgIterator> >::inse
 	for (const_iterator p = begin; p != end; ++p)
 		_cont.push_back(*p);
 }
+#if __cplusplus >= 201103L
+template<> inline void PackageContainer<std::forward_list<pkgCache::PkgIterator> >::insert(const_iterator begin, const_iterator end) {
+	for (const_iterator p = begin; p != end; ++p)
+		_cont.push_front(*p);
+}
+#endif
+template<> inline void PackageContainer<std::deque<pkgCache::PkgIterator> >::insert(const_iterator begin, const_iterator end) {
+	for (const_iterator p = begin; p != end; ++p)
+		_cont.push_back(*p);
+}
 template<> inline void PackageContainer<std::vector<pkgCache::PkgIterator> >::insert(const_iterator begin, const_iterator end) {
 	for (const_iterator p = begin; p != end; ++p)
 		_cont.push_back(*p);
 }
-									/*}}}*/
-
+#if __cplusplus < 201103L
+template<> inline PackageContainer<std::set<pkgCache::PkgIterator> >::iterator PackageContainer<std::set<pkgCache::PkgIterator> >::erase(iterator i) {
+	_cont.erase(i._iter);
+	return end();
+}
+template<> inline PackageContainer<std::set<pkgCache::PkgIterator> >::iterator PackageContainer<std::set<pkgCache::PkgIterator> >::erase(iterator first, iterator last) {
+	_cont.erase(first, last);
+	return end();
+}
+#endif
 template<> template<class Compare> inline bool PackageContainer<std::vector<pkgCache::PkgIterator> >::sort(Compare Comp) {
 	std::sort(_cont.begin(), _cont.end(), Comp);
 	return true;
 }
+template<> template<class Compare> inline bool PackageContainer<std::list<pkgCache::PkgIterator> >::sort(Compare Comp) {
+	_cont.sort(Comp);
+	return true;
+}
+#if __cplusplus >= 201103L
+template<> template<class Compare> inline bool PackageContainer<std::forward_list<pkgCache::PkgIterator> >::sort(Compare Comp) {
+	_cont.sort(Comp);
+	return true;
+}
+#endif
+template<> template<class Compare> inline bool PackageContainer<std::deque<pkgCache::PkgIterator> >::sort(Compare Comp) {
+	std::sort(_cont.begin(), _cont.end(), Comp);
+	return true;
+}
+									/*}}}*/
 
 // class PackageUniverse - pkgCache as PackageContainerInterface	/*{{{*/
 /** \class PackageUniverse
@@ -550,35 +682,53 @@ template<> template<class Compare> inline bool PackageContainer<std::vector<pkgC
 
     The wrapping is read-only in practice modeled by making erase and co
     private methods. */
-class APT_HIDDEN PackageUniverse : public PackageContainerInterface {
+class APT_PUBLIC PackageUniverse : public PackageContainerInterface {
 	pkgCache * const _cont;
+	void * const d;
 public:
-	typedef pkgCache::PkgIterator iterator;
-	typedef pkgCache::PkgIterator const_iterator;
+	class const_iterator : public APT::Container_iterator_base<APT::PackageContainerInterface, PackageUniverse, PackageUniverse::const_iterator, pkgCache::PkgIterator, pkgCache::PkgIterator>
+	{
+	public:
+	   explicit const_iterator(pkgCache::PkgIterator i):
+	      Container_iterator_base<APT::PackageContainerInterface, PackageUniverse, PackageUniverse::const_iterator, pkgCache::PkgIterator, pkgCache::PkgIterator>(i) {}
+
+	   inline pkgCache::PkgIterator getType(void) const { return _iter; }
+	};
+	typedef const_iterator iterator;
 
-	APT_PUBLIC bool empty() const { return false; }
-	APT_PUBLIC size_t size() const { return _cont->Head().PackageCount; }
+	bool empty() const APT_OVERRIDE { return false; }
+	size_t size() const APT_OVERRIDE { return _cont->Head().PackageCount; }
 
-	APT_PUBLIC const_iterator begin() const { return _cont->PkgBegin(); }
-	APT_PUBLIC const_iterator end() const { return  _cont->PkgEnd(); }
-	APT_PUBLIC iterator begin() { return _cont->PkgBegin(); }
-	APT_PUBLIC iterator end() { return _cont->PkgEnd(); }
+	const_iterator begin() const { return const_iterator(_cont->PkgBegin()); }
+	const_iterator end() const { return const_iterator(_cont->PkgEnd()); }
+	const_iterator cbegin() const { return const_iterator(_cont->PkgBegin()); }
+	const_iterator cend() const { return const_iterator(_cont->PkgEnd()); }
+	iterator begin() { return iterator(_cont->PkgBegin()); }
+	iterator end() { return iterator(_cont->PkgEnd()); }
 
-	APT_PUBLIC PackageUniverse(pkgCache * const Owner) : _cont(Owner) { }
+	pkgCache * data() const { return _cont; }
+
+	explicit PackageUniverse(pkgCache * const Owner);
+	explicit PackageUniverse(pkgCacheFile * const Owner);
+	virtual ~PackageUniverse();
 
 private:
-	bool insert(pkgCache::PkgIterator const &) { return true; }
-	template<class Cont> void insert(PackageContainer<Cont> const &) { }
-	void insert(const_iterator, const_iterator) { }
-
-	void clear() { }
-	iterator& erase(iterator &iter) { return iter; }
-	size_t erase(const pkgCache::PkgIterator) { return 0; }
-	void erase(iterator, iterator) { }
+	APT_HIDDEN bool insert(pkgCache::PkgIterator const &) APT_OVERRIDE { return true; }
+	template<class Cont> APT_HIDDEN void insert(PackageContainer<Cont> const &) { }
+	APT_HIDDEN void insert(const_iterator, const_iterator) { }
+
+	APT_HIDDEN void clear() APT_OVERRIDE { }
+	APT_HIDDEN iterator erase( const_iterator pos );
+	APT_HIDDEN iterator erase( const_iterator first, const_iterator last );
 };
 									/*}}}*/
 typedef PackageContainer<std::set<pkgCache::PkgIterator> > PackageSet;
+#if __cplusplus >= 201103L
+typedef PackageContainer<std::unordered_set<pkgCache::PkgIterator> > PackageUnorderedSet;
+typedef PackageContainer<std::forward_list<pkgCache::PkgIterator> > PackageForwardList;
+#endif
 typedef PackageContainer<std::list<pkgCache::PkgIterator> > PackageList;
+typedef PackageContainer<std::deque<pkgCache::PkgIterator> > PackageDeque;
 typedef PackageContainer<std::vector<pkgCache::PkgIterator> > PackageVector;
 
 class VersionContainerInterface {					/*{{{*/
@@ -587,38 +737,39 @@ class VersionContainerInterface {					/*{{{*/
     Same as APT::PackageContainerInterface, just for Versions */
 public:
 	/** \brief smell like a pkgCache::VerIterator */
-	class const_iterator {						/*{{{*/
+	template<class Itr> class iterator_base {			/*{{{*/
+	   pkgCache::VerIterator getType() const { return static_cast<Itr const*>(this)->getType(); };
 	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(); }
+		operator pkgCache::VerIterator(void) { return getType(); }
+
+		inline pkgCache *Cache() const { return getType().Cache(); }
+		inline unsigned long Index() const {return getType().Index();}
+		inline int CompareVer(const pkgCache::VerIterator &B) const { return getType().CompareVer(B); }
+		inline const char *VerStr() const { return getType().VerStr(); }
+		inline const char *Section() const { return getType().Section(); }
+		inline const char *Arch() const { return getType().Arch(); }
+		inline pkgCache::PkgIterator ParentPkg() const { return getType().ParentPkg(); }
+		inline pkgCache::DescIterator DescriptionList() const { return getType().DescriptionList(); }
+		inline pkgCache::DescIterator TranslatedDescription() const { return getType().TranslatedDescription(); }
+		inline pkgCache::DepIterator DependsList() const { return getType().DependsList(); }
+		inline pkgCache::PrvIterator ProvidesList() const { return getType().ProvidesList(); }
+		inline pkgCache::VerFileIterator FileList() const { return getType().FileList(); }
+		inline bool Downloadable() const { return getType().Downloadable(); }
+		inline const char *PriorityType() const { return getType().PriorityType(); }
+		inline std::string RelStr() const { return getType().RelStr(); }
+		inline bool Automatic() const { return getType().Automatic(); }
+		inline pkgCache::VerFileIterator NewestFile() const { return getType().NewestFile(); }
 		// we have only valid iterators here
 		inline bool end() const { return false; }
 
-		inline pkgCache::Version const * operator->() const { return &*getVer(); }
+		inline pkgCache::Version const * operator->() const { return &*getType(); }
 	};
 									/*}}}*/
 
 	virtual bool insert(pkgCache::VerIterator const &V) = 0;
 	virtual bool empty() const = 0;
 	virtual void clear() = 0;
+	virtual size_t size() const = 0;
 
 	/** \brief specifies which version(s) will be returned if non is given */
 	enum APT_DEPRECATED Version {
@@ -701,6 +852,12 @@ APT_IGNORE_DEPRECATED_PUSH
 	}
 APT_IGNORE_DEPRECATED_POP
 
+	VersionContainerInterface();
+	VersionContainerInterface& operator=(VersionContainerInterface const &other);
+	virtual ~VersionContainerInterface();
+private:
+	void * const d;
+
 protected:								/*{{{*/
 
 	/** \brief returns the candidate version of the package
@@ -729,56 +886,38 @@ template<class Container> class VersionContainer : public VersionContainerInterf
     pkgCache. */
 	Container _cont;
 public:									/*{{{*/
-	/** \brief smell like a pkgCache::VerIterator */
-	class const_iterator : public VersionContainerInterface::const_iterator,
-			       public std::iterator<std::forward_iterator_tag, typename Container::const_iterator> {/*{{{*/
-		typename Container::const_iterator _iter;
-	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; }
-		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; }
-		friend std::ostream& operator<<(std::ostream& out, const_iterator i) { return operator<<(out, *i); }
-	};
-	class iterator : public VersionContainerInterface::const_iterator,
-			 public std::iterator<std::forward_iterator_tag, typename Container::iterator> {
-		typename Container::iterator _iter;
-	public:
-		iterator(typename Container::iterator i) : _iter(i) {}
-		pkgCache::VerIterator getVer(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; }
-		friend std::ostream& operator<<(std::ostream& out, iterator i) { return operator<<(out, *i); }
-	};
-									/*}}}*/
+	typedef Container_const_iterator<VersionContainerInterface, Container, VersionContainer> const_iterator;
+	typedef Container_iterator<VersionContainerInterface, Container, VersionContainer> iterator;
+	typedef Container_const_reverse_iterator<VersionContainerInterface, Container, VersionContainer> const_reverse_iterator;
+	typedef Container_reverse_iterator<VersionContainerInterface, Container, VersionContainer> reverse_iterator;
 
-	bool insert(pkgCache::VerIterator const &V) { if (V.end() == true) return false; _cont.insert(V); return true; }
+	bool insert(pkgCache::VerIterator const &V) APT_OVERRIDE { 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(); }
-
+	bool empty() const APT_OVERRIDE { return _cont.empty(); }
+	void clear() APT_OVERRIDE { return _cont.clear(); }
+	size_t size() const APT_OVERRIDE { return _cont.size(); }
+#if __GNUC__ >= 5 || (__GNUC_MINOR__ >= 9 && __GNUC__ >= 4)
+	iterator erase( const_iterator pos ) { return iterator(_cont.erase(pos._iter)); }
+	iterator erase( const_iterator first, const_iterator last ) { return iterator(_cont.erase(first._iter, last._iter)); }
+#else
+	iterator erase( iterator pos ) { return iterator(_cont.erase(pos._iter)); }
+	iterator erase( iterator first, iterator last ) { return iterator(_cont.erase(first._iter, last._iter)); }
+#endif
 	const_iterator begin() const { return const_iterator(_cont.begin()); }
 	const_iterator end() const { return const_iterator(_cont.end()); }
+	const_reverse_iterator rbegin() const { return const_reverse_iterator(_cont.rbegin()); }
+	const_reverse_iterator rend() const { return const_reverse_iterator(_cont.rend()); }
+#if __cplusplus >= 201103L
+	const_iterator cbegin() const { return const_iterator(_cont.cbegin()); }
+	const_iterator cend() const { return const_iterator(_cont.cend()); }
+	const_reverse_iterator crbegin() const { return const_reverse_iterator(_cont.crbegin()); }
+	const_reverse_iterator crend() const { return const_reverse_iterator(_cont.crend()); }
+#endif
 	iterator begin() { return iterator(_cont.begin()); }
 	iterator end() { return iterator(_cont.end()); }
+	reverse_iterator rbegin() { return reverse_iterator(_cont.rbegin()); }
+	reverse_iterator rend() { return reverse_iterator(_cont.rend()); }
 	const_iterator find(pkgCache::VerIterator const &V) const { return const_iterator(_cont.find(V)); }
 
 	/** \brief sort all included versions with given comparer
@@ -924,7 +1063,7 @@ APT_IGNORE_DEPRECATED_POP
 	static VersionContainer FromDependency(pkgCacheFile &Cache, pkgCache::DepIterator const &D,
 					       CacheSetHelper::VerSelector const selector) {
 		CacheSetHelper helper;
-		return FromPackage(Cache, D, selector, helper);
+		return FromDependency(Cache, D, selector, helper);
 	}
 APT_IGNORE_DEPRECATED_PUSH
 	static VersionContainer FromDependency(pkgCacheFile &Cache, pkgCache::DepIterator const &D,
@@ -936,24 +1075,34 @@ APT_IGNORE_DEPRECATED_PUSH
 	static VersionContainer FromDependency(pkgCacheFile &Cache, pkgCache::DepIterator const &D,
 					       Version const &selector) {
 		CacheSetHelper helper;
-		return FromPackage(Cache, D, (CacheSetHelper::VerSelector)selector, helper);
+		return FromDependency(Cache, D, (CacheSetHelper::VerSelector)selector, helper);
 	}
 APT_IGNORE_DEPRECATED_POP
 	static VersionContainer FromDependency(pkgCacheFile &Cache, pkgCache::DepIterator const &D) {
-		return FromPackage(Cache, D, CacheSetHelper::CANDIDATE);
+		return FromDependency(Cache, D, CacheSetHelper::CANDIDATE);
 	}
 									/*}}}*/
 };									/*}}}*/
-// specialisations for push_back containers: std::list & std::vector	/*{{{*/
+// various specialisations for VersionContainer				/*{{{*/
 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);
 }
+#if __cplusplus >= 201103L
+template<> template<class Cont> void VersionContainer<std::forward_list<pkgCache::VerIterator> >::insert(VersionContainer<Cont> const &vercont) {
+	for (typename VersionContainer<Cont>::const_iterator v = vercont.begin(); v != vercont.end(); ++v)
+		_cont.push_front(*v);
+}
+#endif
+template<> template<class Cont> void VersionContainer<std::deque<pkgCache::VerIterator> >::insert(VersionContainer<Cont> const &vercont) {
+	for (typename VersionContainer<Cont>::const_iterator v = vercont.begin(); v != vercont.end(); ++v)
+		_cont.push_back(*v);
+}
 template<> template<class Cont> void VersionContainer<std::vector<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
+// these 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) {
 	if (V.end() == true)
@@ -961,6 +1110,20 @@ template<> inline bool VersionContainer<std::list<pkgCache::VerIterator> >::inse
 	_cont.push_back(V);
 	return true;
 }
+#if __cplusplus >= 201103L
+template<> inline bool VersionContainer<std::forward_list<pkgCache::VerIterator> >::insert(pkgCache::VerIterator const &V) {
+	if (V.end() == true)
+		return false;
+	_cont.push_front(V);
+	return true;
+}
+#endif
+template<> inline bool VersionContainer<std::deque<pkgCache::VerIterator> >::insert(pkgCache::VerIterator const &V) {
+	if (V.end() == true)
+		return false;
+	_cont.push_back(V);
+	return true;
+}
 template<> inline bool VersionContainer<std::vector<pkgCache::VerIterator> >::insert(pkgCache::VerIterator const &V) {
 	if (V.end() == true)
 		return false;
@@ -971,19 +1134,57 @@ template<> inline void VersionContainer<std::list<pkgCache::VerIterator> >::inse
 	for (const_iterator v = begin; v != end; ++v)
 		_cont.push_back(*v);
 }
+#if __cplusplus >= 201103L
+template<> inline void VersionContainer<std::forward_list<pkgCache::VerIterator> >::insert(const_iterator begin, const_iterator end) {
+	for (const_iterator v = begin; v != end; ++v)
+		_cont.push_front(*v);
+}
+#endif
+template<> inline void VersionContainer<std::deque<pkgCache::VerIterator> >::insert(const_iterator begin, const_iterator end) {
+	for (const_iterator v = begin; v != end; ++v)
+		_cont.push_back(*v);
+}
 template<> inline void VersionContainer<std::vector<pkgCache::VerIterator> >::insert(const_iterator begin, const_iterator end) {
 	for (const_iterator v = begin; v != end; ++v)
 		_cont.push_back(*v);
 }
-									/*}}}*/
-
+#if __cplusplus < 201103L
+template<> inline VersionContainer<std::set<pkgCache::VerIterator> >::iterator VersionContainer<std::set<pkgCache::VerIterator> >::erase(iterator i) {
+	_cont.erase(i._iter);
+	return end();
+}
+template<> inline VersionContainer<std::set<pkgCache::VerIterator> >::iterator VersionContainer<std::set<pkgCache::VerIterator> >::erase(iterator first, iterator last) {
+	_cont.erase(first, last);
+	return end();
+}
+#endif
 template<> template<class Compare> inline bool VersionContainer<std::vector<pkgCache::VerIterator> >::sort(Compare Comp) {
 	std::sort(_cont.begin(), _cont.end(), Comp);
 	return true;
 }
+template<> template<class Compare> inline bool VersionContainer<std::list<pkgCache::VerIterator> >::sort(Compare Comp) {
+	_cont.sort(Comp);
+	return true;
+}
+#if __cplusplus >= 201103L
+template<> template<class Compare> inline bool VersionContainer<std::forward_list<pkgCache::VerIterator> >::sort(Compare Comp) {
+	_cont.sort(Comp);
+	return true;
+}
+#endif
+template<> template<class Compare> inline bool VersionContainer<std::deque<pkgCache::VerIterator> >::sort(Compare Comp) {
+	std::sort(_cont.begin(), _cont.end(), Comp);
+	return true;
+}
+									/*}}}*/
 
 typedef VersionContainer<std::set<pkgCache::VerIterator> > VersionSet;
+#if __cplusplus >= 201103L
+typedef VersionContainer<std::unordered_set<pkgCache::VerIterator> > VersionUnorderedSet;
+typedef VersionContainer<std::forward_list<pkgCache::VerIterator> > VersionForwardList;
+#endif
 typedef VersionContainer<std::list<pkgCache::VerIterator> > VersionList;
+typedef VersionContainer<std::deque<pkgCache::VerIterator> > VersionDeque;
 typedef VersionContainer<std::vector<pkgCache::VerIterator> > VersionVector;
 }
 #endif

+ 10 - 3
apt-pkg/cdrom.cc

@@ -16,14 +16,15 @@
 #include <iostream>
 #include <string>
 #include <vector>
-#include <sstream>
-#include <fstream>
 #include <sys/stat.h>
 #include <dirent.h>
 #include <unistd.h>
 #include <stdio.h>
 #include <algorithm>
 #include <dlfcn.h>
+#include <iostream>
+#include <sstream>
+#include <fstream>
 
 #include<apti18n.h>
 
@@ -917,7 +918,7 @@ bool pkgCdrom::Add(pkgCdromStatus *log)					/*{{{*/
 }
 									/*}}}*/
 pkgUdevCdromDevices::pkgUdevCdromDevices()				/*{{{*/
-: libudev_handle(NULL), udev_new(NULL), udev_enumerate_add_match_property(NULL),
+: d(NULL), libudev_handle(NULL), udev_new(NULL), udev_enumerate_add_match_property(NULL),
    udev_enumerate_scan_devices(NULL), udev_enumerate_get_list_entry(NULL),
    udev_device_new_from_syspath(NULL), udev_enumerate_get_udev(NULL),
    udev_list_entry_get_name(NULL), udev_device_get_devnode(NULL),
@@ -1022,3 +1023,9 @@ pkgUdevCdromDevices::~pkgUdevCdromDevices()                             /*{{{*/
       dlclose(libudev_handle);
 }
 									/*}}}*/
+
+pkgCdromStatus::pkgCdromStatus() : d(NULL), totalSteps(0) {}
+pkgCdromStatus::~pkgCdromStatus() {}
+
+pkgCdrom::pkgCdrom() : d(NULL) {}
+pkgCdrom::~pkgCdrom() {}

+ 9 - 2
apt-pkg/cdrom.h

@@ -18,12 +18,13 @@ class OpProgress;
 
 class pkgCdromStatus							/*{{{*/
 {
+   void * const d;
  protected:
    int totalSteps;
 
  public:
-   pkgCdromStatus() : totalSteps(0) {};
-   virtual ~pkgCdromStatus() {};
+   pkgCdromStatus();
+   virtual ~pkgCdromStatus();
 
    // total steps
    virtual void SetTotal(int total) { totalSteps = total; };
@@ -74,7 +75,12 @@ class pkgCdrom								/*{{{*/
    bool Ident(std::string &ident, pkgCdromStatus *log);
    bool Add(pkgCdromStatus *log);
 
+   pkgCdrom();
+   virtual ~pkgCdrom();
+
  private:
+   void * const d;
+
    APT_HIDDEN bool MountAndIdentCDROM(Configuration &Database, std::string &CDROM,
 	 std::string &ident, pkgCdromStatus * const log, bool const interactive);
    APT_HIDDEN bool UnmountCDROM(std::string const &CDROM, pkgCdromStatus * const log);
@@ -92,6 +98,7 @@ struct CdromDevice							/*{{{*/
 									/*}}}*/
 class pkgUdevCdromDevices						/*{{{*/
 {
+   void * const d;
  protected:
    // libudev dlopen structure
    void *libudev_handle;

+ 2 - 1
apt-pkg/clean.cc

@@ -106,7 +106,7 @@ bool pkgArchiveCleaner::Go(std::string Dir,pkgCache &Cache)
 		 J.end() == false; ++J)
 	    {
 	       if (CleanInstalled == true &&
-		   (J.File()->Flags & pkgCache::Flag::NotSource) != 0)
+		   J.File().Flagged(pkgCache::Flag::NotSource))
 		  continue;
 	       IsFetchable = true;
 	       break;
@@ -132,4 +132,5 @@ bool pkgArchiveCleaner::Go(std::string Dir,pkgCache &Cache)
 }
 									/*}}}*/
 
+pkgArchiveCleaner::pkgArchiveCleaner() : d(NULL) {}
 APT_CONST pkgArchiveCleaner::~pkgArchiveCleaner() {}

+ 3 - 1
apt-pkg/clean.h

@@ -21,7 +21,7 @@ class pkgCache;
 class pkgArchiveCleaner
 {
    /** \brief dpointer placeholder (for later in case we need it) */
-   void *d;
+   void * const d;
 
    protected:
 
@@ -30,6 +30,8 @@ class pkgArchiveCleaner
    public:
 
    bool Go(std::string Dir,pkgCache &Cache);
+
+   pkgArchiveCleaner();
    virtual ~pkgArchiveCleaner();
 };
 

+ 2 - 0
apt-pkg/contrib/cdromutl.cc

@@ -287,9 +287,11 @@ string FindMountPointForDevice(const char *devnode)
 	    fclose(f);
 	    // unescape the \0XXX chars in the path
 	    string mount_point = out[1];
+	    free(line);
 	    return DeEscapeString(mount_point);
 	 }
 	 fclose(f);
+	 free(line);
       }
 
    return string();

+ 4 - 4
apt-pkg/contrib/cmndline.cc

@@ -124,7 +124,7 @@ bool CommandLine::Parse(int argc,const char **argv)
 	    Args *A;
 	    for (A = ArgList; A->end() == false && A->ShortOpt != *Opt; A++);
 	    if (A->end() == true)
-	       return _error->Error(_("Command line option '%c' [from %s] is not known."),*Opt,argv[I]);
+	       return _error->Error(_("Command line option '%c' [from %s] is not understood in combination with the other options."),*Opt,argv[I]);
 
 	    if (HandleOpt(I,argc,argv,Opt,A) == false)
 	       return false;
@@ -149,7 +149,7 @@ bool CommandLine::Parse(int argc,const char **argv)
       {
          Opt = (const char*) memchr(Opt, '-', OptEnd - Opt);
 	 if (Opt == NULL)
-	    return _error->Error(_("Command line option %s is not understood"),argv[I]);
+	    return _error->Error(_("Command line option %s is not understood in combination with the other options"),argv[I]);
 	 Opt++;
 	 
 	 for (A = ArgList; A->end() == false &&
@@ -158,7 +158,7 @@ bool CommandLine::Parse(int argc,const char **argv)
 
 	 // Failed again..
 	 if (A->end() == true && OptEnd - Opt != 1)
-	    return _error->Error(_("Command line option %s is not understood"),argv[I]);
+	    return _error->Error(_("Command line option %s is not understood in combination with the other options"),argv[I]);
 
 	 // The option could be a single letter option prefixed by a no-..
 	 if (A->end() == true)
@@ -166,7 +166,7 @@ bool CommandLine::Parse(int argc,const char **argv)
 	    for (A = ArgList; A->end() == false && A->ShortOpt != *Opt; A++);
 	    
 	    if (A->end() == true)
-	       return _error->Error(_("Command line option %s is not understood"),argv[I]);
+	       return _error->Error(_("Command line option %s is not understood in combination with the other options"),argv[I]);
 	 }
 	 
 	 // The option is not boolean

+ 2 - 8
apt-pkg/contrib/configuration.cc

@@ -253,13 +253,7 @@ 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 */
-#if APT_PKG_ABI < 413
-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> Configuration::FindVector(const char *Name, std::string const &Default, bool const Keys) const
 {
    vector<string> Vec;
    const Item *Top = Lookup(Name);
@@ -272,7 +266,7 @@ vector<string> Configuration::FindVector(const char *Name, std::string const &De
    Item *I = Top->Child;
    while(I != NULL)
    {
-      Vec.push_back(I->Value);
+      Vec.push_back(Keys ? I->Tag : I->Value);
       I = I->Next;
    }
    if (Vec.empty() == true)

+ 2 - 9
apt-pkg/contrib/configuration.h

@@ -84,15 +84,8 @@ class Configuration
     *
     * \param Name of the parent node
     * \param Default list of values separated by commas */
-#if APT_PKG_ABI >= 413
-   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); };
-#else
-   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); };
-   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(const char *Name, std::string const &Default = "", bool const Keys = false) const;
+   std::vector<std::string> FindVector(std::string const &Name, std::string const &Default = "", bool const Keys = false) const { return FindVector(Name.c_str(), Default, Keys); };
 
    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);};

+ 62 - 19
apt-pkg/contrib/fileutl.cc

@@ -52,6 +52,7 @@
 
 #include <set>
 #include <algorithm>
+#include <memory>
 
 #ifdef HAVE_ZLIB
 	#include <zlib.h>
@@ -159,7 +160,7 @@ bool CopyFile(FileFd &From,FileFd &To)
       return false;
    
    // Buffered copy between fds
-   SPtrArray<unsigned char> Buf = new unsigned char[64000];
+   std::unique_ptr<unsigned char[]> Buf(new unsigned char[64000]);
    unsigned long long Size = From.Size();
    while (Size != 0)
    {
@@ -167,8 +168,8 @@ bool CopyFile(FileFd &From,FileFd &To)
       if (Size > 64000)
 	 ToRead = 64000;
       
-      if (From.Read(Buf,ToRead) == false || 
-	  To.Write(Buf,ToRead) == false)
+      if (From.Read(Buf.get(),ToRead) == false ||
+	  To.Write(Buf.get(),ToRead) == false)
 	 return false;
       
       Size -= ToRead;
@@ -800,12 +801,26 @@ pid_t ExecFork(std::set<int> KeepFDs)
       signal(SIGCONT,SIG_DFL);
       signal(SIGTSTP,SIG_DFL);
 
-      long ScOpenMax = sysconf(_SC_OPEN_MAX);
-      // Close all of our FDs - just in case
-      for (int K = 3; K != ScOpenMax; K++)
+      DIR *dir = opendir("/proc/self/fd");
+      if (dir != NULL)
       {
-	 if(KeepFDs.find(K) == KeepFDs.end())
-	    fcntl(K,F_SETFD,FD_CLOEXEC);
+	 struct dirent *ent;
+	 while ((ent = readdir(dir)))
+	 {
+	    int fd = atoi(ent->d_name);
+	    // If fd > 0, it was a fd number and not . or ..
+	    if (fd >= 3 && KeepFDs.find(fd) == KeepFDs.end())
+	       fcntl(fd,F_SETFD,FD_CLOEXEC);
+	 }
+	 closedir(dir);
+      } else {
+	 long ScOpenMax = sysconf(_SC_OPEN_MAX);
+	 // Close all of our FDs - just in case
+	 for (int K = 3; K != ScOpenMax; K++)
+	 {
+	    if(KeepFDs.find(K) == KeepFDs.end())
+	       fcntl(K,F_SETFD,FD_CLOEXEC);
+	 }
       }
    }
    
@@ -1011,6 +1026,25 @@ class FileFdPrivate {							/*{{{*/
 	~FileFdPrivate() { CloseDown(""); }
 };
 									/*}}}*/
+// FileFd Constructors							/*{{{*/
+FileFd::FileFd(std::string FileName,unsigned int const Mode,unsigned long AccessMode) : iFd(-1), Flags(0), d(NULL)
+{
+   Open(FileName,Mode, None, AccessMode);
+}
+FileFd::FileFd(std::string FileName,unsigned int const Mode, CompressMode Compress, unsigned long AccessMode) : iFd(-1), Flags(0), d(NULL)
+{
+   Open(FileName,Mode, Compress, AccessMode);
+}
+FileFd::FileFd() : iFd(-1), Flags(AutoClose), d(NULL) {}
+FileFd::FileFd(int const Fd, unsigned int const Mode, CompressMode Compress) : iFd(-1), Flags(0), d(NULL)
+{
+   OpenDescriptor(Fd, Mode, Compress);
+}
+FileFd::FileFd(int const Fd, bool const AutoClose) : iFd(-1), Flags(0), d(NULL)
+{
+   OpenDescriptor(Fd, ReadWrite, None, AutoClose);
+}
+									/*}}}*/
 // FileFd::Open - Open a file						/*{{{*/
 // ---------------------------------------------------------------------
 /* The most commonly used open mode combinations are given with Mode */
@@ -2096,28 +2130,27 @@ std::string GetTempDir()						/*{{{*/
    return string(tmpdir);
 }
 									/*}}}*/
-FileFd* GetTempFile(std::string const &Prefix, bool ImmediateUnlink)	/*{{{*/
+FileFd* GetTempFile(std::string const &Prefix, bool ImmediateUnlink, FileFd * const TmpFd)	/*{{{*/
 {
    char fn[512];
-   FileFd *Fd = new FileFd();
+   FileFd * const Fd = TmpFd == NULL ? new FileFd() : TmpFd;
 
-   std::string tempdir = GetTempDir();
-   snprintf(fn, sizeof(fn), "%s/%s.XXXXXX", 
+   std::string const tempdir = GetTempDir();
+   snprintf(fn, sizeof(fn), "%s/%s.XXXXXX",
             tempdir.c_str(), Prefix.c_str());
-   int fd = mkstemp(fn);
+   int const fd = mkstemp(fn);
    if(ImmediateUnlink)
       unlink(fn);
-   if (fd < 0) 
+   if (fd < 0)
    {
       _error->Errno("GetTempFile",_("Unable to mkstemp %s"), fn);
       return NULL;
    }
-   if (!Fd->OpenDescriptor(fd, FileFd::WriteOnly, FileFd::None, true))
+   if (!Fd->OpenDescriptor(fd, FileFd::ReadWrite, FileFd::None, true))
    {
       _error->Errno("GetTempFile",_("Unable to write to %s"),fn);
       return NULL;
    }
-
    return Fd;
 }
 									/*}}}*/
@@ -2219,22 +2252,32 @@ bool DropPrivileges()							/*{{{*/
       return _error->Error("No user %s, can not drop rights", toUser.c_str());
 
    // Do not change the order here, it might break things
+   // Get rid of all our supplementary groups first
    if (setgroups(1, &pw->pw_gid))
       return _error->Errno("setgroups", "Failed to setgroups");
 
+   // Now change the group ids to the new user
+#ifdef HAVE_SETRESGID
+   if (setresgid(pw->pw_gid, pw->pw_gid, pw->pw_gid) != 0)
+      return _error->Errno("setresgid", "Failed to set new group ids");
+#else
    if (setegid(pw->pw_gid) != 0)
       return _error->Errno("setegid", "Failed to setegid");
 
    if (setgid(pw->pw_gid) != 0)
       return _error->Errno("setgid", "Failed to setgid");
+#endif
 
+   // Change the user ids to the new user
+#ifdef HAVE_SETRESUID
+   if (setresuid(pw->pw_uid, pw->pw_uid, pw->pw_uid) != 0)
+      return _error->Errno("setresuid", "Failed to set new user ids");
+#else
    if (setuid(pw->pw_uid) != 0)
       return _error->Errno("setuid", "Failed to setuid");
-
-   // the seteuid() is probably uneeded (at least thats what the linux
-   // man-page says about setuid(2)) but we cargo culted it anyway
    if (seteuid(pw->pw_uid) != 0)
       return _error->Errno("seteuid", "Failed to seteuid");
+#endif
 
    // Verify that the user has only a single group, and the correct one
    gid_t groups[1];

+ 11 - 21
apt-pkg/contrib/fileutl.h

@@ -130,28 +130,17 @@ class FileFd
    inline bool Eof() {return (Flags & HitEof) == HitEof;};
    inline bool IsCompressed() {return (Flags & Compressed) == Compressed;};
    inline std::string &Name() {return FileName;};
-   
-   FileFd(std::string FileName,unsigned int const Mode,unsigned long AccessMode = 0666) : iFd(-1), Flags(0), d(NULL)
-   {
-      Open(FileName,Mode, None, AccessMode);
-   };
-   FileFd(std::string FileName,unsigned int const Mode, CompressMode Compress, unsigned long AccessMode = 0666) : iFd(-1), Flags(0), d(NULL)
-   {
-      Open(FileName,Mode, Compress, AccessMode);
-   };
-   FileFd() : iFd(-1), Flags(AutoClose), d(NULL) {};
-   FileFd(int const Fd, unsigned int const Mode = ReadWrite, CompressMode Compress = None) : iFd(-1), Flags(0), d(NULL)
-   {
-      OpenDescriptor(Fd, Mode, Compress);
-   };
-   FileFd(int const Fd, bool const AutoClose) : iFd(-1), Flags(0), d(NULL)
-   {
-      OpenDescriptor(Fd, ReadWrite, None, AutoClose);
-   };
+
+   FileFd(std::string FileName,unsigned int const Mode,unsigned long AccessMode = 0666);
+   FileFd(std::string FileName,unsigned int const Mode, CompressMode Compress, unsigned long AccessMode = 0666);
+   FileFd();
+   FileFd(int const Fd, unsigned int const Mode = ReadWrite, CompressMode Compress = None);
+   FileFd(int const Fd, bool const AutoClose);
    virtual ~FileFd();
 
    private:
-   FileFdPrivate* d;
+   FileFdPrivate * d;
+   APT_HIDDEN FileFd & operator=(const FileFd &);
    APT_HIDDEN bool OpenInternDescriptor(unsigned int const Mode, APT::Configuration::Compressor const &compressor);
 
    // private helpers to set Fail flag and call _error->Error
@@ -170,8 +159,9 @@ time_t GetModificationTime(std::string const &Path);
 bool Rename(std::string From, std::string To);
 
 std::string GetTempDir();
-FileFd* GetTempFile(std::string const &Prefix = "", 
-                    bool ImmediateUnlink = true);
+FileFd* GetTempFile(std::string const &Prefix = "",
+                    bool ImmediateUnlink = true,
+		    FileFd * const TmpFd = NULL);
 
 /** \brief Ensure the existence of the given Path
  *

+ 18 - 1
apt-pkg/contrib/gpgv.cc

@@ -16,6 +16,8 @@
 #include <sys/wait.h>
 #include <unistd.h>
 #include <stddef.h>
+
+#include <algorithm>
 #include <iostream>
 #include <string>
 #include <vector>
@@ -42,7 +44,7 @@ static char * GenerateTemporaryFileTemplate(const char *basename)	/*{{{*/
    of the lifting in regards to merging keyrings. Fun for the whole family.
 */
 void ExecGPGV(std::string const &File, std::string const &FileGPG,
-             int const &statusfd, int fd[2])
+             int const &statusfd, int fd[2], std::string const &key)
 {
    #define EINTERNAL 111
    std::string const aptkey = _config->FindFile("Dir::Bin::apt-key", "/usr/bin/apt-key");
@@ -55,6 +57,19 @@ void ExecGPGV(std::string const &File, std::string const &FileGPG,
    Args.push_back(aptkey.c_str());
    Args.push_back("--quiet");
    Args.push_back("--readonly");
+   if (key.empty() == false)
+   {
+      if (key[0] == '/')
+      {
+	 Args.push_back("--keyring");
+	 Args.push_back(key.c_str());
+      }
+      else
+      {
+	 Args.push_back("--keyid");
+	 Args.push_back(key.c_str());
+      }
+   }
    Args.push_back("verify");
 
    char statusfdstr[10];
@@ -296,6 +311,8 @@ bool SplitClearSignedFile(std::string const &InFile, FileFd * const ContentFile,
       // all the rest is whitespace, unsigned garbage or additional message blocks we ignore
    }
    fclose(in);
+   if (buf != NULL)
+      free(buf);
 
    if (found_signature == true)
       return _error->Error("Signature in file %s wasn't closed", InFile.c_str());

+ 4 - 1
apt-pkg/contrib/gpgv.h

@@ -38,9 +38,12 @@ class FileFd;
  *
  * @param File is the message (unsigned or clear-signed)
  * @param FileSig is the signature (detached or clear-signed)
+ * @param statusfd is the fd given to gpgv as --status-fd
+ * @param fd is used as a pipe for the standard output of gpgv
+ * @param key is the specific one to be used instead of using all
  */
 void ExecGPGV(std::string const &File, std::string const &FileSig,
-      int const &statusfd, int fd[2]) APT_NORETURN;
+      int const &statusfd, int fd[2], std::string const &Key = "") APT_NORETURN;
 inline APT_NORETURN void ExecGPGV(std::string const &File, std::string const &FileSig,
       int const &statusfd = -1) {
    int fd[2];

+ 34 - 18
apt-pkg/contrib/hashes.cc

@@ -23,6 +23,7 @@
 #include <stddef.h>
 #include <algorithm>
 #include <unistd.h>
+#include <stdlib.h>
 #include <string>
 #include <iostream>
 									/*}}}*/
@@ -178,6 +179,22 @@ HashString const * HashStringList::find(char const * const type) const /*{{{*/
    return NULL;
 }
 									/*}}}*/
+unsigned long long HashStringList::FileSize() const			/*{{{*/
+{
+   HashString const * const hsf = find("Checksum-FileSize");
+   if (hsf == NULL)
+      return 0;
+   std::string const hv = hsf->HashValue();
+   return strtoull(hv.c_str(), NULL, 10);
+}
+									/*}}}*/
+bool HashStringList::FileSize(unsigned long long const Size)		/*{{{*/
+{
+   std::string size;
+   strprintf(size, "%llu", Size);
+   return push_back(HashString("Checksum-FileSize", size));
+}
+									/*}}}*/
 bool HashStringList::supported(char const * const type)			/*{{{*/
 {
    for (char const * const * t = HashString::SupportedHashes(); *t != NULL; ++t)
@@ -259,7 +276,19 @@ public:
    unsigned long long FileSize;
    unsigned int CalcHashes;
 
-   PrivateHashes(unsigned int const CalcHashes) : FileSize(0), CalcHashes(CalcHashes) {}
+   explicit PrivateHashes(unsigned int const CalcHashes) : FileSize(0), CalcHashes(CalcHashes) {}
+   explicit PrivateHashes(HashStringList const &Hashes) : FileSize(0) {
+      unsigned int calcHashes = Hashes.usable() ? 0 : ~0;
+      if (Hashes.find("MD5Sum") != NULL)
+	 calcHashes |= Hashes::MD5SUM;
+      if (Hashes.find("SHA1") != NULL)
+	 calcHashes |= Hashes::SHA1SUM;
+      if (Hashes.find("SHA256") != NULL)
+	 calcHashes |= Hashes::SHA256SUM;
+      if (Hashes.find("SHA512") != NULL)
+	 calcHashes |= Hashes::SHA512SUM;
+      CalcHashes = calcHashes;
+   }
 };
 									/*}}}*/
 // Hashes::Add* - Add the contents of data or FD			/*{{{*/
@@ -351,25 +380,12 @@ APT_IGNORE_DEPRECATED_PUSH
    if ((d->CalcHashes & SHA512SUM) == SHA512SUM)
       hashes.push_back(HashString("SHA512", SHA512.Result().Value()));
 APT_IGNORE_DEPRECATED_POP
-   std::string SizeStr;
-   strprintf(SizeStr, "%llu", d->FileSize);
-   hashes.push_back(HashString("Checksum-FileSize", SizeStr));
+   hashes.FileSize(d->FileSize);
    return hashes;
 }
 APT_IGNORE_DEPRECATED_PUSH
-Hashes::Hashes() { d = new PrivateHashes(~0); }
-Hashes::Hashes(unsigned int const Hashes) { d = new PrivateHashes(Hashes); }
-Hashes::Hashes(HashStringList const &Hashes) {
-   unsigned int calcHashes = Hashes.usable() ? 0 : ~0;
-   if (Hashes.find("MD5Sum") != NULL)
-      calcHashes |= MD5SUM;
-   if (Hashes.find("SHA1") != NULL)
-      calcHashes |= SHA1SUM;
-   if (Hashes.find("SHA256") != NULL)
-      calcHashes |= SHA256SUM;
-   if (Hashes.find("SHA512") != NULL)
-      calcHashes |= SHA512SUM;
-   d = new PrivateHashes(calcHashes);
-}
+Hashes::Hashes() : d(new PrivateHashes(~0)) { }
+Hashes::Hashes(unsigned int const Hashes) : d(new PrivateHashes(Hashes)) {}
+Hashes::Hashes(HashStringList const &Hashes) : d(new PrivateHashes(Hashes)) {}
 Hashes::~Hashes() { delete d; }
 APT_IGNORE_DEPRECATED_POP

+ 17 - 1
apt-pkg/contrib/hashes.h

@@ -87,6 +87,22 @@ class HashStringList
     */
    HashString const * find(char const * const type) const;
    HashString const * find(std::string const &type) const { return find(type.c_str()); }
+
+   /** finds the filesize hash and returns it as number
+    *
+    * @return beware: if the size isn't known we return \b 0 here,
+    * just like we would do for an empty file. If that is a problem
+    * for you have to get the size manually out of the list.
+    */
+   unsigned long long FileSize() const;
+
+   /** sets the filesize hash
+    *
+    * @param Size of the file
+    * @return @see #push_back
+    */
+   bool FileSize(unsigned long long const Size);
+
    /** check if the given hash type is supported
     *
     * @param type to check
@@ -166,7 +182,7 @@ class HashStringList
 class PrivateHashes;
 class Hashes
 {
-   PrivateHashes *d;
+   PrivateHashes * const d;
 
    public:
    /* those will disappear in the future as it is hard to add new ones this way.

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

@@ -87,7 +87,7 @@ class HashSumValue
          Sum[I] = S[I];
    }
 
-   HashSumValue(std::string Str)
+   explicit HashSumValue(std::string const &Str)
    {
          memset(Sum,0,sizeof(Sum));
          Set(Str);

+ 8 - 2
apt-pkg/contrib/macros.h

@@ -148,13 +148,19 @@
 	#define APT_IGNORE_DEPRECATED(XXX) XXX
 #endif
 
+#if __cplusplus >= 201103L
+	#define APT_OVERRIDE override
+#else
+	#define APT_OVERRIDE /* no c++11 standard */
+#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 15
+#define APT_PKG_MAJOR 5
+#define APT_PKG_MINOR 0
 #define APT_PKG_RELEASE 0
 #define APT_PKG_ABI ((APT_PKG_MAJOR * 100) + APT_PKG_MINOR)
 

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

@@ -48,7 +48,7 @@ class MD5Summation : public SummationImplementation
 
    public:
 
-   bool Add(const unsigned char *inbuf, unsigned long long inlen);
+   bool Add(const unsigned char *inbuf, unsigned long long inlen) APT_OVERRIDE;
    using SummationImplementation::Add;
 
    MD5SumValue Result();

+ 3 - 2
apt-pkg/contrib/progress.h

@@ -24,6 +24,7 @@
 
 #include <string>
 #include <sys/time.h>
+#include <apt-pkg/macros.h>
 
 #ifndef APT_8_CLEANER_HEADERS
 using std::string;
@@ -74,12 +75,12 @@ class OpTextProgress : public OpProgress
    bool NoUpdate;
    bool NoDisplay;
    unsigned long LastLen;
-   virtual void Update();
+   virtual void Update() APT_OVERRIDE;
    void Write(const char *S);
    
    public:
 
-   virtual void Done();
+   virtual void Done() APT_OVERRIDE;
    
    OpTextProgress(bool NoUpdate = false) : NoUpdate(NoUpdate), 
                 NoDisplay(false), LastLen(0) {};

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

@@ -37,7 +37,7 @@ class SHA1Summation : public SummationImplementation
    bool Done;
    
    public:
-   bool Add(const unsigned char *inbuf, unsigned long long inlen);
+   bool Add(const unsigned char *inbuf, unsigned long long inlen) APT_OVERRIDE;
    using SummationImplementation::Add;
 
    SHA1SumValue Result();

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

@@ -34,7 +34,7 @@ class SHA2SummationBase : public SummationImplementation
  protected:
    bool Done;
  public:
-   bool Add(const unsigned char *inbuf, unsigned long long len) = 0;
+   bool Add(const unsigned char *inbuf, unsigned long long len) APT_OVERRIDE = 0;
 
    void Result();
 };
@@ -45,7 +45,7 @@ class SHA256Summation : public SHA2SummationBase
    unsigned char Sum[32];
 
    public:
-   bool Add(const unsigned char *inbuf, unsigned long long len)
+   bool Add(const unsigned char *inbuf, unsigned long long len) APT_OVERRIDE
    {
       if (Done) 
          return false;
@@ -78,7 +78,7 @@ class SHA512Summation : public SHA2SummationBase
    unsigned char Sum[64];
 
    public:
-   bool Add(const unsigned char *inbuf, unsigned long long len)
+   bool Add(const unsigned char *inbuf, unsigned long long len) APT_OVERRIDE
    {
       if (Done) 
          return false;

+ 10 - 2
apt-pkg/contrib/sptr.h

@@ -22,7 +22,7 @@
 #define SMART_POINTER_H
 
 template <class T>
-class SPtr
+class APT_DEPRECATED SPtr
 {
    public:
    T *Ptr;
@@ -43,7 +43,7 @@ class SPtr
 };
 
 template <class T>
-class SPtrArray
+class APT_DEPRECATED SPtrArray
 {
    public:
    T *Ptr;
@@ -60,7 +60,15 @@ class SPtrArray
    
    inline SPtrArray(T *Ptr) : Ptr(Ptr) {};
    inline SPtrArray() : Ptr(0) {};
+#if __GNUC__ >= 4
+	#pragma GCC diagnostic push
+	#pragma GCC diagnostic ignored "-Wunsafe-loop-optimizations"
+	// gcc warns about this, but we can do nothing here…
+#endif
    inline ~SPtrArray() {delete [] Ptr;};
+#if __GNUC__ >= 4
+	#pragma GCC diagnostic pop
+#endif
 };
 
 #endif

+ 13 - 6
apt-pkg/contrib/strutl.cc

@@ -1308,7 +1308,7 @@ void ioprintf(ostream &out,const char *format,...)
    va_list args;
    ssize_t size = 400;
    while (true) {
-      bool ret = false;
+      bool ret;
       va_start(args,format);
       ret = iovprintf(out, format, args, size);
       va_end(args);
@@ -1322,7 +1322,7 @@ void strprintf(string &out,const char *format,...)
    ssize_t size = 400;
    std::ostringstream outstr;
    while (true) {
-      bool ret = false;
+      bool ret;
       va_start(args,format);
       ret = iovprintf(outstr, format, args, size);
       va_end(args);
@@ -1637,8 +1637,6 @@ URI::operator string()
 }
 									/*}}}*/
 // URI::SiteOnly - Return the schema and site for the URI		/*{{{*/
-// ---------------------------------------------------------------------
-/* */
 string URI::SiteOnly(const string &URI)
 {
    ::URI U(URI);
@@ -1648,9 +1646,18 @@ string URI::SiteOnly(const string &URI)
    return U;
 }
 									/*}}}*/
+// URI::ArchiveOnly - Return the schema, site and cleaned path for the URI /*{{{*/
+string URI::ArchiveOnly(const string &URI)
+{
+   ::URI U(URI);
+   U.User.clear();
+   U.Password.clear();
+   if (U.Path.empty() == false && U.Path[U.Path.length() - 1] == '/')
+      U.Path.erase(U.Path.length() - 1);
+   return U;
+}
+									/*}}}*/
 // URI::NoUserPassword - Return the schema, site and path for the URI	/*{{{*/
-// ---------------------------------------------------------------------
-/* */
 string URI::NoUserPassword(const string &URI)
 {
    ::URI U(URI);

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

@@ -167,6 +167,7 @@ class URI
    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 ArchiveOnly(const std::string &URI);
    static std::string NoUserPassword(const std::string &URI);
    
    URI(std::string Path) {CopyFrom(Path);}

+ 113 - 666
apt-pkg/deb/debindexfile.cc

@@ -16,56 +16,34 @@
 #include <apt-pkg/deblistparser.h>
 #include <apt-pkg/debrecords.h>
 #include <apt-pkg/configuration.h>
-#include <apt-pkg/progress.h>
 #include <apt-pkg/error.h>
-#include <apt-pkg/strutl.h>
-#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 <apt-pkg/sptr.h>
 
 #include <stdio.h>
 #include <iostream>
-#include <sstream>
 #include <string>
+#include <sstream>
+
 #include <sys/stat.h>
 									/*}}}*/
 
-using std::string;
-
-// SourcesIndex::debSourcesIndex - Constructor				/*{{{*/
-// ---------------------------------------------------------------------
-/* */
-debSourcesIndex::debSourcesIndex(string URI,string Dist,string Section,bool Trusted) :
-     pkgIndexFile(Trusted), URI(URI), Dist(Dist), Section(Section)
+// Sources Index							/*{{{*/
+debSourcesIndex::debSourcesIndex(IndexTarget const &Target,bool const Trusted) :
+     pkgDebianIndexTargetFile(Target, Trusted), d(NULL)
 {
 }
-									/*}}}*/
-// SourcesIndex::SourceInfo - Short 1 liner describing a source		/*{{{*/
-// ---------------------------------------------------------------------
-/* The result looks like:
-     http://foo/debian/ stable/main src 1.1.1 (dsc) */
-string debSourcesIndex::SourceInfo(pkgSrcRecords::Parser const &Record,
+std::string debSourcesIndex::SourceInfo(pkgSrcRecords::Parser const &Record,
 				   pkgSrcRecords::File const &File) const
 {
-   string Res;
-   Res = ::URI::NoUserPassword(URI) + ' ';
-   if (Dist[Dist.size() - 1] == '/')
-   {
-      if (Dist != "/")
-	 Res += Dist;
-   }      
-   else
-      Res += Dist + '/' + Section;
-   
+   // The result looks like: http://foo/debian/ stable/main src 1.1.1 (dsc)
+   std::string Res = Target.Description;
+   Res.erase(Target.Description.rfind(' '));
+
    Res += " ";
    Res += Record.Package();
    Res += " ";
@@ -74,622 +52,111 @@ string debSourcesIndex::SourceInfo(pkgSrcRecords::Parser const &Record,
       Res += " (" + File.Type + ")";
    return Res;
 }
-									/*}}}*/
-// SourcesIndex::CreateSrcParser - Get a parser for the source files	/*{{{*/
-// ---------------------------------------------------------------------
-/* */
 pkgSrcRecords::Parser *debSourcesIndex::CreateSrcParser() const
 {
-   string SourcesURI = _config->FindDir("Dir::State::lists") + 
-      URItoFileName(IndexURI("Sources"));
-
-   std::vector<std::string> types = APT::Configuration::getCompressionTypes();
-   for (std::vector<std::string>::const_iterator t = types.begin(); t != types.end(); ++t)
-   {
-      string p;
-      p = SourcesURI + '.' + *t;
-      if (FileExists(p))
-         return new debSrcRecordParser(p, this);
-   }
+   std::string const SourcesURI = IndexFileName();
    if (FileExists(SourcesURI))
       return new debSrcRecordParser(SourcesURI, this);
    return NULL;
 }
-									/*}}}*/
-// SourcesIndex::Describe - Give a descriptive path to the index	/*{{{*/
-// ---------------------------------------------------------------------
-/* */
-string debSourcesIndex::Describe(bool Short) const
-{
-   char S[300];
-   if (Short == true)
-      snprintf(S,sizeof(S),"%s",Info("Sources").c_str());
-   else
-      snprintf(S,sizeof(S),"%s (%s)",Info("Sources").c_str(),
-	       IndexFile("Sources").c_str());
-   
-   return S;
-}
-									/*}}}*/
-// SourcesIndex::Info - One liner describing the index URI		/*{{{*/
-// ---------------------------------------------------------------------
-/* */
-string debSourcesIndex::Info(const char *Type) const
+bool debSourcesIndex::OpenListFile(FileFd &, std::string const &)
 {
-   string Info = ::URI::NoUserPassword(URI) + ' ';
-   if (Dist[Dist.size() - 1] == '/')
-   {
-      if (Dist != "/")
-	 Info += Dist;
-   }
-   else
-      Info += Dist + '/' + Section;   
-   Info += " ";
-   Info += Type;
-   return Info;
+   return true;
 }
-									/*}}}*/
-// SourcesIndex::Index* - Return the URI to the index files		/*{{{*/
-// ---------------------------------------------------------------------
-/* */
-string debSourcesIndex::IndexFile(const char *Type) const
+pkgCacheListParser * debSourcesIndex::CreateListParser(FileFd &)
 {
-   string s = URItoFileName(IndexURI(Type));
-
-   std::vector<std::string> types = APT::Configuration::getCompressionTypes();
-   for (std::vector<std::string>::const_iterator t = types.begin(); t != types.end(); ++t)
-   {
-      string p = s + '.' + *t;
-      if (FileExists(p))
-         return p;
-   }
-   return s;
+   return NULL;
 }
-
-string debSourcesIndex::IndexURI(const char *Type) const
+uint8_t debSourcesIndex::GetIndexFlags() const
 {
-   string Res;
-   if (Dist[Dist.size() - 1] == '/')
-   {
-      if (Dist != "/")
-	 Res = URI + Dist;
-      else 
-	 Res = URI;
-   }
-   else
-      Res = URI + "dists/" + Dist + '/' + Section +
-      "/source/";
-   
-   Res += Type;
-   return Res;
+   return 0;
 }
 									/*}}}*/
-// SourcesIndex::Exists - Check if the index is available		/*{{{*/
-// ---------------------------------------------------------------------
-/* */
-bool debSourcesIndex::Exists() const
+// Packages Index							/*{{{*/
+debPackagesIndex::debPackagesIndex(IndexTarget const &Target, bool const Trusted) :
+                  pkgDebianIndexTargetFile(Target, Trusted), d(NULL)
 {
-   return FileExists(IndexFile("Sources"));
 }
-									/*}}}*/
-// SourcesIndex::Size - Return the size of the index			/*{{{*/
-// ---------------------------------------------------------------------
-/* */
-unsigned long debSourcesIndex::Size() const
+std::string debPackagesIndex::ArchiveInfo(pkgCache::VerIterator const &Ver) const
 {
-   unsigned long size = 0;
-
-   /* we need to ignore errors here; if the lists are absent, just return 0 */
-   _error->PushToStack();
-
-   FileFd f(IndexFile("Sources"), FileFd::ReadOnly, FileFd::Extension);
-   if (!f.Failed())
-      size = f.Size();
+   std::string Res = Target.Description;
+   Res.erase(Target.Description.rfind(' '));
 
-   if (_error->PendingError() == true)
-       size = 0;
-   _error->RevertToStack();
-
-   return size;
-}
-									/*}}}*/
-
-// PackagesIndex::debPackagesIndex - Contructor				/*{{{*/
-// ---------------------------------------------------------------------
-/* */
-debPackagesIndex::debPackagesIndex(string const &URI, string const &Dist, string const &Section,
-					bool const &Trusted, string const &Arch) :
-                  pkgIndexFile(Trusted), URI(URI), Dist(Dist), Section(Section), Architecture(Arch)
-{
-	if (Architecture == "native")
-		Architecture = _config->Find("APT::Architecture");
-}
-									/*}}}*/
-// PackagesIndex::ArchiveInfo - Short version of the archive url	/*{{{*/
-// ---------------------------------------------------------------------
-/* This is a shorter version that is designed to be < 60 chars or so */
-string debPackagesIndex::ArchiveInfo(pkgCache::VerIterator Ver) const
-{
-   string Res = ::URI::NoUserPassword(URI) + ' ';
-   if (Dist[Dist.size() - 1] == '/')
-   {
-      if (Dist != "/")
-	 Res += Dist;
-   }
-   else
-      Res += Dist + '/' + Section;
-   
    Res += " ";
    Res += Ver.ParentPkg().Name();
    Res += " ";
-   if (Dist[Dist.size() - 1] != '/')
+   std::string const Dist = Target.Option(IndexTarget::RELEASE);
+   if (Dist.empty() == false && Dist[Dist.size() - 1] != '/')
       Res.append(Ver.Arch()).append(" ");
    Res += Ver.VerStr();
    return Res;
 }
-									/*}}}*/
-// PackagesIndex::Describe - Give a descriptive path to the index	/*{{{*/
-// ---------------------------------------------------------------------
-/* This should help the user find the index in the sources.list and
-   in the filesystem for problem solving */
-string debPackagesIndex::Describe(bool Short) const
-{   
-   char S[300];
-   if (Short == true)
-      snprintf(S,sizeof(S),"%s",Info("Packages").c_str());
-   else
-      snprintf(S,sizeof(S),"%s (%s)",Info("Packages").c_str(),
-	       IndexFile("Packages").c_str());
-   return S;
-}
-									/*}}}*/
-// PackagesIndex::Info - One liner describing the index URI		/*{{{*/
-// ---------------------------------------------------------------------
-/* */
-string debPackagesIndex::Info(const char *Type) const 
+uint8_t debPackagesIndex::GetIndexFlags() const
 {
-   string Info = ::URI::NoUserPassword(URI) + ' ';
-   if (Dist[Dist.size() - 1] == '/')
-   {
-      if (Dist != "/")
-	 Info += Dist;
-   }
-   else
-      Info += Dist + '/' + Section;   
-   Info += " ";
-   if (Dist[Dist.size() - 1] != '/')
-      Info += Architecture + " ";
-   Info += Type;
-   return Info;
-}
-									/*}}}*/
-// PackagesIndex::Index* - Return the URI to the index files		/*{{{*/
-// ---------------------------------------------------------------------
-/* */
-string debPackagesIndex::IndexFile(const char *Type) const
-{
-   string s =_config->FindDir("Dir::State::lists") + URItoFileName(IndexURI(Type));
-
-   std::vector<std::string> types = APT::Configuration::getCompressionTypes();
-   for (std::vector<std::string>::const_iterator t = types.begin(); t != types.end(); ++t)
-   {
-      string p = s + '.' + *t;
-      if (FileExists(p))
-         return p;
-   }
-   return s;
-}
-string debPackagesIndex::IndexURI(const char *Type) const
-{
-   string Res;
-   if (Dist[Dist.size() - 1] == '/')
-   {
-      if (Dist != "/")
-	 Res = URI + Dist;
-      else 
-	 Res = URI;
-   }
-   else
-      Res = URI + "dists/" + Dist + '/' + Section +
-      "/binary-" + Architecture + '/';
-   
-   Res += Type;
-   return Res;
-}
-									/*}}}*/
-// PackagesIndex::Exists - Check if the index is available		/*{{{*/
-// ---------------------------------------------------------------------
-/* */
-bool debPackagesIndex::Exists() const
-{
-   return FileExists(IndexFile("Packages"));
-}
-									/*}}}*/
-// PackagesIndex::Size - Return the size of the index			/*{{{*/
-// ---------------------------------------------------------------------
-/* This is really only used for progress reporting. */
-unsigned long debPackagesIndex::Size() const
-{
-   unsigned long size = 0;
-
-   /* we need to ignore errors here; if the lists are absent, just return 0 */
-   _error->PushToStack();
-
-   FileFd f(IndexFile("Packages"), FileFd::ReadOnly, FileFd::Extension);
-   if (!f.Failed())
-      size = f.Size();
-
-   if (_error->PendingError() == true)
-       size = 0;
-   _error->RevertToStack();
-
-   return size;
-}
-									/*}}}*/
-// PackagesIndex::Merge - Load the index file into a cache		/*{{{*/
-// ---------------------------------------------------------------------
-/* */
-bool debPackagesIndex::Merge(pkgCacheGenerator &Gen,OpProgress *Prog) const
-{
-   string PackageFile = IndexFile("Packages");
-   FileFd Pkg(PackageFile,FileFd::ReadOnly, FileFd::Extension);
-   debListParser Parser(&Pkg, Architecture);
-
-   if (_error->PendingError() == true)
-      return _error->Error("Problem opening %s",PackageFile.c_str());
-   if (Prog != NULL)
-      Prog->SubProgress(0,Info("Packages"));
-   ::URI Tmp(URI);
-   if (Gen.SelectFile(PackageFile,Tmp.Host,*this) == false)
-      return _error->Error("Problem with SelectFile %s",PackageFile.c_str());
-
-   // Store the IMS information
-   pkgCache::PkgFileIterator File = Gen.GetCurFile();
-   pkgCacheGenerator::Dynamic<pkgCache::PkgFileIterator> DynFile(File);
-   File->Size = Pkg.FileSize();
-   File->mtime = Pkg.ModificationTime();
-   
-   if (Gen.MergeList(Parser) == false)
-      return _error->Error("Problem with MergeList %s",PackageFile.c_str());
-
-   // Check the release file
-   string ReleaseFile = debReleaseIndex(URI,Dist).MetaIndexFile("InRelease");
-   bool releaseExists = false;
-   if (FileExists(ReleaseFile) == true)
-      releaseExists = true;
-   else
-      ReleaseFile = debReleaseIndex(URI,Dist).MetaIndexFile("Release");
-
-   if (releaseExists == true || FileExists(ReleaseFile) == true)
-   {
-      FileFd Rel;
-      // Beware: The 'Release' file might be clearsigned in case the
-      // signature for an 'InRelease' file couldn't be checked
-      if (OpenMaybeClearSignedFile(ReleaseFile, Rel) == false)
-	 return false;
-
-      if (_error->PendingError() == true)
-	 return false;
-      Parser.LoadReleaseInfo(File,Rel,Section);
-   }
-   
-   return true;
-}
-									/*}}}*/
-// PackagesIndex::FindInCache - Find this index				/*{{{*/
-// ---------------------------------------------------------------------
-/* */
-pkgCache::PkgFileIterator debPackagesIndex::FindInCache(pkgCache &Cache) const
-{
-   string FileName = IndexFile("Packages");
-   pkgCache::PkgFileIterator File = Cache.FileBegin();
-   for (; File.end() == false; ++File)
-   {
-       if (File.FileName() == NULL || FileName != File.FileName())
-	 continue;
-      
-      struct stat St;
-      if (stat(File.FileName(),&St) != 0)
-      {
-         if (_config->FindB("Debug::pkgCacheGen", false))
-	    std::clog << "PackagesIndex::FindInCache - stat failed on " << File.FileName() << std::endl;
-	 return pkgCache::PkgFileIterator(Cache);
-      }
-      if ((unsigned)St.st_size != File->Size || St.st_mtime != File->mtime)
-      {
-         if (_config->FindB("Debug::pkgCacheGen", false))
-	    std::clog << "PackagesIndex::FindInCache - size (" << St.st_size << " <> " << File->Size
-			<< ") or mtime (" << St.st_mtime << " <> " << File->mtime
-			<< ") doesn't match for " << File.FileName() << std::endl;
-	 return pkgCache::PkgFileIterator(Cache);
-      }
-      return File;
-   }
-   
-   return File;
+   return 0;
 }
 									/*}}}*/
-
-// TranslationsIndex::debTranslationsIndex - Contructor			/*{{{*/
-// ---------------------------------------------------------------------
-/* */
-debTranslationsIndex::debTranslationsIndex(std::string const &URI, std::string const &Dist,
-						std::string const &Section, std::string const &Translation) :
-			pkgIndexFile(true), URI(URI), Dist(Dist), Section(Section),
-				Language(Translation)
+// Translation-* Index							/*{{{*/
+debTranslationsIndex::debTranslationsIndex(IndexTarget const &Target) :
+			pkgDebianIndexTargetFile(Target, true), d(NULL)
 {}
-									/*}}}*/
-// TranslationIndex::Trans* - Return the URI to the translation files	/*{{{*/
-// ---------------------------------------------------------------------
-/* */
-string debTranslationsIndex::IndexFile(const char *Type) const
+bool debTranslationsIndex::HasPackages() const
 {
-   string s =_config->FindDir("Dir::State::lists") + URItoFileName(IndexURI(Type));
-
-   std::vector<std::string> types = APT::Configuration::getCompressionTypes();
-   for (std::vector<std::string>::const_iterator t = types.begin(); t != types.end(); ++t)
-   {
-      string p = s + '.' + *t;
-      if (FileExists(p))
-         return p;
-   }
-   return s;
+   return Exists();
 }
-string debTranslationsIndex::IndexURI(const char *Type) const
+bool debTranslationsIndex::OpenListFile(FileFd &Pkg, std::string const &FileName)
 {
-   string Res;
-   if (Dist[Dist.size() - 1] == '/')
-   {
-      if (Dist != "/")
-	 Res = URI + Dist;
-      else 
-	 Res = URI;
-   }
-   else
-      Res = URI + "dists/" + Dist + '/' + Section +
-      "/i18n/Translation-";
-   
-   Res += Type;
-   return Res;
-}
-									/*}}}*/
-// TranslationsIndex::Describe - Give a descriptive path to the index	/*{{{*/
-// ---------------------------------------------------------------------
-/* This should help the user find the index in the sources.list and
-   in the filesystem for problem solving */
-string debTranslationsIndex::Describe(bool Short) const
-{
-   std::string S;
-   if (Short == true)
-      strprintf(S,"%s",Info(TranslationFile().c_str()).c_str());
-   else
-      strprintf(S,"%s (%s)",Info(TranslationFile().c_str()).c_str(),
-	       IndexFile(Language.c_str()).c_str());
-   return S;
-}
-									/*}}}*/
-// TranslationsIndex::Info - One liner describing the index URI		/*{{{*/
-// ---------------------------------------------------------------------
-/* */
-string debTranslationsIndex::Info(const char *Type) const 
-{
-   string Info = ::URI::NoUserPassword(URI) + ' ';
-   if (Dist[Dist.size() - 1] == '/')
-   {
-      if (Dist != "/")
-	 Info += Dist;
-   }
-   else
-      Info += Dist + '/' + Section;   
-   Info += " ";
-   Info += Type;
-   return Info;
+   if (FileExists(FileName))
+      return pkgDebianIndexTargetFile::OpenListFile(Pkg, FileName);
+   return true;
 }
-									/*}}}*/
-bool debTranslationsIndex::HasPackages() const				/*{{{*/
+uint8_t debTranslationsIndex::GetIndexFlags() const
 {
-   return FileExists(IndexFile(Language.c_str()));
+   return pkgCache::Flag::NotSource | pkgCache::Flag::NoPackages;
 }
-									/*}}}*/
-// TranslationsIndex::Exists - Check if the index is available		/*{{{*/
-// ---------------------------------------------------------------------
-/* */
-bool debTranslationsIndex::Exists() const
+std::string debTranslationsIndex::GetArchitecture() const
 {
-   return FileExists(IndexFile(Language.c_str()));
+   return std::string();
 }
-									/*}}}*/
-// TranslationsIndex::Size - Return the size of the index		/*{{{*/
-// ---------------------------------------------------------------------
-/* This is really only used for progress reporting. */
-unsigned long debTranslationsIndex::Size() const
+pkgCacheListParser * debTranslationsIndex::CreateListParser(FileFd &Pkg)
 {
-   unsigned long size = 0;
-
-   /* we need to ignore errors here; if the lists are absent, just return 0 */
+   if (Pkg.IsOpen() == false)
+      return NULL;
    _error->PushToStack();
-
-   FileFd f(IndexFile(Language.c_str()), FileFd::ReadOnly, FileFd::Extension);
-   if (!f.Failed())
-      size = f.Size();
-
-   if (_error->PendingError() == true)
-       size = 0;
-   _error->RevertToStack();
-
-   return size;
+   pkgCacheListParser * const Parser = new debTranslationsParser(&Pkg);
+   bool const newError = _error->PendingError();
+   _error->MergeWithStack();
+   return newError ? NULL : Parser;
 }
 									/*}}}*/
-// TranslationsIndex::Merge - Load the index file into a cache		/*{{{*/
-// ---------------------------------------------------------------------
-/* */
-bool debTranslationsIndex::Merge(pkgCacheGenerator &Gen,OpProgress *Prog) const
-{
-   // Check the translation file, if in use
-   string TranslationFile = IndexFile(Language.c_str());
-   if (FileExists(TranslationFile))
-   {
-     FileFd Trans(TranslationFile,FileFd::ReadOnly, FileFd::Extension);
-     debTranslationsParser TransParser(&Trans);
-     if (_error->PendingError() == true)
-       return false;
-     
-     if (Prog != NULL)
-	Prog->SubProgress(0, Info(TranslationFile.c_str()));
-     if (Gen.SelectFile(TranslationFile,string(),*this) == false)
-       return _error->Error("Problem with SelectFile %s",TranslationFile.c_str());
-
-     // Store the IMS information
-     pkgCache::PkgFileIterator TransFile = Gen.GetCurFile();
-     TransFile->Size = Trans.FileSize();
-     TransFile->mtime = Trans.ModificationTime();
-   
-     if (Gen.MergeList(TransParser) == false)
-       return _error->Error("Problem with MergeList %s",TranslationFile.c_str());
-   }
-
-   return true;
-}
-									/*}}}*/
-// TranslationsIndex::FindInCache - Find this index				/*{{{*/
-// ---------------------------------------------------------------------
-/* */
-pkgCache::PkgFileIterator debTranslationsIndex::FindInCache(pkgCache &Cache) const
+// dpkg/status Index							/*{{{*/
+debStatusIndex::debStatusIndex(std::string const &File) : pkgDebianIndexRealFile(File, true), d(NULL)
 {
-   string FileName = IndexFile(Language.c_str());
-   
-   pkgCache::PkgFileIterator File = Cache.FileBegin();
-   for (; File.end() == false; ++File)
-   {
-      if (FileName != File.FileName())
-	 continue;
-
-      struct stat St;
-      if (stat(File.FileName(),&St) != 0)
-      {
-         if (_config->FindB("Debug::pkgCacheGen", false))
-	    std::clog << "TranslationIndex::FindInCache - stat failed on " << File.FileName() << std::endl;
-	 return pkgCache::PkgFileIterator(Cache);
-      }
-      if ((unsigned)St.st_size != File->Size || St.st_mtime != File->mtime)
-      {
-         if (_config->FindB("Debug::pkgCacheGen", false))
-	    std::clog << "TranslationIndex::FindInCache - size (" << St.st_size << " <> " << File->Size
-			<< ") or mtime (" << St.st_mtime << " <> " << File->mtime
-			<< ") doesn't match for " << File.FileName() << std::endl;
-	 return pkgCache::PkgFileIterator(Cache);
-      }
-      return File;
-   }   
-   return File;
 }
-									/*}}}*/
-// StatusIndex::debStatusIndex - Constructor				/*{{{*/
-// ---------------------------------------------------------------------
-/* */
-debStatusIndex::debStatusIndex(string File) : pkgIndexFile(true), File(File)
+std::string debStatusIndex::GetArchitecture() const
 {
+   return std::string();
 }
-									/*}}}*/
-// StatusIndex::Size - Return the size of the index			/*{{{*/
-// ---------------------------------------------------------------------
-/* */
-unsigned long debStatusIndex::Size() const
-{
-   struct stat S;
-   if (stat(File.c_str(),&S) != 0)
-      return 0;
-   return S.st_size;
-}
-									/*}}}*/
-// StatusIndex::Merge - Load the index file into a cache		/*{{{*/
-// ---------------------------------------------------------------------
-/* */
-bool debStatusIndex::Merge(pkgCacheGenerator &Gen,OpProgress *Prog) const
-{
-   FileFd Pkg(File,FileFd::ReadOnly, FileFd::Extension);
-   if (_error->PendingError() == true)
-      return false;
-   debListParser Parser(&Pkg);
-   if (_error->PendingError() == true)
-      return false;
-
-   if (Prog != NULL)
-      Prog->SubProgress(0,File);
-   if (Gen.SelectFile(File,string(),*this,pkgCache::Flag::NotSource) == false)
-      return _error->Error("Problem with SelectFile %s",File.c_str());
-
-   // Store the IMS information
-   pkgCache::PkgFileIterator CFile = Gen.GetCurFile();
-   CFile->Size = Pkg.FileSize();
-   CFile->mtime = Pkg.ModificationTime();
-   map_stringitem_t const storage = Gen.StoreString(pkgCacheGenerator::MIXED, "now");
-   CFile->Archive = storage;
-   
-   if (Gen.MergeList(Parser) == false)
-      return _error->Error("Problem with MergeList %s",File.c_str());   
-   return true;
-}
-									/*}}}*/
-// StatusIndex::FindInCache - Find this index				/*{{{*/
-// ---------------------------------------------------------------------
-/* */
-pkgCache::PkgFileIterator debStatusIndex::FindInCache(pkgCache &Cache) const
+std::string debStatusIndex::GetComponent() const
 {
-   pkgCache::PkgFileIterator File = Cache.FileBegin();
-   for (; File.end() == false; ++File)
-   {
-      if (this->File != File.FileName())
-	 continue;
-      
-      struct stat St;
-      if (stat(File.FileName(),&St) != 0)
-      {
-         if (_config->FindB("Debug::pkgCacheGen", false))
-	    std::clog << "StatusIndex::FindInCache - stat failed on " << File.FileName() << std::endl;
-	 return pkgCache::PkgFileIterator(Cache);
-      }
-      if ((unsigned)St.st_size != File->Size || St.st_mtime != File->mtime)
-      {
-         if (_config->FindB("Debug::pkgCacheGen", false))
-	    std::clog << "StatusIndex::FindInCache - size (" << St.st_size << " <> " << File->Size
-			<< ") or mtime (" << St.st_mtime << " <> " << File->mtime
-			<< ") doesn't match for " << File.FileName() << std::endl;
-	 return pkgCache::PkgFileIterator(Cache);
-      }
-      return File;
-   }   
-   return File;
+   return "now";
 }
-									/*}}}*/
-// StatusIndex::Exists - Check if the index is available		/*{{{*/
-// ---------------------------------------------------------------------
-/* */
-APT_CONST bool debStatusIndex::Exists() const
+uint8_t debStatusIndex::GetIndexFlags() const
 {
-   // Abort if the file does not exist.
-   return true;
+   return pkgCache::Flag::NotSource;
 }
 									/*}}}*/
-
-// debDebPkgFile - Single .deb file					/*{{{*/
-debDebPkgFileIndex::debDebPkgFileIndex(std::string DebFile)
-   : pkgIndexFile(true), DebFile(DebFile)
-{
-   DebFileFullPath = flAbsPath(DebFile);
-}
-
-std::string debDebPkgFileIndex::ArchiveURI(std::string /*File*/) const
-{
-   return "file:" + DebFileFullPath;
-}
-
-bool debDebPkgFileIndex::Exists() const
+// DebPkgFile Index - a single .deb file as an index			/*{{{*/
+debDebPkgFileIndex::debDebPkgFileIndex(std::string const &DebFile)
+   : pkgDebianIndexRealFile(DebFile, true), d(NULL), DebFile(DebFile)
 {
-   return FileExists(DebFile);
 }
 bool debDebPkgFileIndex::GetContent(std::ostream &content, std::string const &debfile)
 {
+   struct stat Buf;
+   if (stat(debfile.c_str(), &Buf) != 0)
+      return false;
+
    // get the control data out of the deb file via dpkg-deb -I
    std::string dpkg = _config->Find("Dir::Bin::dpkg","dpkg-deb");
    std::vector<const char *> Args;
@@ -716,106 +183,86 @@ bool debDebPkgFileIndex::GetContent(std::ostream &content, std::string const &de
    ExecWait(Child, "Popen");
 
    content << "Filename: " << debfile << "\n";
-   struct stat Buf;
-   if (stat(debfile.c_str(), &Buf) != 0)
-      return false;
    content << "Size: " << Buf.st_size << "\n";
 
    return true;
 }
-bool debDebPkgFileIndex::Merge(pkgCacheGenerator& Gen, OpProgress* Prog) const
+bool debDebPkgFileIndex::OpenListFile(FileFd &Pkg, std::string const &FileName)
 {
-   if(Prog)
-      Prog->SubProgress(0, "Reading deb file");
-
    // write the control data to a tempfile
-   SPtr<FileFd> DebControl = GetTempFile("deb-file-" + flNotDir(DebFile));
-   if(DebControl == NULL)
+   if (GetTempFile("deb-file-" + flNotDir(FileName), true, &Pkg) == NULL)
       return false;
    std::ostringstream content;
-   if (GetContent(content, DebFile) == false)
+   if (GetContent(content, FileName) == false)
       return false;
    std::string const contentstr = content.str();
-   DebControl->Write(contentstr.c_str(), contentstr.length());
-   // rewind for the listparser
-   DebControl->Seek(0);
-
-   // and give it to the list parser
-   debDebFileParser Parser(DebControl, DebFile);
-   if(Gen.SelectFile(DebFile, "local", *this) == false)
-      return _error->Error("Problem with SelectFile %s", DebFile.c_str());
-
-   pkgCache::PkgFileIterator File = Gen.GetCurFile();
-   File->Size = DebControl->Size();
-   File->mtime = DebControl->ModificationTime();
-   
-   if (Gen.MergeList(Parser) == false)
-      return _error->Error("Problem with MergeLister for %s", DebFile.c_str());
-
+   if (contentstr.empty())
+      return true;
+   if (Pkg.Write(contentstr.c_str(), contentstr.length()) == false || Pkg.Seek(0) == false)
+      return false;
    return true;
 }
+pkgCacheListParser * debDebPkgFileIndex::CreateListParser(FileFd &Pkg)
+{
+   if (Pkg.IsOpen() == false)
+      return NULL;
+   _error->PushToStack();
+   pkgCacheListParser * const Parser = new debDebFileParser(&Pkg, DebFile);
+   bool const newError = _error->PendingError();
+   _error->MergeWithStack();
+   return newError ? NULL : Parser;
+}
+uint8_t debDebPkgFileIndex::GetIndexFlags() const
+{
+   return pkgCache::Flag::LocalSource;
+}
+std::string debDebPkgFileIndex::GetArchitecture() const
+{
+   return std::string();
+}
+std::string debDebPkgFileIndex::GetComponent() const
+{
+   return "local-deb";
+}
 pkgCache::PkgFileIterator debDebPkgFileIndex::FindInCache(pkgCache &Cache) const
 {
+   std::string const FileName = IndexFileName();
    pkgCache::PkgFileIterator File = Cache.FileBegin();
    for (; File.end() == false; ++File)
    {
-       if (File.FileName() == NULL || DebFile != File.FileName())
+       if (File.FileName() == NULL || FileName != File.FileName())
 	 continue;
-
-       return File;
+      // we can't do size checks here as file size != content size
+      return File;
    }
-   
-   return File;
-}
-unsigned long debDebPkgFileIndex::Size() const
-{
-   struct stat buf;
-   if(stat(DebFile.c_str(), &buf) != 0)
-      return 0;
-   return buf.st_size;
-}
-									/*}}}*/
 
-// debDscFileIndex stuff
-debDscFileIndex::debDscFileIndex(std::string &DscFile) 
-   : pkgIndexFile(true), DscFile(DscFile)
-{
-}
-
-bool debDscFileIndex::Exists() const
-{
-   return FileExists(DscFile);
+   return File;
 }
 
-unsigned long debDscFileIndex::Size() const
+									/*}}}*/
+// DscFile Index - a single .dsc file as an index			/*{{{*/
+debDscFileIndex::debDscFileIndex(std::string const &DscFile)
+   : pkgDebianIndexRealFile(DscFile, true), d(NULL)
 {
-   struct stat buf;
-   if(stat(DscFile.c_str(), &buf) == 0)
-      return buf.st_size;
-   return 0;
 }
-
-// DscFileIndex::CreateSrcParser - Get a parser for the .dsc file	/*{{{*/
 pkgSrcRecords::Parser *debDscFileIndex::CreateSrcParser() const
 {
-   if (!FileExists(DscFile))
+   if (Exists() == false)
       return NULL;
-
-   return new debDscRecordParser(DscFile,this);
+   return new debDscRecordParser(File, this);
 }
 									/*}}}*/
+
 // Index File types for Debian						/*{{{*/
 class APT_HIDDEN debIFTypeSrc : public pkgIndexFile::Type
 {
    public:
-   
    debIFTypeSrc() {Label = "Debian Source Index";};
 };
 class APT_HIDDEN debIFTypePkg : public pkgIndexFile::Type
 {
    public:
-   
-   virtual pkgRecords::Parser *CreatePkgParser(pkgCache::PkgFileIterator File) const 
+   virtual pkgRecords::Parser *CreatePkgParser(pkgCache::PkgFileIterator const &File) const APT_OVERRIDE
    {
       return new debRecordParser(File.FileName(),*File.Cache());
    };
@@ -829,8 +276,7 @@ class APT_HIDDEN debIFTypeTrans : public debIFTypePkg
 class APT_HIDDEN debIFTypeStatus : public pkgIndexFile::Type
 {
    public:
-   
-   virtual pkgRecords::Parser *CreatePkgParser(pkgCache::PkgFileIterator File) const 
+   virtual pkgRecords::Parser *CreatePkgParser(pkgCache::PkgFileIterator const &File) const APT_OVERRIDE
    {
       return new debRecordParser(File.FileName(),*File.Cache());
    };
@@ -839,29 +285,29 @@ class APT_HIDDEN debIFTypeStatus : public pkgIndexFile::Type
 class APT_HIDDEN debIFTypeDebPkgFile : public pkgIndexFile::Type
 {
    public:
-   virtual pkgRecords::Parser *CreatePkgParser(pkgCache::PkgFileIterator File) const 
+   virtual pkgRecords::Parser *CreatePkgParser(pkgCache::PkgFileIterator const &File) const APT_OVERRIDE
    {
       return new debDebFileRecordParser(File.FileName());
    };
-   debIFTypeDebPkgFile() {Label = "deb Package file";};
+   debIFTypeDebPkgFile() {Label = "Debian deb file";};
 };
 class APT_HIDDEN debIFTypeDscFile : public pkgIndexFile::Type
 {
    public:
-   virtual pkgSrcRecords::Parser *CreateSrcPkgParser(std::string DscFile) const
+   virtual pkgSrcRecords::Parser *CreateSrcPkgParser(std::string const &DscFile) const APT_OVERRIDE
    {
       return new debDscRecordParser(DscFile, NULL);
    };
-   debIFTypeDscFile() {Label = "dsc File Source Index";};
+   debIFTypeDscFile() {Label = "Debian dsc file";};
 };
 class APT_HIDDEN debIFTypeDebianSourceDir : public pkgIndexFile::Type
 {
    public:
-   virtual pkgSrcRecords::Parser *CreateSrcPkgParser(std::string SourceDir) const
+   virtual pkgSrcRecords::Parser *CreateSrcPkgParser(std::string const &SourceDir) const APT_OVERRIDE
    {
-      return new debDscRecordParser(SourceDir + string("/debian/control"), NULL);
+      return new debDscRecordParser(SourceDir + std::string("/debian/control"), NULL);
    };
-   debIFTypeDebianSourceDir() {Label = "debian/control File Source Index";};
+   debIFTypeDebianSourceDir() {Label = "Debian control file";};
 };
 
 APT_HIDDEN debIFTypeSrc _apt_Src;
@@ -909,3 +355,4 @@ debTranslationsIndex::~debTranslationsIndex() {}
 debSourcesIndex::~debSourcesIndex() {}
 
 debDebPkgFileIndex::~debDebPkgFileIndex() {}
+debDscFileIndex::~debDscFileIndex() {}

+ 71 - 134
apt-pkg/deb/debindexfile.h

@@ -1,6 +1,5 @@
 // -*- mode: cpp; mode: fold -*-
 // Description								/*{{{*/
-// $Id: debindexfile.h,v 1.3.2.1 2003/12/24 23:09:17 mdz Exp $
 /* ######################################################################
 
    Debian Index Files
@@ -27,155 +26,105 @@ class OpProgress;
 class pkgAcquire;
 class pkgCacheGenerator;
 
-
-class APT_HIDDEN debStatusIndex : public pkgIndexFile
+class debStatusIndex : public pkgDebianIndexRealFile
 {
-   /** \brief dpointer placeholder (for later in case we need it) */
-   void *d;
+   void * const d;
+protected:
+   virtual std::string GetArchitecture() const APT_OVERRIDE;
+   virtual std::string GetComponent() const APT_OVERRIDE;
+   virtual uint8_t GetIndexFlags() const APT_OVERRIDE;
 
-   protected:
-   std::string File;
+public:
 
-   public:
+   virtual const Type *GetType() const APT_OVERRIDE APT_CONST;
 
-   virtual const Type *GetType() const APT_CONST;
-   
-   // Interface for acquire
-   virtual std::string Describe(bool /*Short*/) const {return File;};
-   
    // Interface for the Cache Generator
-   virtual bool Exists() const;
-   virtual bool HasPackages() const {return true;};
-   virtual unsigned long Size() const;
-   virtual bool Merge(pkgCacheGenerator &Gen,OpProgress *Prog) const;
-   bool Merge(pkgCacheGenerator &Gen,OpProgress *Prog, unsigned long const Flag) const;
-   virtual pkgCache::PkgFileIterator FindInCache(pkgCache &Cache) const;
-
-   debStatusIndex(std::string File);
+   virtual bool HasPackages() const APT_OVERRIDE {return true;};
+   // Abort if the file does not exist.
+   virtual bool Exists() const APT_OVERRIDE {return true;};
+
+   debStatusIndex(std::string const &File);
    virtual ~debStatusIndex();
 };
-    
-class APT_HIDDEN debPackagesIndex : public pkgIndexFile
-{
-   /** \brief dpointer placeholder (for later in case we need it) */
-   void *d;
-
-   std::string URI;
-   std::string Dist;
-   std::string Section;
-   std::string Architecture;
 
-   APT_HIDDEN std::string Info(const char *Type) const;
-   APT_HIDDEN std::string IndexFile(const char *Type) const;
-   APT_HIDDEN std::string IndexURI(const char *Type) const;
+class debPackagesIndex : public pkgDebianIndexTargetFile
+{
+   void * const d;
+protected:
+   virtual uint8_t GetIndexFlags() const APT_OVERRIDE;
 
-   public:
-   
-   virtual const Type *GetType() const APT_CONST;
+public:
+   virtual const Type *GetType() const APT_OVERRIDE APT_CONST;
 
    // Stuff for accessing files on remote items
-   virtual std::string ArchiveInfo(pkgCache::VerIterator Ver) const;
-   virtual std::string ArchiveURI(std::string File) const {return URI + File;};
-   
-   // Interface for acquire
-   virtual std::string Describe(bool Short) const;   
-   
+   virtual std::string ArchiveInfo(pkgCache::VerIterator const &Ver) const APT_OVERRIDE;
+
    // Interface for the Cache Generator
-   virtual bool Exists() const;
-   virtual bool HasPackages() const {return true;};
-   virtual unsigned long Size() const;
-   virtual bool Merge(pkgCacheGenerator &Gen,OpProgress *Prog) const;
-   virtual pkgCache::PkgFileIterator FindInCache(pkgCache &Cache) const;
-
-   debPackagesIndex(std::string const &URI, std::string const &Dist, std::string const &Section,
-			bool const &Trusted, std::string const &Arch = "native");
+   virtual bool HasPackages() const APT_OVERRIDE {return true;};
+
+   debPackagesIndex(IndexTarget const &Target, bool const Trusted);
    virtual ~debPackagesIndex();
 };
 
-class APT_HIDDEN debTranslationsIndex : public pkgIndexFile
+class debTranslationsIndex : public pkgDebianIndexTargetFile
 {
-   /** \brief dpointer placeholder (for later in case we need it) */
-   void *d;
+   void * const d;
+protected:
+   virtual std::string GetArchitecture() const APT_OVERRIDE;
+   virtual uint8_t GetIndexFlags() const APT_OVERRIDE;
+   virtual bool OpenListFile(FileFd &Pkg, std::string const &FileName) APT_OVERRIDE;
+   APT_HIDDEN virtual pkgCacheListParser * CreateListParser(FileFd &Pkg) APT_OVERRIDE;
 
-   std::string const URI;
-   std::string const Dist;
-   std::string const Section;
-   std::string const Language;
+public:
 
-   APT_HIDDEN std::string Info(const char *Type) const;
-   APT_HIDDEN std::string IndexFile(const char *Type) const;
-   APT_HIDDEN std::string IndexURI(const char *Type) const;
-
-   APT_HIDDEN std::string TranslationFile() const {return std::string("Translation-").append(Language);};
-
-   public:
-
-   virtual const Type *GetType() const APT_CONST;
-
-   // Interface for acquire
-   virtual std::string Describe(bool Short) const;
+   virtual const Type *GetType() const APT_OVERRIDE APT_CONST;
 
    // Interface for the Cache Generator
-   virtual bool Exists() const;
-   virtual bool HasPackages() const;
-   virtual unsigned long Size() const;
-   virtual bool Merge(pkgCacheGenerator &Gen,OpProgress *Prog) const;
-   virtual pkgCache::PkgFileIterator FindInCache(pkgCache &Cache) const;
+   virtual bool HasPackages() const APT_OVERRIDE;
 
-   debTranslationsIndex(std::string const &URI,std::string const &Dist,std::string const &Section, std::string const &Language);
+   debTranslationsIndex(IndexTarget const &Target);
    virtual ~debTranslationsIndex();
 };
 
-class APT_HIDDEN debSourcesIndex : public pkgIndexFile
+class debSourcesIndex : public pkgDebianIndexTargetFile
 {
-   /** \brief dpointer placeholder (for later in case we need it) */
-   void *d;
-
-   std::string URI;
-   std::string Dist;
-   std::string Section;
-
-   APT_HIDDEN std::string Info(const char *Type) const;
-   APT_HIDDEN std::string IndexFile(const char *Type) const;
-   APT_HIDDEN std::string IndexURI(const char *Type) const;
+   void * const d;
+   virtual uint8_t GetIndexFlags() const APT_OVERRIDE;
+   virtual bool OpenListFile(FileFd &Pkg, std::string const &FileName) APT_OVERRIDE;
+   APT_HIDDEN virtual pkgCacheListParser * CreateListParser(FileFd &Pkg) APT_OVERRIDE;
 
    public:
 
-   virtual const Type *GetType() const APT_CONST;
+   virtual const Type *GetType() const APT_OVERRIDE APT_CONST;
 
    // Stuff for accessing files on remote items
    virtual std::string SourceInfo(pkgSrcRecords::Parser const &Record,
-			     pkgSrcRecords::File const &File) const;
-   virtual std::string ArchiveURI(std::string File) const {return URI + File;};
-   
-   // Interface for acquire
-   virtual std::string Describe(bool Short) const;   
+			     pkgSrcRecords::File const &File) const APT_OVERRIDE;
 
    // Interface for the record parsers
-   virtual pkgSrcRecords::Parser *CreateSrcParser() const;
-   
+   virtual pkgSrcRecords::Parser *CreateSrcParser() const APT_OVERRIDE;
+
    // Interface for the Cache Generator
-   virtual bool Exists() const;
-   virtual bool HasPackages() const {return false;};
-   virtual unsigned long Size() const;
-   
-   debSourcesIndex(std::string URI,std::string Dist,std::string Section,bool Trusted);
+   virtual bool HasPackages() const APT_OVERRIDE {return false;};
+
+   debSourcesIndex(IndexTarget const &Target, bool const Trusted);
    virtual ~debSourcesIndex();
 };
 
-class APT_HIDDEN debDebPkgFileIndex : public pkgIndexFile
+class debDebPkgFileIndex : public pkgDebianIndexRealFile
 {
- private:
-   void *d;
+   void * const d;
    std::string DebFile;
-   std::string DebFileFullPath;
 
- public:
-   virtual const Type *GetType() const APT_CONST;
+protected:
+   virtual std::string GetComponent() const APT_OVERRIDE;
+   virtual std::string GetArchitecture() const APT_OVERRIDE;
+   virtual uint8_t GetIndexFlags() const APT_OVERRIDE;
+   virtual bool OpenListFile(FileFd &Pkg, std::string const &FileName) APT_OVERRIDE;
+   APT_HIDDEN virtual pkgCacheListParser * CreateListParser(FileFd &Pkg) APT_OVERRIDE;
 
-   virtual std::string Describe(bool /*Short*/) const {
-      return DebFile;
-   }
+public:
+   virtual const Type *GetType() const APT_OVERRIDE APT_CONST;
 
    /** get the control (file) content of the deb file
     *
@@ -186,43 +135,31 @@ class APT_HIDDEN debDebPkgFileIndex : public pkgIndexFile
    static bool GetContent(std::ostream &content, std::string const &debfile);
 
    // Interface for the Cache Generator
-   virtual bool Exists() const;
-   virtual bool HasPackages() const {
-      return true;
-   };
-   virtual unsigned long Size() const;
-   virtual bool Merge(pkgCacheGenerator &Gen,OpProgress *Prog) const;
-   virtual pkgCache::PkgFileIterator FindInCache(pkgCache &Cache) const;
+   virtual bool HasPackages() const APT_OVERRIDE {return true;}
+   virtual pkgCache::PkgFileIterator FindInCache(pkgCache &Cache) const APT_OVERRIDE;
 
    // Interface for acquire
-   virtual std::string ArchiveURI(std::string /*File*/) const;
 
-   debDebPkgFileIndex(std::string DebFile);
+   debDebPkgFileIndex(std::string const &DebFile);
    virtual ~debDebPkgFileIndex();
 };
 
-class APT_HIDDEN debDscFileIndex : public pkgIndexFile
+class debDscFileIndex : public pkgDebianIndexRealFile
 {
- private:
-   std::string DscFile;
+   void * const d;
  public:
-   virtual const Type *GetType() const APT_CONST;
-   virtual pkgSrcRecords::Parser *CreateSrcParser() const;
-   virtual bool Exists() const;
-   virtual bool HasPackages() const {return false;};
-   virtual unsigned long Size() const;
-   virtual std::string Describe(bool /*Short*/) const {
-      return DscFile;
-   };
-
-   debDscFileIndex(std::string &DscFile);
-   virtual ~debDscFileIndex() {};
+   virtual const Type *GetType() const APT_OVERRIDE APT_CONST;
+   virtual pkgSrcRecords::Parser *CreateSrcParser() const APT_OVERRIDE;
+   virtual bool HasPackages() const APT_OVERRIDE {return false;};
+
+   debDscFileIndex(std::string const &DscFile);
+   virtual ~debDscFileIndex();
 };
 
-class APT_HIDDEN debDebianSourceDirIndex : public debDscFileIndex
+class debDebianSourceDirIndex : public debDscFileIndex
 {
  public:
-   virtual const Type *GetType() const APT_CONST;
+   virtual const Type *GetType() const APT_OVERRIDE APT_CONST;
 };
 
 #endif

+ 28 - 134
apt-pkg/deb/deblistparser.cc

@@ -18,10 +18,8 @@
 #include <apt-pkg/cachefilter.h>
 #include <apt-pkg/aptconfiguration.h>
 #include <apt-pkg/strutl.h>
-#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>
@@ -50,12 +48,9 @@ static debListParser::WordList PrioList[] = {
 /* Provide an architecture and only this one and "all" will be accepted
    in Step(), if no Architecture is given we will accept every arch
    we would accept in general with checkArchitecture() */
-debListParser::debListParser(FileFd *File, string const &Arch) : Tags(File),
-				Arch(Arch) {
-   if (Arch == "native")
-      this->Arch = _config->Find("APT::Architecture");
-   Architectures = APT::Configuration::getArchitectures();
-   MultiArchEnabled = Architectures.size() > 1;
+debListParser::debListParser(FileFd *File) :
+   pkgCacheListParser(), d(NULL), Tags(File)
+{
 }
 									/*}}}*/
 // ListParser::Package - Return the package name			/*{{{*/
@@ -72,7 +67,8 @@ string debListParser::Package() {
 // ---------------------------------------------------------------------
 /* This will return the Architecture of the package this section describes */
 string debListParser::Architecture() {
-   return Section.FindS("Architecture");
+   std::string const Arch = Section.FindS("Architecture");
+   return Arch.empty() ? "none" : Arch;
 }
 									/*}}}*/
 // ListParser::ArchitectureAll						/*{{{*/
@@ -97,14 +93,14 @@ unsigned char debListParser::ParseMultiArch(bool const showErrors)	/*{{{*/
    unsigned char MA;
    string const MultiArch = Section.FindS("Multi-Arch");
    if (MultiArch.empty() == true || MultiArch == "no")
-      MA = pkgCache::Version::None;
+      MA = pkgCache::Version::No;
    else if (MultiArch == "same") {
       if (ArchitectureAll() == true)
       {
 	 if (showErrors == true)
 	    _error->Warning("Architecture: all package '%s' can't be Multi-Arch: same",
 		  Section.FindS("Package").c_str());
-	 MA = pkgCache::Version::None;
+	 MA = pkgCache::Version::No;
       }
       else
 	 MA = pkgCache::Version::Same;
@@ -118,7 +114,7 @@ unsigned char debListParser::ParseMultiArch(bool const showErrors)	/*{{{*/
       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;
+      MA = pkgCache::Version::No;
    }
 
    if (ArchitectureAll() == true)
@@ -141,7 +137,6 @@ bool debListParser::NewVersion(pkgCache::VerIterator &Ver)
       map_stringitem_t const idx = StoreString(pkgCacheGenerator::SECTION, Start, Stop - Start);
       Ver->Section = idx;
    }
-#if APT_PKG_ABI >= 413
    // Parse the source package name
    pkgCache::GrpIterator const G = Ver.ParentPkg().Group();
    Ver->SourcePkgName = G->Name;
@@ -193,7 +188,6 @@ bool debListParser::NewVersion(pkgCache::VerIterator &Ver)
 	 }
       }
    }
-#endif
 
    Ver->MultiArch = ParseMultiArch(true);
    // Archive Size
@@ -209,23 +203,22 @@ bool debListParser::NewVersion(pkgCache::VerIterator &Ver)
 	 Ver->Priority = pkgCache::State::Extra;
    }
 
-   if (ParseDepends(Ver,"Depends",pkgCache::Dep::Depends) == false)
-      return false;
    if (ParseDepends(Ver,"Pre-Depends",pkgCache::Dep::PreDepends) == false)
       return false;
-   if (ParseDepends(Ver,"Suggests",pkgCache::Dep::Suggests) == false)
-      return false;
-   if (ParseDepends(Ver,"Recommends",pkgCache::Dep::Recommends) == false)
+   if (ParseDepends(Ver,"Depends",pkgCache::Dep::Depends) == false)
       return false;
    if (ParseDepends(Ver,"Conflicts",pkgCache::Dep::Conflicts) == false)
       return false;
    if (ParseDepends(Ver,"Breaks",pkgCache::Dep::DpkgBreaks) == false)
       return false;
+   if (ParseDepends(Ver,"Recommends",pkgCache::Dep::Recommends) == false)
+      return false;
+   if (ParseDepends(Ver,"Suggests",pkgCache::Dep::Suggests) == false)
+      return false;
    if (ParseDepends(Ver,"Replaces",pkgCache::Dep::Replaces) == false)
       return false;
    if (ParseDepends(Ver,"Enhances",pkgCache::Dep::Enhances) == false)
       return false;
-
    // Obsolete.
    if (ParseDepends(Ver,"Optional",pkgCache::Dep::Suggests) == false)
       return false;
@@ -793,43 +786,23 @@ bool debListParser::ParseDepends(pkgCache::VerIterator &Ver,
 	 return _error->Error("Problem parsing dependency %s",Tag);
       size_t const found = Package.rfind(':');
 
-      // If negative is unspecific it needs to apply on all architectures
-      if (MultiArchEnabled == true && found == string::npos &&
-	  (Type == pkgCache::Dep::Conflicts ||
-	   Type == pkgCache::Dep::DpkgBreaks ||
-	   Type == pkgCache::Dep::Replaces))
+      if (found == string::npos || strcmp(Package.c_str() + found, ":any") == 0)
       {
-	 for (std::vector<std::string>::const_iterator a = Architectures.begin();
-	      a != Architectures.end(); ++a)
-	    if (NewDepends(Ver,Package,*a,Version,Op,Type) == false)
-	       return false;
-	 if (NewDepends(Ver,Package,"none",Version,Op,Type) == false)
+	 if (NewDepends(Ver,Package,pkgArch,Version,Op,Type) == false)
 	    return false;
       }
-      else if (found != string::npos &&
-	       strcmp(Package.c_str() + found, ":any") != 0)
+      else
       {
 	 string Arch = Package.substr(found+1, string::npos);
 	 Package = Package.substr(0, found);
 	 // Such dependencies are not supposed to be accepted …
-	 // … but this is probably the best thing to do.
+	 // … but this is probably the best thing to do anyway
 	 if (Arch == "native")
 	    Arch = _config->Find("APT::Architecture");
-	 if (NewDepends(Ver,Package,Arch,Version,Op,Type) == false)
-	    return false;
-      }
-      else
-      {
-	 if (NewDepends(Ver,Package,pkgArch,Version,Op,Type) == false)
-	    return false;
-	 if ((Type == pkgCache::Dep::Conflicts ||
-	      Type == pkgCache::Dep::DpkgBreaks ||
-	      Type == pkgCache::Dep::Replaces) &&
-	     NewDepends(Ver, Package,
-			(pkgArch != "none") ? "none" : _config->Find("APT::Architecture"),
-			Version,Op,Type) == false)
+	 if (NewDepends(Ver,Package,Arch,Version,Op | pkgCache::Dep::ArchSpecific,Type) == false)
 	    return false;
       }
+
       if (Start == Stop)
 	 break;
    }
@@ -861,13 +834,13 @@ bool debListParser::ParseProvides(pkgCache::VerIterator &Ver)
 	 } else if (archfound != string::npos) {
 	    string OtherArch = Package.substr(archfound+1, string::npos);
 	    Package = Package.substr(0, archfound);
-	    if (NewProvides(Ver, Package, OtherArch, Version) == false)
+	    if (NewProvides(Ver, Package, OtherArch, Version, pkgCache::Flag::ArchSpecific) == false)
 	       return false;
 	 } else if ((Ver->MultiArch & pkgCache::Version::Foreign) == pkgCache::Version::Foreign) {
-	    if (NewProvidesAllArch(Ver, Package, Version) == false)
+	    if (NewProvidesAllArch(Ver, Package, Version, 0) == false)
 	       return false;
 	 } else {
-	    if (NewProvides(Ver, Package, Arch, Version) == false)
+	    if (NewProvides(Ver, Package, Arch, Version, 0) == false)
 	       return false;
 	 }
 
@@ -879,26 +852,14 @@ bool debListParser::ParseProvides(pkgCache::VerIterator &Ver)
    if ((Ver->MultiArch & pkgCache::Version::Allowed) == pkgCache::Version::Allowed)
    {
       string const Package = string(Ver.ParentPkg().Name()).append(":").append("any");
-      return NewProvidesAllArch(Ver, Package, Ver.VerStr());
+      return NewProvidesAllArch(Ver, Package, Ver.VerStr(), pkgCache::Flag::MultiArchImplicit);
    }
    else if ((Ver->MultiArch & pkgCache::Version::Foreign) == pkgCache::Version::Foreign)
-      return NewProvidesAllArch(Ver, Ver.ParentPkg().Name(), Ver.VerStr());
+      return NewProvidesAllArch(Ver, Ver.ParentPkg().Name(), Ver.VerStr(), pkgCache::Flag::MultiArchImplicit);
 
    return true;
 }
 									/*}}}*/
-// ListParser::NewProvides - add provides for all architectures		/*{{{*/
-bool debListParser::NewProvidesAllArch(pkgCache::VerIterator &Ver, string const &Package,
-				string const &Version) {
-   for (std::vector<string>::const_iterator a = Architectures.begin();
-	a != Architectures.end(); ++a)
-   {
-      if (NewProvides(Ver, Package, *a, Version) == false)
-	 return false;
-   }
-   return true;
-}
-									/*}}}*/
 // ListParser::GrabWord - Matches a word and returns			/*{{{*/
 // ---------------------------------------------------------------------
 /* Looks for a word in a list of words - for ParseStatus */
@@ -921,71 +882,7 @@ bool debListParser::GrabWord(string Word,WordList *List,unsigned char &Out)
 bool debListParser::Step()
 {
    iOffset = Tags.Offset();
-   while (Tags.Step(Section) == true)
-   {      
-      /* See if this is the correct Architecture, if it isn't then we
-         drop the whole section. A missing arch tag only happens (in theory)
-         inside the Status file, so that is a positive return */
-      string const Architecture = Section.FindS("Architecture");
-
-      if (Arch.empty() == true || Arch == "any" || MultiArchEnabled == false)
-      {
-	 if (APT::Configuration::checkArchitecture(Architecture) == true)
-	    return true;
-	 /* parse version stanzas without an architecture only in the status file
-	    (and as misfortune bycatch flat-archives) */
-	 if ((Arch.empty() == true || Arch == "any") && Architecture.empty() == true)
-	    return true;
-      }
-      else
-      {
-	 if (Architecture == Arch)
-	    return true;
-
-	 if (Architecture == "all" && Arch == _config->Find("APT::Architecture"))
-	    return true;
-      }
-
-      iOffset = Tags.Offset();
-   }   
-   return false;
-}
-									/*}}}*/
-// ListParser::LoadReleaseInfo - Load the release information		/*{{{*/
-// ---------------------------------------------------------------------
-/* */
-bool debListParser::LoadReleaseInfo(pkgCache::PkgFileIterator &FileI,
-				    FileFd &File, string component)
-{
-   // apt-secure does no longer download individual (per-section) Release
-   // file. to provide Component pinning we use the section name now
-   map_stringitem_t const storage = StoreString(pkgCacheGenerator::MIXED, component);
-   FileI->Component = storage;
-
-   pkgTagFile TagFile(&File, File.Size());
-   pkgTagSection Section;
-   if (_error->PendingError() == true || TagFile.Step(Section) == false)
-      return false;
-
-   std::string data;
-   #define APT_INRELEASE(TYPE, TAG, STORE) \
-   data = Section.FindS(TAG); \
-   if (data.empty() == false) \
-   { \
-      map_stringitem_t const storage = StoreString(pkgCacheGenerator::TYPE, data); \
-      STORE = storage; \
-   }
-   APT_INRELEASE(MIXED, "Suite", FileI->Archive)
-   APT_INRELEASE(MIXED, "Component", FileI->Component)
-   APT_INRELEASE(VERSIONNUMBER, "Version", FileI->Version)
-   APT_INRELEASE(MIXED, "Origin", FileI->Origin)
-   APT_INRELEASE(MIXED, "Codename", FileI->Codename)
-   APT_INRELEASE(MIXED, "Label", FileI->Label)
-   #undef APT_INRELEASE
-   Section.FindFlag("NotAutomatic", FileI->Flags, pkgCache::Flag::NotAutomatic);
-   Section.FindFlag("ButAutomaticUpgrades", FileI->Flags, pkgCache::Flag::ButAutomaticUpgrades);
-
-   return !_error->PendingError();
+   return Tags.Step(Section);
 }
 									/*}}}*/
 // ListParser::GetPrio - Convert the priority from a string		/*{{{*/
@@ -1000,11 +897,10 @@ unsigned char debListParser::GetPrio(string Str)
    return Out;
 }
 									/*}}}*/
-#if APT_PKG_ABI >= 413
 bool debListParser::SameVersion(unsigned short const Hash,		/*{{{*/
       pkgCache::VerIterator const &Ver)
 {
-   if (pkgCacheGenerator::ListParser::SameVersion(Hash, Ver) == false)
+   if (pkgCacheListParser::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
@@ -1020,11 +916,9 @@ bool debListParser::SameVersion(unsigned short const Hash,		/*{{{*/
    return true;
 }
 									/*}}}*/
-#endif
-
 
 debDebFileParser::debDebFileParser(FileFd *File, std::string const &DebFile)
-   : debListParser(File, ""), DebFile(DebFile)
+   : debListParser(File), DebFile(DebFile)
 {
 }
 
@@ -1034,7 +928,7 @@ bool debDebFileParser::UsePackage(pkgCache::PkgIterator &Pkg,
    bool res = debListParser::UsePackage(Pkg, Ver);
    // we use the full file path as a provides so that the file is found
    // by its name
-   if(NewProvidesAllArch(Ver, DebFile, Ver.VerStr()) == false)
+   if(NewProvides(Ver, DebFile, Pkg.Cache()->NativeArch(), Ver.VerStr(), 0) == false)
       return false;
    return res;
 }

+ 25 - 31
apt-pkg/deb/deblistparser.h

@@ -26,7 +26,7 @@
 
 class FileFd;
 
-class APT_HIDDEN debListParser : public pkgCacheGenerator::ListParser
+class APT_HIDDEN debListParser : public pkgCacheListParser
 {
    public:
 
@@ -39,21 +39,17 @@ class APT_HIDDEN debListParser : public pkgCacheGenerator::ListParser
 
    private:
    /** \brief dpointer placeholder (for later in case we need it) */
-   void *d;
+   void * const d;
 
    protected:
    pkgTagFile Tags;
    pkgTagSection Section;
    map_filesize_t iOffset;
-   std::string Arch;
-   std::vector<std::string> Architectures;
-   bool MultiArchEnabled;
 
    virtual bool ParseStatus(pkgCache::PkgIterator &Pkg,pkgCache::VerIterator &Ver);
    bool ParseDepends(pkgCache::VerIterator &Ver,const char *Tag,
 		     unsigned int Type);
    bool ParseProvides(pkgCache::VerIterator &Ver);
-   bool NewProvidesAllArch(pkgCache::VerIterator &Ver, std::string const &Package, std::string const &Version);
    static bool GrabWord(std::string Word,WordList *List,unsigned char &Out);
    APT_HIDDEN unsigned char ParseMultiArch(bool const showErrors);
 
@@ -62,27 +58,25 @@ class APT_HIDDEN debListParser : public pkgCacheGenerator::ListParser
    APT_PUBLIC static unsigned char GetPrio(std::string Str);
       
    // These all operate against the current section
-   virtual std::string Package();
-   virtual std::string Architecture();
-   virtual bool ArchitectureAll();
-   virtual std::string Version();
-   virtual bool NewVersion(pkgCache::VerIterator &Ver);
-   virtual std::string Description(std::string const &lang);
-   virtual std::vector<std::string> AvailableDescriptionLanguages();
-   virtual MD5SumValue Description_md5();
-   virtual unsigned short VersionHash();
-#if APT_PKG_ABI >= 413
-   virtual bool SameVersion(unsigned short const Hash, pkgCache::VerIterator const &Ver);
-#endif
+   virtual std::string Package() APT_OVERRIDE;
+   virtual std::string Architecture() APT_OVERRIDE;
+   virtual bool ArchitectureAll() APT_OVERRIDE;
+   virtual std::string Version() APT_OVERRIDE;
+   virtual bool NewVersion(pkgCache::VerIterator &Ver) APT_OVERRIDE;
+   virtual std::string Description(std::string const &lang) APT_OVERRIDE;
+   virtual std::vector<std::string> AvailableDescriptionLanguages() APT_OVERRIDE;
+   virtual MD5SumValue Description_md5() APT_OVERRIDE;
+   virtual unsigned short VersionHash() APT_OVERRIDE;
+   virtual bool SameVersion(unsigned short const Hash, pkgCache::VerIterator const &Ver) APT_OVERRIDE;
    virtual bool UsePackage(pkgCache::PkgIterator &Pkg,
-			   pkgCache::VerIterator &Ver);
-   virtual map_filesize_t Offset() {return iOffset;};
-   virtual map_filesize_t Size() {return Section.size();};
+			   pkgCache::VerIterator &Ver) APT_OVERRIDE;
+   virtual map_filesize_t Offset() APT_OVERRIDE {return iOffset;};
+   virtual map_filesize_t Size() APT_OVERRIDE {return Section.size();};
 
-   virtual bool Step();
-   
-   bool LoadReleaseInfo(pkgCache::PkgFileIterator &FileI,FileFd &File,
-			std::string section);
+   virtual bool Step() APT_OVERRIDE;
+
+   bool LoadReleaseInfo(pkgCache::RlsFileIterator &FileI,FileFd &File,
+			std::string const &section);
 
    APT_PUBLIC static const char *ParseDepends(const char *Start,const char *Stop,
 	 std::string &Package,std::string &Ver,unsigned int &Op);
@@ -99,7 +93,7 @@ class APT_HIDDEN debListParser : public pkgCacheGenerator::ListParser
 
    APT_PUBLIC static const char *ConvertRelation(const char *I,unsigned int &Op);
 
-   debListParser(FileFd *File, std::string const &Arch = "");
+   debListParser(FileFd *File);
    virtual ~debListParser();
 };
 
@@ -111,18 +105,18 @@ class APT_HIDDEN debDebFileParser : public debListParser
  public:
    debDebFileParser(FileFd *File, std::string const &DebFile);
    virtual bool UsePackage(pkgCache::PkgIterator &Pkg,
-			   pkgCache::VerIterator &Ver);
+			   pkgCache::VerIterator &Ver) APT_OVERRIDE;
 };
 
 class APT_HIDDEN debTranslationsParser : public debListParser
 {
  public:
    // a translation can never be a real package
-   virtual std::string Architecture() { return ""; }
-   virtual std::string Version() { return ""; }
+   virtual std::string Architecture() APT_OVERRIDE { return ""; }
+   virtual std::string Version() APT_OVERRIDE { return ""; }
 
-   debTranslationsParser(FileFd *File, std::string const &Arch = "")
-      : debListParser(File, Arch) {};
+   debTranslationsParser(FileFd *File)
+      : debListParser(File) {};
 };
 
 #endif

Rozdílová data souboru nebyla zobrazena, protože soubor je příliš velký
+ 623 - 385
apt-pkg/deb/debmetaindex.cc


+ 33 - 65
apt-pkg/deb/debmetaindex.h

@@ -1,4 +1,3 @@
-// ijones, walters
 #ifndef PKGLIB_DEBMETAINDEX_H
 #define PKGLIB_DEBMETAINDEX_H
 
@@ -18,83 +17,52 @@
 
 class pkgAcquire;
 class pkgIndexFile;
-class debDebPkgFileIndex;
 class IndexTarget;
+class pkgCacheGenerator;
+class OpProgress;
+class debReleaseIndexPrivate;
 
-class APT_HIDDEN debReleaseIndex : public metaIndex {
-   public:
-
-   class debSectionEntry
-   {
-      public:
-      debSectionEntry (std::string const &Section, bool const &IsSrc);
-      std::string const Section;
-      bool const IsSrc;
-   };
-
-   private:
-   /** \brief dpointer placeholder (for later in case we need it) */
-   void *d;
-   std::map<std::string, std::vector<debSectionEntry const*> > ArchEntries;
-   enum APT_HIDDEN { ALWAYS_TRUSTED, NEVER_TRUSTED, CHECK_TRUST } Trusted;
+class APT_HIDDEN debReleaseIndex : public metaIndex
+{
+   debReleaseIndexPrivate * const d;
 
+   APT_HIDDEN bool parseSumData(const char *&Start, const char *End, std::string &Name,
+		     std::string &Hash, unsigned long long &Size);
    public:
 
+   APT_HIDDEN std::string MetaIndexInfo(const char *Type) const;
+   APT_HIDDEN std::string MetaIndexFile(const char *Types) const;
+   APT_HIDDEN std::string MetaIndexURI(const char *Type) const;
+
    debReleaseIndex(std::string const &URI, std::string const &Dist);
    debReleaseIndex(std::string const &URI, std::string const &Dist, bool const Trusted);
    virtual ~debReleaseIndex();
 
-   virtual std::string ArchiveURI(std::string const &File) const {return URI + File;};
-   virtual bool GetIndexes(pkgAcquire *Owner, bool const &GetAll=false) const;
-   std::vector <IndexTarget *>* ComputeIndexTargets() const;
-   std::string Info(const char *Type, std::string const &Section, std::string const &Arch="") const;
+   virtual std::string ArchiveURI(std::string const &File) const APT_OVERRIDE {return URI + File;};
+   virtual bool GetIndexes(pkgAcquire *Owner, bool const &GetAll=false) APT_OVERRIDE;
+   virtual std::vector<IndexTarget> GetIndexTargets() const APT_OVERRIDE;
 
-   std::string MetaIndexInfo(const char *Type) const;
-   std::string MetaIndexFile(const char *Types) const;
-   std::string MetaIndexURI(const char *Type) const;
+   virtual std::string Describe() const APT_OVERRIDE;
+   virtual pkgCache::RlsFileIterator FindInCache(pkgCache &Cache, bool const ModifyCheck) const APT_OVERRIDE;
+   virtual bool Merge(pkgCacheGenerator &Gen,OpProgress *Prog) const APT_OVERRIDE;
 
-#if APT_PKG_ABI >= 413
-   virtual
-#endif
-   std::string LocalFileName() const;
-
-   std::string IndexURI(const char *Type, std::string const &Section, std::string const &Arch="native") const;
-   std::string IndexURISuffix(const char *Type, std::string const &Section, std::string const &Arch="native") const;
-   std::string SourceIndexURI(const char *Type, const std::string &Section) const;
-   std::string SourceIndexURISuffix(const char *Type, const std::string &Section) const;
-   std::string TranslationIndexURI(const char *Type, const std::string &Section) const;
-   std::string TranslationIndexURISuffix(const char *Type, const std::string &Section) const;
-   virtual std::vector <pkgIndexFile *> *GetIndexFiles();
-
-   void SetTrusted(bool const Trusted);
-   virtual bool IsTrusted() const;
-
-   void PushSectionEntry(std::vector<std::string> const &Archs, const debSectionEntry *Entry);
-   void PushSectionEntry(std::string const &Arch, const debSectionEntry *Entry);
-   void PushSectionEntry(const debSectionEntry *Entry);
-};
+   virtual bool Load(std::string const &Filename, std::string * const ErrorText) APT_OVERRIDE;
+   virtual metaIndex * UnloadedClone() const APT_OVERRIDE;
 
-class APT_HIDDEN debDebFileMetaIndex : public metaIndex
-{
- private:
-   std::string DebFile;
-   debDebPkgFileIndex *DebIndex;
- public:
-   virtual std::string ArchiveURI(std::string const& /*File*/) const {
-      return DebFile;
-   }
-   virtual bool GetIndexes(pkgAcquire* /*Owner*/, const bool& /*GetAll=false*/) const {
-      return true;
-   }
-   virtual std::vector<pkgIndexFile *> *GetIndexFiles() {
-      return Indexes;
-   }
-   virtual bool IsTrusted() const {
-      return true;
-   }
-   debDebFileMetaIndex(std::string const &DebFile);
-   virtual ~debDebFileMetaIndex() {};
+   virtual std::vector <pkgIndexFile *> *GetIndexFiles() APT_OVERRIDE;
+
+   bool SetTrusted(TriState const Trusted);
+   bool SetCheckValidUntil(TriState const Trusted);
+   bool SetValidUntilMin(time_t const Valid);
+   bool SetValidUntilMax(time_t const Valid);
+   bool SetSignedBy(std::string const &SignedBy);
+
+   virtual bool IsTrusted() const APT_OVERRIDE;
 
+   void AddComponent(bool const isSrc, std::string const &Name,
+	 std::vector<std::string> const &Targets,
+	 std::vector<std::string> const &Architectures,
+	 std::vector<std::string> Languages);
 };
 
 #endif

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

@@ -34,7 +34,7 @@ using std::string;
 
 // RecordParser::debRecordParser - Constructor				/*{{{*/
 debRecordParser::debRecordParser(string FileName,pkgCache &Cache) :
-   debRecordParserBase(), File(FileName, FileFd::ReadOnly, FileFd::Extension),
+   debRecordParserBase(), d(NULL), File(FileName, FileFd::ReadOnly, FileFd::Extension),
    Tags(&File, std::max(Cache.Head().MaxVerFileSize, Cache.Head().MaxDescFileSize) + 200)
 {
 }
@@ -42,15 +42,20 @@ debRecordParser::debRecordParser(string FileName,pkgCache &Cache) :
 // RecordParser::Jump - Jump to a specific record			/*{{{*/
 bool debRecordParser::Jump(pkgCache::VerFileIterator const &Ver)
 {
+   if (Ver.end() == true)
+      return false;
    return Tags.Jump(Section,Ver->Offset);
 }
 bool debRecordParser::Jump(pkgCache::DescFileIterator const &Desc)
 {
+   if (Desc.end() == true)
+      return false;
    return Tags.Jump(Section,Desc->Offset);
 }
 									/*}}}*/
 debRecordParser::~debRecordParser() {}
 
+debRecordParserBase::debRecordParserBase() : Parser(), d(NULL) {}
 // RecordParserBase::FileName - Return the archive filename on the site	/*{{{*/
 string debRecordParserBase::FileName()
 {
@@ -207,3 +212,9 @@ bool debDebFileRecordParser::LoadContent()
       return _error->Error(_("Unable to parse package file %s (%d)"), debFileName.c_str(), 3);
    return true;
 }
+bool debDebFileRecordParser::Jump(pkgCache::VerFileIterator const &) { return LoadContent(); }
+bool debDebFileRecordParser::Jump(pkgCache::DescFileIterator const &) { return LoadContent(); }
+std::string debDebFileRecordParser::FileName() { return debFileName; }
+
+debDebFileRecordParser::debDebFileRecordParser(std::string FileName) : debRecordParserBase(), d(NULL), debFileName(FileName) {}
+debDebFileRecordParser::~debDebFileRecordParser() {}

+ 22 - 19
apt-pkg/deb/debrecords.h

@@ -27,41 +27,43 @@
 
 class APT_HIDDEN debRecordParserBase : public pkgRecords::Parser
 {
+   void * const d;
  protected:
    pkgTagSection Section;
 
  public:
    // These refer to the archive file for the Version
-   virtual std::string FileName();
-   virtual std::string SourcePkg();
-   virtual std::string SourceVer();
+   virtual std::string FileName() APT_OVERRIDE;
+   virtual std::string SourcePkg() APT_OVERRIDE;
+   virtual std::string SourceVer() APT_OVERRIDE;
 
-   virtual HashStringList Hashes() const;
+   virtual HashStringList Hashes() const APT_OVERRIDE;
 
    // These are some general stats about the package
-   virtual std::string Maintainer();
-   virtual std::string ShortDesc(std::string const &lang);
-   virtual std::string LongDesc(std::string const &lang);
-   virtual std::string Name();
-   virtual std::string Homepage();
+   virtual std::string Maintainer() APT_OVERRIDE;
+   virtual std::string ShortDesc(std::string const &lang) APT_OVERRIDE;
+   virtual std::string LongDesc(std::string const &lang) APT_OVERRIDE;
+   virtual std::string Name() APT_OVERRIDE;
+   virtual std::string Homepage() APT_OVERRIDE;
 
    // An arbitrary custom field
-   virtual std::string RecordField(const char *fieldName);
+   virtual std::string RecordField(const char *fieldName) APT_OVERRIDE;
 
-   virtual void GetRec(const char *&Start,const char *&Stop);
+   virtual void GetRec(const char *&Start,const char *&Stop) APT_OVERRIDE;
 
-   debRecordParserBase() : Parser() {}
+   debRecordParserBase();
    virtual ~debRecordParserBase();
 };
 
 class APT_HIDDEN debRecordParser : public debRecordParserBase
 {
+   void * const d;
  protected:
    FileFd File;
    pkgTagFile Tags;
 
-   virtual bool Jump(pkgCache::VerFileIterator const &Ver);
-   virtual bool Jump(pkgCache::DescFileIterator const &Desc);
+   virtual bool Jump(pkgCache::VerFileIterator const &Ver) APT_OVERRIDE;
+   virtual bool Jump(pkgCache::DescFileIterator const &Desc) APT_OVERRIDE;
 
  public:
    debRecordParser(std::string FileName,pkgCache &Cache);
@@ -71,20 +73,21 @@ class APT_HIDDEN debRecordParser : public debRecordParserBase
 // custom record parser that reads deb files directly
 class APT_HIDDEN debDebFileRecordParser : public debRecordParserBase
 {
+   void * const d;
    std::string debFileName;
    std::string controlContent;
 
    APT_HIDDEN bool LoadContent();
  protected:
    // single file files, so no jumping whatsoever
-   bool Jump(pkgCache::VerFileIterator const &) { return LoadContent(); }
-   bool Jump(pkgCache::DescFileIterator const &) { return LoadContent(); }
+   bool Jump(pkgCache::VerFileIterator const &) APT_OVERRIDE;
+   bool Jump(pkgCache::DescFileIterator const &) APT_OVERRIDE;
 
  public:
-   virtual std::string FileName() { return debFileName; }
+   virtual std::string FileName() APT_OVERRIDE;
 
-   debDebFileRecordParser(std::string FileName)
-      : debRecordParserBase(), debFileName(FileName) {};
+   debDebFileRecordParser(std::string FileName);
+   virtual ~debDebFileRecordParser();
 };
 
 #endif

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

@@ -32,6 +32,10 @@
 using std::max;
 using std::string;
 
+debSrcRecordParser::debSrcRecordParser(std::string const &File,pkgIndexFile const *Index)
+   : Parser(Index), d(NULL), Fd(File,FileFd::ReadOnly, FileFd::Extension), Tags(&Fd,102400),
+   iOffset(0), Buffer(NULL) {}
+
 // SrcRecordParser::Binaries - Return the binaries field		/*{{{*/
 // ---------------------------------------------------------------------
 /* This member parses the binaries field into a pair of class arrays and

+ 14 - 16
apt-pkg/deb/debsrcrecords.h

@@ -24,7 +24,7 @@ class pkgIndexFile;
 class APT_HIDDEN debSrcRecordParser : public pkgSrcRecords::Parser
 {
    /** \brief dpointer placeholder (for later in case we need it) */
-   void *d;
+   void * const d;
 
  protected:
    FileFd Fd;
@@ -36,29 +36,27 @@ class APT_HIDDEN debSrcRecordParser : public pkgSrcRecords::Parser
    
    public:
 
-   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);};
+   virtual bool Restart() APT_OVERRIDE {return Jump(0);};
+   virtual bool Step() APT_OVERRIDE {iOffset = Tags.Offset(); return Tags.Step(Sect);};
+   virtual bool Jump(unsigned long const &Off) APT_OVERRIDE {iOffset = Off; return Tags.Jump(Sect,Off);};
 
-   virtual std::string Package() const {return Sect.FindS("Package");};
-   virtual std::string Version() const {return Sect.FindS("Version");};
-   virtual std::string Maintainer() const {return Sect.FindS("Maintainer");};
-   virtual std::string Section() const {return Sect.FindS("Section");};
-   virtual const char **Binaries();
-   virtual bool BuildDepends(std::vector<BuildDepRec> &BuildDeps, bool const &ArchOnly, bool const &StripMultiArch = true);
-   virtual unsigned long Offset() {return iOffset;};
-   virtual std::string AsStr() 
+   virtual std::string Package() const APT_OVERRIDE {return Sect.FindS("Package");};
+   virtual std::string Version() const APT_OVERRIDE {return Sect.FindS("Version");};
+   virtual std::string Maintainer() const APT_OVERRIDE {return Sect.FindS("Maintainer");};
+   virtual std::string Section() const APT_OVERRIDE {return Sect.FindS("Section");};
+   virtual const char **Binaries() APT_OVERRIDE;
+   virtual bool BuildDepends(std::vector<BuildDepRec> &BuildDeps, bool const &ArchOnly, bool const &StripMultiArch = true) APT_OVERRIDE;
+   virtual unsigned long Offset() APT_OVERRIDE {return iOffset;};
+   virtual std::string AsStr() APT_OVERRIDE 
    {
       const char *Start=0,*Stop=0;
       Sect.GetSection(Start,Stop);
       return std::string(Start,Stop);
    };
-   virtual bool Files(std::vector<pkgSrcRecords::File> &F);
+   virtual bool Files(std::vector<pkgSrcRecords::File> &F) APT_OVERRIDE;
    bool Files2(std::vector<pkgSrcRecords::File2> &F);
 
-   debSrcRecordParser(std::string const &File,pkgIndexFile const *Index) 
-      : Parser(Index), Fd(File,FileFd::ReadOnly, FileFd::Extension), Tags(&Fd,102400),
-        iOffset(0), Buffer(NULL) {}
+   debSrcRecordParser(std::string const &File,pkgIndexFile const *Index);
    virtual ~debSrcRecordParser();
 };
 

+ 1 - 4
apt-pkg/deb/debsystem.cc

@@ -53,11 +53,8 @@ public:
 // System::debSystem - Constructor					/*{{{*/
 // ---------------------------------------------------------------------
 /* */
-debSystem::debSystem()
+debSystem::debSystem() : pkgSystem("Debian dpkg interface", &debVS), d(new debSystemPrivate())
 {
-   d = new debSystemPrivate();
-   Label = "Debian dpkg interface";
-   VS = &debVS;
 }
 									/*}}}*/
 // System::~debSystem - Destructor					/*{{{*/

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

@@ -28,20 +28,20 @@ class debStatusIndex;
 class debSystem : public pkgSystem
 {
    // private d-pointer
-   debSystemPrivate *d;
+   debSystemPrivate * const d;
    APT_HIDDEN bool CheckUpdates();
 
    public:
 
-   virtual bool Lock();
-   virtual bool UnLock(bool NoErrors = false);   
-   virtual pkgPackageManager *CreatePM(pkgDepCache *Cache) const;
-   virtual bool Initialize(Configuration &Cnf);
-   virtual bool ArchiveSupported(const char *Type);
-   virtual signed Score(Configuration const &Cnf);
-   virtual bool AddStatusFiles(std::vector<pkgIndexFile *> &List);
+   virtual bool Lock() APT_OVERRIDE;
+   virtual bool UnLock(bool NoErrors = false) APT_OVERRIDE;   
+   virtual pkgPackageManager *CreatePM(pkgDepCache *Cache) const APT_OVERRIDE;
+   virtual bool Initialize(Configuration &Cnf) APT_OVERRIDE;
+   virtual bool ArchiveSupported(const char *Type) APT_OVERRIDE;
+   virtual signed Score(Configuration const &Cnf) APT_OVERRIDE;
+   virtual bool AddStatusFiles(std::vector<pkgIndexFile *> &List) APT_OVERRIDE;
    virtual bool FindIndex(pkgCache::PkgFileIterator File,
-			  pkgIndexFile *&Found) const;
+			  pkgIndexFile *&Found) const APT_OVERRIDE;
 
    debSystem();
    virtual ~debSystem();

+ 22 - 26
apt-pkg/deb/debversion.cc

@@ -16,7 +16,6 @@
 #include <apt-pkg/pkgcache.h>
 
 #include <string.h>
-#include <string>
 #include <stdlib.h>
 #include <ctype.h>
 									/*}}}*/
@@ -34,29 +33,26 @@ debVersioningSystem::debVersioningSystem()
 
 // debVS::CmpFragment - Compare versions			        /*{{{*/
 // ---------------------------------------------------------------------
-/* This compares a fragment of the version. This is a slightly adapted 
-   version of what dpkg uses. */
-#define order(x) ((x) == '~' ? -1    \
-		: isdigit((x)) ? 0   \
-		: !(x) ? 0           \
-		: isalpha((x)) ? (x) \
-		: (x) + 256)
-int debVersioningSystem::CmpFragment(const char *A,const char *AEnd,
-				     const char *B,const char *BEnd)
+/* This compares a fragment of the version. This is a slightly adapted
+   version of what dpkg uses in dpkg/lib/dpkg/version.c.
+   In particular, the a | b = NULL check is removed as we check this in the
+   caller, we use an explicit end for a | b strings and we check ~ explicit. */
+static int order(char c)
 {
-   if (A >= AEnd && B >= BEnd)
+   if (isdigit(c))
       return 0;
-   if (A >= AEnd)
-   {
-      if (*B == '~') return 1;
+   else if (isalpha(c))
+      return c;
+   else if (c == '~')
       return -1;
-   }
-   if (B >= BEnd)
-   {
-      if (*A == '~') return -1;
-      return 1;
-   }
-
+   else if (c)
+      return c + 256;
+   else
+      return 0;
+}
+int debVersioningSystem::CmpFragment(const char *A,const char *AEnd,
+				     const char *B,const char *BEnd)
+{
    /* Iterate over the whole string
       What this does is to split the whole string into groups of
       numeric and non numeric portions. For instance:
@@ -77,19 +73,19 @@ int debVersioningSystem::CmpFragment(const char *A,const char *AEnd,
 	 int rc = order(*rhs);
 	 if (vc != rc)
 	    return vc - rc;
-	 lhs++; rhs++;
+	 ++lhs; ++rhs;
       }
 
       while (*lhs == '0')
-	 lhs++;
+	 ++lhs;
       while (*rhs == '0')
-	 rhs++;
+	 ++rhs;
       while (isdigit(*lhs) && isdigit(*rhs))
       {
 	 if (!first_diff)
 	    first_diff = *lhs - *rhs;
-	 lhs++;
-	 rhs++;
+	 ++lhs;
+	 ++rhs;
       }
 
       if (isdigit(*lhs))

+ 4 - 5
apt-pkg/deb/debversion.h

@@ -1,6 +1,5 @@
 // -*- mode: cpp; mode: fold -*-
 // Description								/*{{{*/
-// $Id: debversion.h,v 1.3 2001/05/03 05:25:04 jgg Exp $
 /* ######################################################################
 
    Debian Version - Versioning system for Debian
@@ -25,14 +24,14 @@ class debVersioningSystem : public pkgVersioningSystem
 
    // Compare versions..
    virtual int DoCmpVersion(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;
+			  const char *B,const char *Bend) APT_OVERRIDE APT_PURE;
+   virtual bool CheckDep(const char *PkgVer,int Op,const char *DepVer) APT_OVERRIDE APT_PURE;
    virtual APT_PURE int DoCmpReleaseVer(const char *A,const char *Aend,
-			     const char *B,const char *Bend)
+			     const char *B,const char *Bend) APT_OVERRIDE
    {
       return DoCmpVersion(A,Aend,B,Bend);
    }
-   virtual std::string UpstreamVersion(const char *A);
+   virtual std::string UpstreamVersion(const char *A) APT_OVERRIDE;
 
    debVersioningSystem();
 };

+ 9 - 18
apt-pkg/deb/dpkgpm.cc

@@ -18,7 +18,6 @@
 #include <apt-pkg/fileutl.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>
@@ -27,7 +26,6 @@
 #include <errno.h>
 #include <fcntl.h>
 #include <grp.h>
-#include <pty.h>
 #include <pwd.h>
 #include <signal.h>
 #include <stddef.h>
@@ -205,8 +203,10 @@ pkgCache::VerIterator FindNowVersion(const pkgCache::PkgIterator &Pkg)
    for (Ver = Pkg.VersionList(); Ver.end() == false; ++Ver)
       for (pkgCache::VerFileIterator Vf = Ver.FileList(); Vf.end() == false; ++Vf)
 	 for (pkgCache::PkgFileIterator F = Vf.File(); F.end() == false; ++F)
-	    if (F->Archive != 0 && strcmp(F.Archive(), "now") == 0)
+	 {
+	    if (F.Archive() != 0 && strcmp(F.Archive(), "now") == 0)
 	       return Ver;
+	 }
    return Ver;
 }
 									/*}}}*/
@@ -214,10 +214,9 @@ pkgCache::VerIterator FindNowVersion(const pkgCache::PkgIterator &Pkg)
 // DPkgPM::pkgDPkgPM - Constructor					/*{{{*/
 // ---------------------------------------------------------------------
 /* */
-pkgDPkgPM::pkgDPkgPM(pkgDepCache *Cache) 
-   : pkgPackageManager(Cache), pkgFailures(0), PackagesDone(0), PackagesTotal(0)
+pkgDPkgPM::pkgDPkgPM(pkgDepCache *Cache)
+   : pkgPackageManager(Cache),d(new pkgDPkgPMPrivate()), pkgFailures(0), PackagesDone(0), PackagesTotal(0)
 {
-   d = new pkgDPkgPMPrivate();
 }
 									/*}}}*/
 // DPkgPM::pkgDPkgPM - Destructor					/*{{{*/
@@ -1483,6 +1482,10 @@ bool pkgDPkgPM::Go(APT::Progress::PackageManager *progress)
 	      a != Args.end(); ++a)
 	    clog << *a << ' ';
 	 clog << endl;
+	 for (std::vector<char *>::const_iterator p = Packages.begin();
+	       p != Packages.end(); ++p)
+	    free(*p);
+	 Packages.clear();
 	 continue;
       }
       Args.push_back(NULL);
@@ -1540,9 +1543,6 @@ bool pkgDPkgPM::Go(APT::Progress::PackageManager *progress)
 	       _exit(100);
 	 }
 
-	 /* No Job Control Stop Env is a magic dpkg var that prevents it
-	    from using sigstop */
-	 putenv((char *)"DPKG_NO_TSTP=yes");
 	 execvp(Args[0], (char**) &Args[0]);
 	 cerr << "Could not exec dpkg!" << endl;
 	 _exit(100);
@@ -1841,16 +1841,7 @@ void pkgDPkgPM::WriteApportReport(const char *pkgpath, const char *errormsg)
    time_t now = time(NULL);
    fprintf(report, "Date: %s" , ctime(&now));
    fprintf(report, "Package: %s %s\n", pkgname.c_str(), pkgver.c_str());
-#if APT_PKG_ABI >= 413
    fprintf(report, "SourcePackage: %s\n", Ver.SourcePkgName());
-#else
-   pkgRecords Recs(Cache);
-   pkgRecords::Parser &Parse = Recs.Lookup(Ver.FileList());
-   std::string srcpkgname = Parse.SourcePkg();
-   if(srcpkgname.empty())
-      srcpkgname = pkgname;
-   fprintf(report, "SourcePackage: %s\n", srcpkgname.c_str());
-#endif
    fprintf(report, "ErrorMessage:\n %s\n", errormsg);
 
    // ensure that the log is flushed

+ 7 - 7
apt-pkg/deb/dpkgpm.h

@@ -37,7 +37,7 @@ class pkgDPkgPMPrivate;
 class pkgDPkgPM : public pkgPackageManager
 {
    private:
-   pkgDPkgPMPrivate *d;
+   pkgDPkgPMPrivate * const d;
 
    /** \brief record the disappear action and handle accordingly
 
@@ -120,14 +120,14 @@ class pkgDPkgPM : public pkgPackageManager
    void ProcessDpkgStatusLine(char *line);
 
    // The Actuall installation implementation
-   virtual bool Install(PkgIterator Pkg,std::string File);
-   virtual bool Configure(PkgIterator Pkg);
-   virtual bool Remove(PkgIterator Pkg,bool Purge = false);
+   virtual bool Install(PkgIterator Pkg,std::string File) APT_OVERRIDE;
+   virtual bool Configure(PkgIterator Pkg) APT_OVERRIDE;
+   virtual bool Remove(PkgIterator Pkg,bool Purge = false) APT_OVERRIDE;
 
-   virtual bool Go(APT::Progress::PackageManager *progress);
-   virtual bool Go(int StatusFd=-1);
+   virtual bool Go(APT::Progress::PackageManager *progress) APT_OVERRIDE;
+   virtual bool Go(int StatusFd=-1) APT_OVERRIDE;
 
-   virtual void Reset();
+   virtual void Reset() APT_OVERRIDE;
    
    public:
 

+ 161 - 115
apt-pkg/depcache.cc

@@ -13,7 +13,6 @@
 #include <apt-pkg/depcache.h>
 #include <apt-pkg/versionmatch.h>
 #include <apt-pkg/error.h>
-#include <apt-pkg/sptr.h>
 #include <apt-pkg/fileutl.h>
 #include <apt-pkg/strutl.h>
 #include <apt-pkg/configuration.h>
@@ -23,6 +22,7 @@
 #include <apt-pkg/cacheset.h>
 #include <apt-pkg/pkgcache.h>
 #include <apt-pkg/cacheiterators.h>
+#include <apt-pkg/cachefile.h>
 #include <apt-pkg/macros.h>
 
 #include <stdio.h>
@@ -63,7 +63,7 @@ ConfigValueInSubTree(const char* SubTree, const char *needle)
 }
 									/*}}}*/
 pkgDepCache::ActionGroup::ActionGroup(pkgDepCache &cache) :		/*{{{*/
-  cache(cache), released(false)
+  d(NULL), cache(cache), released(false)
 {
   ++cache.group_level;
 }
@@ -94,8 +94,10 @@ pkgDepCache::ActionGroup::~ActionGroup()
 // DepCache::pkgDepCache - Constructors					/*{{{*/
 // ---------------------------------------------------------------------
 /* */
-pkgDepCache::pkgDepCache(pkgCache *pCache,Policy *Plcy) :
-  group_level(0), Cache(pCache), PkgState(0), DepState(0)
+pkgDepCache::pkgDepCache(pkgCache * const pCache,Policy * const Plcy) :
+  group_level(0), Cache(pCache), PkgState(0), DepState(0),
+   iUsrSize(0), iDownloadSize(0), iInstCount(0), iDelCount(0), iKeepCount(0),
+   iBrokenCount(0), iPolicyBrokenCount(0), iBadCount(0), d(NULL)
 {
    DebugMarker = _config->FindB("Debug::pkgDepCache::Marker", false);
    DebugAutoInstall = _config->FindB("Debug::pkgDepCache::AutoInstall", false);
@@ -118,7 +120,7 @@ pkgDepCache::~pkgDepCache()
 // DepCache::Init - Generate the initial extra structures.		/*{{{*/
 // ---------------------------------------------------------------------
 /* This allocats the extension buffers and initializes them. */
-bool pkgDepCache::Init(OpProgress *Prog)
+bool pkgDepCache::Init(OpProgress * const Prog)
 {
    // Suppress mark updates during this operation (just in case) and
    // run a mark operation when Init terminates.
@@ -129,7 +131,7 @@ bool pkgDepCache::Init(OpProgress *Prog)
    PkgState = new StateCache[Head().PackageCount];
    DepState = new unsigned char[Head().DependsCount];
    memset(PkgState,0,sizeof(*PkgState)*Head().PackageCount);
-   memset(DepState,0,sizeof(*DepState)*Head().DependsCount); 
+   memset(DepState,0,sizeof(*DepState)*Head().DependsCount);
 
    if (Prog != 0)
    {
@@ -137,7 +139,7 @@ bool pkgDepCache::Init(OpProgress *Prog)
 			    _("Building dependency tree"));
       Prog->SubProgress(Head().PackageCount,_("Candidate versions"));
    }
-   
+
    /* Set the current state of everything. In this state all of the
       packages are kept exactly as is. See AllUpgrade */
    int Done = 0;
@@ -145,7 +147,7 @@ bool pkgDepCache::Init(OpProgress *Prog)
    {
       if (Prog != 0 && Done%20 == 0)
 	 Prog->Progress(Done);
-      
+
       // Find the proper cache slot
       StateCache &State = PkgState[I->ID];
       State.iFlags = 0;
@@ -154,28 +156,27 @@ bool pkgDepCache::Init(OpProgress *Prog)
       State.CandidateVer = GetCandidateVer(I);
       State.InstallVer = I.CurrentVer();
       State.Mode = ModeKeep;
-      
+
       State.Update(I,*this);
-   }   
-   
+   }
+
    if (Prog != 0)
    {
-      
       Prog->OverallProgress(Head().PackageCount,2*Head().PackageCount,
 			    Head().PackageCount,
 			    _("Building dependency tree"));
       Prog->SubProgress(Head().PackageCount,_("Dependency generation"));
    }
-   
+
    Update(Prog);
 
    if(Prog != 0)
       Prog->Done();
 
    return true;
-} 
+}
 									/*}}}*/
-bool pkgDepCache::readStateFile(OpProgress *Prog)			/*{{{*/
+bool pkgDepCache::readStateFile(OpProgress * const Prog)		/*{{{*/
 {
    FileFd state_file;
    string const state = _config->FindFile("Dir::State::extended_states");
@@ -183,7 +184,7 @@ bool pkgDepCache::readStateFile(OpProgress *Prog)			/*{{{*/
       state_file.Open(state, FileFd::ReadOnly);
       off_t const file_size = state_file.Size();
       if(Prog != NULL)
-	 Prog->OverallProgress(0, file_size, 1, 
+	 Prog->OverallProgress(0, file_size, 1,
 			       _("Reading state information"));
 
       pkgTagFile tagfile(&state_file);
@@ -227,7 +228,7 @@ bool pkgDepCache::readStateFile(OpProgress *Prog)			/*{{{*/
    return true;
 }
 									/*}}}*/
-bool pkgDepCache::writeStateFile(OpProgress * /*prog*/, bool InstalledOnly)	/*{{{*/
+bool pkgDepCache::writeStateFile(OpProgress * const /*prog*/, bool const InstalledOnly)	/*{{{*/
 {
    bool const debug_autoremove = _config->FindB("Debug::pkgAutoRemove",false);
    
@@ -337,7 +338,7 @@ bool pkgDepCache::writeStateFile(OpProgress * /*prog*/, bool InstalledOnly)	/*{{
    then walks along the package provides list and checks if each provides 
    will be installed then checks the provides against the dep. Res will be 
    set to the package which was used to satisfy the dep. */
-bool pkgDepCache::CheckDep(DepIterator Dep,int Type,PkgIterator &Res)
+bool pkgDepCache::CheckDep(DepIterator const &Dep,int const Type,PkgIterator &Res)
 {
    Res = Dep.TargetPkg();
 
@@ -346,24 +347,27 @@ bool pkgDepCache::CheckDep(DepIterator Dep,int Type,PkgIterator &Res)
       bug. Conflicts may never self match */
    if (Dep.IsIgnorable(Res) == false)
    {
-      PkgIterator Pkg = Dep.TargetPkg();
       // Check the base package
-      if (Type == NowVersion && Pkg->CurrentVer != 0)
-	 if (Dep.IsSatisfied(Pkg.CurrentVer()) == true)
+      if (Type == NowVersion)
+      {
+	 if (Res->CurrentVer != 0 && Dep.IsSatisfied(Res.CurrentVer()) == true)
 	    return true;
-      
-      if (Type == InstallVersion && PkgState[Pkg->ID].InstallVer != 0)
-	 if (Dep.IsSatisfied(PkgState[Pkg->ID].InstVerIter(*this)) == true)
+      }
+      else if (Type == InstallVersion)
+      {
+	 if (PkgState[Res->ID].InstallVer != 0 &&
+	       Dep.IsSatisfied(PkgState[Res->ID].InstVerIter(*this)) == true)
 	    return true;
-      
-      if (Type == CandidateVersion && PkgState[Pkg->ID].CandidateVer != 0)
-	 if (Dep.IsSatisfied(PkgState[Pkg->ID].CandidateVerIter(*this)) == true)
+      }
+      else if (Type == CandidateVersion)
+	 if (PkgState[Res->ID].CandidateVer != 0 &&
+	       Dep.IsSatisfied(PkgState[Res->ID].CandidateVerIter(*this)) == true)
 	    return true;
    }
-   
+
    if (Dep->Type == Dep::Obsoletes)
       return false;
-   
+
    // Check the providing packages
    PrvIterator P = Dep.TargetPkg().ProvidesList();
    for (; P.end() != true; ++P)
@@ -377,21 +381,19 @@ bool pkgDepCache::CheckDep(DepIterator Dep,int Type,PkgIterator &Res)
 	 if (P.OwnerPkg().CurrentVer() != P.OwnerVer())
 	    continue;
       }
-      
-      if (Type == InstallVersion)
+      else if (Type == InstallVersion)
       {
 	 StateCache &State = PkgState[P.OwnerPkg()->ID];
 	 if (State.InstallVer != (Version *)P.OwnerVer())
 	    continue;
       }
-
-      if (Type == CandidateVersion)
+      else if (Type == CandidateVersion)
       {
 	 StateCache &State = PkgState[P.OwnerPkg()->ID];
 	 if (State.CandidateVer != (Version *)P.OwnerVer())
 	    continue;
       }
-      
+
       // Compare the versions.
       if (Dep.IsSatisfied(P) == true)
       {
@@ -399,7 +401,7 @@ bool pkgDepCache::CheckDep(DepIterator Dep,int Type,PkgIterator &Res)
 	 return true;
       }
    }
-   
+
    return false;
 }
 									/*}}}*/
@@ -481,47 +483,46 @@ void pkgDepCache::AddStates(const PkgIterator &Pkg, bool const Invert)
 {
    signed char const Add = (Invert == false) ? 1 : -1;
    StateCache &State = PkgState[Pkg->ID];
-   
+
    // The Package is broken (either minimal dep or policy dep)
    if ((State.DepState & DepInstMin) != DepInstMin)
       iBrokenCount += Add;
    if ((State.DepState & DepInstPolicy) != DepInstPolicy)
       iPolicyBrokenCount += Add;
-   
+
    // Bad state
    if (Pkg.State() != PkgIterator::NeedsNothing)
       iBadCount += Add;
-   
+
    // Not installed
    if (Pkg->CurrentVer == 0)
    {
       if (State.Mode == ModeDelete &&
 	  (State.iFlags & Purge) == Purge && Pkg.Purge() == false)
 	 iDelCount += Add;
-      
+
       if (State.Mode == ModeInstall)
 	 iInstCount += Add;
       return;
    }
-   
+
    // Installed, no upgrade
    if (State.Status == 0)
-   {	 
+   {
       if (State.Mode == ModeDelete)
 	 iDelCount += Add;
       else
 	 if ((State.iFlags & ReInstall) == ReInstall)
 	    iInstCount += Add;
-      
       return;
    }
-   
+
    // Alll 3 are possible
    if (State.Mode == ModeDelete)
-      iDelCount += Add;   
-   if (State.Mode == ModeKeep)
+      iDelCount += Add;
+   else if (State.Mode == ModeKeep)
       iKeepCount += Add;
-   if (State.Mode == ModeInstall)
+   else if (State.Mode == ModeInstall)
       iInstCount += Add;
 }
 									/*}}}*/
@@ -532,7 +533,6 @@ void pkgDepCache::AddStates(const PkgIterator &Pkg, bool const Invert)
 void pkgDepCache::BuildGroupOrs(VerIterator const &V)
 {
    unsigned char Group = 0;
-   
    for (DepIterator D = V.DependsList(); D.end() != true; ++D)
    {
       // Build the dependency state.
@@ -542,18 +542,18 @@ void pkgDepCache::BuildGroupOrs(VerIterator const &V)
          right sense for a conflicts group */
       if (D.IsNegative() == true)
 	 State = ~State;
-      
+
       // Add to the group if we are within an or..
       State &= 0x7;
       Group |= State;
       State |= Group << 3;
       if ((D->CompareOp & Dep::Or) != Dep::Or)
 	 Group = 0;
-      
+
       // Invert for Conflicts
       if (D.IsNegative() == true)
 	 State = ~State;
-   }	 
+   }
 }
 									/*}}}*/
 // DepCache::VersionState - Perform a pass over a dependency list	/*{{{*/
@@ -562,34 +562,31 @@ void pkgDepCache::BuildGroupOrs(VerIterator const &V)
    state of the list, filtering it through both a Min check and a Policy
    check. The return result will have SetMin/SetPolicy low if a check
    fails. It uses the DepState cache for it's computations. */
-unsigned char pkgDepCache::VersionState(DepIterator D,unsigned char Check,
-				       unsigned char SetMin,
-				       unsigned char SetPolicy)
+unsigned char pkgDepCache::VersionState(DepIterator D, unsigned char const Check,
+				       unsigned char const SetMin,
+				       unsigned char const SetPolicy) const
 {
    unsigned char Dep = 0xFF;
-   
    while (D.end() != true)
    {
-      // Compute a single dependency element (glob or)
-      DepIterator Start = D;
-      unsigned char State = 0;
-      for (bool LastOR = true; D.end() == false && LastOR == true; ++D)
-      {
-	 State |= DepState[D->ID];
-	 LastOR = (D->CompareOp & Dep::Or) == Dep::Or;
-      }
-	
+      // the last or-dependency has the state of all previous or'ed
+      DepIterator Start, End;
+      D.GlobOr(Start, End);
+      // ignore if we are called with Dep{Install,…} or DepG{Install,…}
+      // the later would be more correct, but the first is what we get
+      unsigned char const State = DepState[End->ID] | (DepState[End->ID] >> 3);
+
       // Minimum deps that must be satisfied to have a working package
       if (Start.IsCritical() == true)
+      {
 	 if ((State & Check) != Check)
-	    Dep &= ~SetMin;
-      
+	    return Dep &= ~(SetMin | SetPolicy);
+      }
       // Policy deps that must be satisfied to install the package
-      if (IsImportantDep(Start) == true && 
+      else if (IsImportantDep(Start) == true &&
 	  (State & Check) != Check)
 	 Dep &= ~SetPolicy;
    }
-
    return Dep;
 }
 									/*}}}*/
@@ -598,17 +595,17 @@ unsigned char pkgDepCache::VersionState(DepIterator D,unsigned char Check,
 /* This is the main dependency computation bit. It computes the 3 main
    results for a dependencys, Now, Install and Candidate. Callers must
    invert the result if dealing with conflicts. */
-unsigned char pkgDepCache::DependencyState(DepIterator &D)
+unsigned char pkgDepCache::DependencyState(DepIterator const &D)
 {
    unsigned char State = 0;
-   
+
    if (CheckDep(D,NowVersion) == true)
       State |= DepNow;
    if (CheckDep(D,InstallVersion) == true)
       State |= DepInstall;
    if (CheckDep(D,CandidateVersion) == true)
       State |= DepCVer;
-   
+
    return State;
 }
 									/*}}}*/
@@ -617,7 +614,7 @@ unsigned char pkgDepCache::DependencyState(DepIterator &D)
 /* This determines the combined dependency representation of a package
    for its two states now and install. This is done by using the pre-generated
    dependency information. */
-void pkgDepCache::UpdateVerState(PkgIterator Pkg)
+void pkgDepCache::UpdateVerState(PkgIterator const &Pkg)
 {   
    // Empty deps are always true
    StateCache &State = PkgState[Pkg->ID];
@@ -651,7 +648,7 @@ void pkgDepCache::UpdateVerState(PkgIterator Pkg)
 // ---------------------------------------------------------------------
 /* This will figure out the state of all the packages and all the 
    dependencies based on the current policy. */
-void pkgDepCache::Update(OpProgress *Prog)
+void pkgDepCache::Update(OpProgress * const Prog)
 {   
    iUsrSize = 0;
    iDownloadSize = 0;
@@ -838,6 +835,41 @@ bool pkgDepCache::MarkDelete(PkgIterator const &Pkg, bool rPurge,
 
    ActionGroup group(*this);
 
+   if (FromUser == false)
+   {
+      VerIterator const PV = P.InstVerIter(*this);
+      if (PV.end() == false)
+      {
+	 // removed metapackages mark their dependencies as manual to prevent in "desktop depends browser, texteditor"
+	 // the removal of browser to suggest the removal of desktop and texteditor.
+	 // We ignore the auto-bit here as we can't deal with metapackage cascardes otherwise.
+	 // We do not check for or-groups here as we don't know which package takes care of
+	 // providing the feature the user likes e.g.:  browser1 | browser2 | browser3
+	 // Temporary removals are effected by this as well, which is bad, but unlikely in practice
+	 bool const PinNeverMarkAutoSection = (PV->Section != 0 && ConfigValueInSubTree("APT::Never-MarkAuto-Sections", PV.Section()));
+	 if (PinNeverMarkAutoSection)
+	 {
+	    for (DepIterator D = PV.DependsList(); D.end() != true; ++D)
+	    {
+	       if (D.IsMultiArchImplicit() == true || D.IsNegative() == true || IsImportantDep(D) == false)
+		  continue;
+
+	       pkgCacheFile CacheFile(this);
+	       APT::VersionList verlist = APT::VersionList::FromDependency(CacheFile, D, APT::CacheSetHelper::INSTALLED);
+	       for (auto const &V : verlist)
+	       {
+		  PkgIterator const DP = V.ParentPkg();
+		  if(DebugAutoInstall == true)
+		     std::clog << OutputInDepth(Depth) << "Setting " << DP.FullName(false) << " NOT as auto-installed (direct "
+			<< D.DepType() << " of " << Pkg.FullName(false) << " which is in APT::Never-MarkAuto-Sections)" << std::endl;
+
+		  MarkAuto(DP, false);
+	       }
+	    }
+	 }
+      }
+   }
+
    if (DebugMarker == true)
       std::clog << OutputInDepth(Depth) << (rPurge ? "MarkPurge " : "MarkDelete ") << Pkg << " FU=" << FromUser << std::endl;
 
@@ -947,7 +979,7 @@ bool pkgDepCache::IsModeChangeOk(ModeList const mode, PkgIterator const &Pkg,
 /* */
 struct CompareProviders {
    pkgCache::PkgIterator const Pkg;
-   CompareProviders(pkgCache::DepIterator const &Dep) : Pkg(Dep.TargetPkg()) {};
+   explicit CompareProviders(pkgCache::DepIterator const &Dep) : Pkg(Dep.TargetPkg()) {};
    //bool operator() (APT::VersionList::iterator const &AV, APT::VersionList::iterator const &BV)
    bool operator() (pkgCache::VerIterator const &AV, pkgCache::VerIterator const &BV)
    {
@@ -1095,7 +1127,28 @@ bool pkgDepCache::MarkInstall(PkgIterator const &Pkg,bool AutoInst,
    if (DebugMarker == true)
       std::clog << OutputInDepth(Depth) << "MarkInstall " << Pkg << " FU=" << FromUser << std::endl;
 
-   DepIterator Dep = P.InstVerIter(*this).DependsList();
+   bool MoveAutoBitToDependencies = false;
+   VerIterator const PV = P.InstVerIter(*this);
+   if (unlikely(PV.end() == true))
+      return false;
+   else if (PV->Section != 0 && (P.Flags & Flag::Auto) != Flag::Auto)
+   {
+      VerIterator const CurVer = Pkg.CurrentVer();
+      if (CurVer.end() == false && CurVer->Section != 0 && strcmp(CurVer.Section(), PV.Section()) != 0)
+      {
+	 bool const CurVerInMoveSection = ConfigValueInSubTree("APT::Move-Autobit-Sections", CurVer.Section());
+	 bool const InstVerInMoveSection = ConfigValueInSubTree("APT::Move-Autobit-Sections", PV.Section());
+	 MoveAutoBitToDependencies = (CurVerInMoveSection == false && InstVerInMoveSection == true);
+	 if (MoveAutoBitToDependencies == true)
+	 {
+	    if(DebugAutoInstall == true)
+	       std::clog << OutputInDepth(Depth) << "Setting " << Pkg.FullName(false) << " as auto-installed, moving manual to its dependencies" << std::endl;
+	    MarkAuto(Pkg, true);
+	 }
+      }
+   }
+
+   DepIterator Dep = PV.DependsList();
    for (; Dep.end() != true;)
    {
       // Grok or groups
@@ -1187,18 +1240,8 @@ bool pkgDepCache::MarkInstall(PkgIterator const &Pkg,bool AutoInst,
          fixing the problem for "positive" dependencies */
       if (Start.IsNegative() == false && (DepState[Start->ID] & DepCVer) == DepCVer)
       {
-	 APT::VersionList verlist;
-	 pkgCache::VerIterator Cand = PkgState[Start.TargetPkg()->ID].CandidateVerIter(*this);
-	 if (Cand.end() == false && Start.IsSatisfied(Cand) == true)
-	    verlist.insert(Cand);
-	 for (PrvIterator Prv = Start.TargetPkg().ProvidesList(); Prv.end() != true; ++Prv)
-	 {
-	    pkgCache::VerIterator V = Prv.OwnerVer();
-	    pkgCache::VerIterator Cand = PkgState[Prv.OwnerPkg()->ID].CandidateVerIter(*this);
-	    if (Cand.end() == true || V != Cand || Start.IsSatisfied(Prv) == false)
-	       continue;
-	    verlist.insert(Cand);
-	 }
+	 pkgCacheFile CacheFile(this);
+	 APT::VersionList verlist = APT::VersionList::FromDependency(CacheFile, Start, APT::CacheSetHelper::CANDIDATE);
 	 CompareProviders comp(Start);
 
 	 do {
@@ -1217,14 +1260,17 @@ bool pkgDepCache::MarkInstall(PkgIterator const &Pkg,bool AutoInst,
 	       verlist.erase(InstVer);
 	       continue;
 	    }
+
 	    // now check if we should consider it a automatic dependency or not
-	    if(InstPkg->CurrentVer == 0 && InstVer->Section != 0 && ConfigValueInSubTree("APT::Never-MarkAuto-Sections", InstVer.Section()))
+	    if(InstPkg->CurrentVer == 0 && MoveAutoBitToDependencies)
 	    {
 	       if(DebugAutoInstall == true)
-		  std::clog << OutputInDepth(Depth) << "Setting NOT as auto-installed (direct "
-                            << Start.DepType() << " of pkg in APT::Never-MarkAuto-Sections)" << std::endl;
+		  std::clog << OutputInDepth(Depth) << "Setting " << InstPkg.FullName(false) << " NOT as auto-installed (direct "
+		     << Start.DepType() << " of " << Pkg.FullName(false) << " which is manual and in APT::Move-Autobit-Sections)" << std::endl;
 	       MarkAuto(InstPkg, false);
 	    }
+
+
 	    break;
 	 } while(true);
 	 continue;
@@ -1234,9 +1280,9 @@ bool pkgDepCache::MarkInstall(PkgIterator const &Pkg,bool AutoInst,
 	 Otherwise we remove the offender if needed */
       else if (Start.IsNegative() == true && Start->Type != pkgCache::Dep::Obsoletes)
       {
-	 SPtrArray<Version *> List = Start.AllTargets();
+	 std::unique_ptr<Version *[]> List(Start.AllTargets());
 	 pkgCache::PkgIterator TrgPkg = Start.TargetPkg();
-	 for (Version **I = List; *I != 0; I++)
+	 for (Version **I = List.get(); *I != 0; I++)
 	 {
 	    VerIterator Ver(*this,*I);
 	    PkgIterator Pkg = Ver.ParentPkg();
@@ -1662,10 +1708,10 @@ const char *pkgDepCache::StateCache::StripEpoch(const char *Ver)
       return 0;
 
    // Strip any epoch
-   for (const char *I = Ver; *I != 0; I++)
-      if (*I == ':')
-	 return I + 1;
-   return Ver;
+   char const * const I = strchr(Ver, ':');
+   if (I == nullptr)
+      return Ver;
+   return I + 1;
 }
 									/*}}}*/
 // Policy::GetCandidateVer - Returns the Candidate install version	/*{{{*/
@@ -1685,13 +1731,13 @@ pkgCache::VerIterator pkgDepCache::Policy::GetCandidateVer(PkgIterator const &Pk
       
       for (VerFileIterator J = I.FileList(); J.end() == false; ++J)
       {
-	 if ((J.File()->Flags & Flag::NotSource) != 0)
+	 if (J.File().Flagged(Flag::NotSource))
 	    continue;
 
 	 /* Stash the highest version of a not-automatic source, we use it
 	    if there is nothing better */
-	 if ((J.File()->Flags & Flag::NotAutomatic) != 0 ||
-	     (J.File()->Flags & Flag::ButAutomaticUpgrades) != 0)
+	 if (J.File().Flagged(Flag::NotAutomatic) ||
+	     J.File().Flagged(Flag::ButAutomaticUpgrades))
 	 {
 	    if (Last.end() == true)
 	       Last = I;
@@ -1708,17 +1754,17 @@ pkgCache::VerIterator pkgDepCache::Policy::GetCandidateVer(PkgIterator const &Pk
 // Policy::IsImportantDep - True if the dependency is important		/*{{{*/
 // ---------------------------------------------------------------------
 /* */
-bool pkgDepCache::Policy::IsImportantDep(DepIterator const &Dep)
+bool pkgDepCache::Policy::IsImportantDep(DepIterator const &Dep) const
 {
    if(Dep.IsCritical())
       return true;
-   else if(Dep->Type == pkgCache::Dep::Recommends) 
+   else if(Dep->Type == pkgCache::Dep::Recommends)
    {
       if (InstallRecommends)
 	 return true;
       // we suport a special mode to only install-recommends for certain
       // sections
-      // FIXME: this is a meant as a temporarly solution until the 
+      // FIXME: this is a meant as a temporarly solution until the
       //        recommends are cleaned up
       const char *sec = Dep.ParentVer().Section();
       if (sec && ConfigValueInSubTree("APT::Install-Recommends-Sections", sec))
@@ -1733,6 +1779,8 @@ bool pkgDepCache::Policy::IsImportantDep(DepIterator const &Dep)
 // Policy::GetPriority - Get the priority of the package pin		/*{{{*/
 APT_CONST signed short pkgDepCache::Policy::GetPriority(pkgCache::PkgIterator const &/*Pkg*/)
 { return 0; }
+APT_CONST signed short pkgDepCache::Policy::GetPriority(pkgCache::VerIterator const &/*Ver*/, bool /*ConsiderFiles*/)
+{ return 0; }
 APT_CONST signed short pkgDepCache::Policy::GetPriority(pkgCache::PkgFileIterator const &/*File*/)
 { return 0; }
 									/*}}}*/
@@ -1764,24 +1812,22 @@ bool pkgDepCache::MarkRequired(InRootSetFunc &userFunc)
    if (_config->Find("APT::Solver", "internal") != "internal")
       return true;
 
-   bool follow_recommends;
-   bool follow_suggests;
-   bool debug_autoremove = _config->FindB("Debug::pkgAutoRemove",false);
+   bool const debug_autoremove = _config->FindB("Debug::pkgAutoRemove",false);
 
    // init the states
-   for(PkgIterator p = PkgBegin(); !p.end(); ++p)
+   map_id_t const PackagesCount = Head().PackageCount;
+   for(map_id_t i = 0; i < PackagesCount; ++i)
    {
-      PkgState[p->ID].Marked  = false;
-      PkgState[p->ID].Garbage = false;
-
-      // debug output
-      if(debug_autoremove && PkgState[p->ID].Flags & Flag::Auto)
-  	 std::clog << "AutoDep: " << p.FullName() << std::endl;
+      PkgState[i].Marked  = false;
+      PkgState[i].Garbage = false;
    }
+   if (debug_autoremove)
+      for(PkgIterator p = PkgBegin(); !p.end(); ++p)
+	 if(PkgState[p->ID].Flags & Flag::Auto)
+	    std::clog << "AutoDep: " << p.FullName() << std::endl;
 
-   // init vars
-   follow_recommends = MarkFollowsRecommends();
-   follow_suggests   = MarkFollowsSuggests();
+   bool const follow_recommends = MarkFollowsRecommends();
+   bool const follow_suggests   = MarkFollowsSuggests();
 
    // do the mark part, this is the core bit of the algorithm
    for(PkgIterator p = PkgBegin(); !p.end(); ++p)
@@ -1965,7 +2011,7 @@ bool pkgDepCache::MarkAndSweep(InRootSetFunc &rootFunc)
 }
 bool pkgDepCache::MarkAndSweep()
 {
-   std::auto_ptr<InRootSetFunc> f(GetRootSetFunc());
+   std::unique_ptr<InRootSetFunc> f(GetRootSetFunc());
    if(f.get() != NULL)
       return MarkAndSweep(*f.get());
    else

+ 22 - 19
apt-pkg/depcache.h

@@ -1,6 +1,5 @@
 // -*- mode: c++; mode: fold -*-
 // Description								/*{{{*/
-// $Id: depcache.h,v 1.14 2001/02/20 07:03:17 jgg Exp $
 /* ######################################################################
 
    DepCache - Dependency Extension data for the cache
@@ -164,6 +163,7 @@ class pkgDepCache : protected pkgCache::Namespace
     */
    class ActionGroup
    {
+       void * const d;
        pkgDepCache &cache;
 
        bool released;
@@ -179,7 +179,7 @@ class pkgDepCache : protected pkgCache::Namespace
 	*  As long as this object exists, no automatic cleanup
 	*  operations will be undertaken.
 	*/
-       ActionGroup(pkgDepCache &cache);
+       explicit ActionGroup(pkgDepCache &cache);
 
        /** \brief Clean up the action group before it is destroyed.
         *
@@ -192,7 +192,7 @@ class pkgDepCache : protected pkgCache::Namespace
 	*  If this is the last action group, the automatic cache
 	*  cleanup operations will be undertaken.
 	*/
-       ~ActionGroup();
+       virtual ~ActionGroup();
    };
 
    /** \brief Returns \b true for packages matching a regular
@@ -204,7 +204,7 @@ class pkgDepCache : protected pkgCache::Namespace
      DefaultRootSetFunc() : Configuration::MatchAgainstConfig("APT::NeverAutoRemove") {};
      virtual ~DefaultRootSetFunc() {};
 
-     bool InRootSet(const pkgCache::PkgIterator &pkg) { return pkg.end() == false && Match(pkg.Name()); };
+     bool InRootSet(const pkgCache::PkgIterator &pkg) APT_OVERRIDE { return pkg.end() == false && Match(pkg.Name()); };
    };
 
    struct StateCache
@@ -250,7 +250,7 @@ class pkgDepCache : protected pkgCache::Namespace
       inline bool Keep() const {return Mode == ModeKeep;};
       inline bool Protect() const {return (iFlags & Protected) == Protected;};
       inline bool Upgrade() const {return Status > 0 && Mode == ModeInstall;};
-      inline bool Upgradable() const {return Status >= 1;};
+      inline bool Upgradable() const {return Status >= 1 && CandidateVer != NULL;};
       inline bool Downgrade() const {return Status < 0 && Mode == ModeInstall;};
       inline bool Held() const {return Status != 0 && Keep();};
       inline bool NowBroken() const {return (DepState & DepNowMin) != DepNowMin;};
@@ -267,7 +267,7 @@ class pkgDepCache : protected pkgCache::Namespace
    
    // Helper functions
    void BuildGroupOrs(VerIterator const &V);
-   void UpdateVerState(PkgIterator Pkg);
+   void UpdateVerState(PkgIterator const &Pkg);
 
    // User Policy control
    class Policy
@@ -279,8 +279,9 @@ class pkgDepCache : protected pkgCache::Namespace
       }
 
       virtual VerIterator GetCandidateVer(PkgIterator const &Pkg);
-      virtual bool IsImportantDep(DepIterator const &Dep);
+      virtual bool IsImportantDep(DepIterator const &Dep) const;
       virtual signed short GetPriority(PkgIterator const &Pkg);
+      virtual signed short GetPriority(VerIterator const &Ver, bool ConsiderFiles=true);
       virtual signed short GetPriority(PkgFileIterator const &File);
 
       virtual ~Policy() {};
@@ -323,18 +324,18 @@ class pkgDepCache : protected pkgCache::Namespace
    Policy *LocalPolicy;
    
    // Check for a matching provides
-   bool CheckDep(DepIterator Dep,int Type,PkgIterator &Res);
-   inline bool CheckDep(DepIterator Dep,int Type)
+   bool CheckDep(DepIterator const &Dep,int const Type,PkgIterator &Res);
+   inline bool CheckDep(DepIterator const &Dep,int const Type)
    {
       PkgIterator Res(*this,0);
       return CheckDep(Dep,Type,Res);
    }
    
    // Computes state information for deps and versions (w/o storing)
-   unsigned char DependencyState(DepIterator &D);
-   unsigned char VersionState(DepIterator D,unsigned char Check,
-			      unsigned char SetMin,
-			      unsigned char SetPolicy);
+   unsigned char DependencyState(DepIterator const &D);
+   unsigned char VersionState(DepIterator D,unsigned char const Check,
+			      unsigned char const SetMin,
+			      unsigned char const SetPolicy) const;
 
    // Recalculates various portions of the cache, call after changing something
    void Update(DepIterator Dep);           // Mostly internal
@@ -362,7 +363,7 @@ class pkgDepCache : protected pkgCache::Namespace
    
    // Policy implementation
    inline VerIterator GetCandidateVer(PkgIterator const &Pkg) {return LocalPolicy->GetCandidateVer(Pkg);};
-   inline bool IsImportantDep(DepIterator Dep) {return LocalPolicy->IsImportantDep(Dep);};
+   inline bool IsImportantDep(DepIterator Dep) const {return LocalPolicy->IsImportantDep(Dep);};
    inline Policy &GetPolicy() {return *LocalPolicy;};
    
    // Accessors
@@ -471,8 +472,8 @@ class pkgDepCache : protected pkgCache::Namespace
 			    unsigned long Depth = 0, bool FromUser = true);
 
    // read persistent states
-   bool readStateFile(OpProgress *prog);
-   bool writeStateFile(OpProgress *prog, bool InstalledOnly=true);
+   bool readStateFile(OpProgress * const prog);
+   bool writeStateFile(OpProgress * const prog, bool const InstalledOnly=true);
    
    // Size queries
    inline signed long long UsrSize() {return iUsrSize;};
@@ -484,11 +485,11 @@ class pkgDepCache : protected pkgCache::Namespace
    inline unsigned long PolicyBrokenCount() {return iPolicyBrokenCount;};
    inline unsigned long BadCount() {return iBadCount;};
 
-   bool Init(OpProgress *Prog);
+   bool Init(OpProgress * const Prog);
    // Generate all state information
-   void Update(OpProgress *Prog = 0);
+   void Update(OpProgress * const Prog = 0);
 
-   pkgDepCache(pkgCache *Cache,Policy *Plcy = 0);
+   pkgDepCache(pkgCache * const Cache,Policy * const Plcy = 0);
    virtual ~pkgDepCache();
 
    protected:
@@ -503,6 +504,8 @@ class pkgDepCache : protected pkgCache::Namespace
 	 bool const rPurge, unsigned long const Depth, bool const FromUser);
 
    private:
+   void * const d;
+
    APT_HIDDEN bool IsModeChangeOk(ModeList const mode, PkgIterator const &Pkg,
 			unsigned long const Depth, bool const FromUser);
 };

+ 71 - 83
apt-pkg/edsp.cc

@@ -7,31 +7,25 @@
 // Include Files							/*{{{*/
 #include <config.h>
 
-#include <apt-pkg/edsp.h>
 #include <apt-pkg/error.h>
 #include <apt-pkg/cacheset.h>
-#include <apt-pkg/configuration.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/progress.h>
+#include <apt-pkg/fileutl.h>
+#include <apt-pkg/edsp.h>
+#include <apt-pkg/tagfile.h>
 #include <apt-pkg/strutl.h>
-#include <apt-pkg/pkgrecords.h>
 
 #include <ctype.h>
 #include <stddef.h>
 #include <string.h>
-#include <time.h>
 #include <unistd.h>
 #include <stdio.h>
-#include <algorithm>
 #include <iostream>
-#include <vector>
 #include <limits>
 #include <string>
-#include <list>
 
 #include <apti18n.h>
 									/*}}}*/
@@ -39,71 +33,19 @@
 using std::string;
 
 // we could use pkgCache::DepType and ::Priority, but these would be localized strings…
-const char * const EDSP::PrioMap[] = {0, "important", "required", "standard",
+const char * const PrioMap[] = {0, "important", "required", "standard",
 				      "optional", "extra"};
-const char * const EDSP::DepMap[] = {"", "Depends", "Pre-Depends", "Suggests",
+const char * const DepMap[] = {"", "Depends", "Pre-Depends", "Suggests",
 				     "Recommends" , "Conflicts", "Replaces",
 				     "Obsoletes", "Breaks", "Enhances"};
 
-// EDSP::WriteScenario - to the given file descriptor			/*{{{*/
-bool EDSP::WriteScenario(pkgDepCache &Cache, FILE* output, OpProgress *Progress)
-{
-   if (Progress != NULL)
-      Progress->SubProgress(Cache.Head().VersionCount, _("Send scenario to solver"));
-   unsigned long p = 0;
-   std::vector<std::string> archs = APT::Configuration::getArchitectures();
-   for (pkgCache::PkgIterator Pkg = Cache.PkgBegin(); Pkg.end() == false; ++Pkg)
-   {
-      std::string const arch = Pkg.Arch();
-      if (std::find(archs.begin(), archs.end(), arch) == archs.end())
-	 continue;
-      for (pkgCache::VerIterator Ver = Pkg.VersionList(); Ver.end() == false; ++Ver, ++p)
-      {
-	 WriteScenarioVersion(Cache, output, Pkg, Ver);
-	 WriteScenarioDependency(output, Ver);
-	 fprintf(output, "\n");
-	 if (Progress != NULL && p % 100 == 0)
-	    Progress->Progress(p);
-      }
-   }
-   return true;
-}
-									/*}}}*/
-// EDSP::WriteLimitedScenario - to the given file descriptor		/*{{{*/
-bool EDSP::WriteLimitedScenario(pkgDepCache &Cache, FILE* output,
-				APT::PackageSet const &pkgset,
-				OpProgress *Progress)
-{
-   if (Progress != NULL)
-      Progress->SubProgress(Cache.Head().VersionCount, _("Send scenario to solver"));
-   unsigned long p  = 0;
-   for (APT::PackageSet::const_iterator Pkg = pkgset.begin(); Pkg != pkgset.end(); ++Pkg, ++p)
-      for (pkgCache::VerIterator Ver = Pkg.VersionList(); Ver.end() == false; ++Ver)
-      {
-	 WriteScenarioVersion(Cache, output, Pkg, Ver);
-	 WriteScenarioLimitedDependency(output, Ver, pkgset);
-	 fprintf(output, "\n");
-	 if (Progress != NULL && p % 100 == 0)
-	    Progress->Progress(p);
-      }
-   if (Progress != NULL)
-      Progress->Done();
-   return true;
-}
-									/*}}}*/
-// EDSP::WriteScenarioVersion						/*{{{*/
-void EDSP::WriteScenarioVersion(pkgDepCache &Cache, FILE* output, pkgCache::PkgIterator const &Pkg,
+
+// WriteScenarioVersion							/*{{{*/
+static void WriteScenarioVersion(pkgDepCache &Cache, FILE* output, pkgCache::PkgIterator const &Pkg,
 				pkgCache::VerIterator const &Ver)
 {
    fprintf(output, "Package: %s\n", Pkg.Name());
-#if APT_PKG_ABI >= 413
    fprintf(output, "Source: %s\n", Ver.SourcePkgName());
-#else
-   pkgRecords Recs(Cache);
-   pkgRecords::Parser &rec = Recs.Lookup(Ver.FileList());
-   string srcpkg = rec.SourcePkg().empty() ? Pkg.Name() : rec.SourcePkg();
-   fprintf(output, "Source: %s\n", srcpkg.c_str());
-#endif
    fprintf(output, "Architecture: %s\n", Ver.Arch());
    fprintf(output, "Version: %s\n", Ver.VerStr());
    if (Pkg.CurrentVer() == Ver)
@@ -129,7 +71,7 @@ void EDSP::WriteScenarioVersion(pkgDepCache &Cache, FILE* output, pkgCache::PkgI
       signed short const p = Cache.GetPolicy().GetPriority(File);
       if (Pin < p)
 	 Pin = p;
-      if ((File->Flags & pkgCache::Flag::NotSource) != pkgCache::Flag::NotSource) {
+      if (File.Flagged(pkgCache::Flag::NotSource) == false) {
 	 string Release = File.RelStr();
 	 if (!Release.empty())
 	    Releases.insert(Release);
@@ -147,18 +89,18 @@ void EDSP::WriteScenarioVersion(pkgDepCache &Cache, FILE* output, pkgCache::PkgI
       fprintf(output, "APT-Automatic: yes\n");
 }
 									/*}}}*/
-// EDSP::WriteScenarioDependency					/*{{{*/
-void EDSP::WriteScenarioDependency( FILE* output, pkgCache::VerIterator const &Ver)
+// WriteScenarioDependency						/*{{{*/
+static void WriteScenarioDependency( FILE* output, pkgCache::VerIterator const &Ver)
 {
    std::string dependencies[pkgCache::Dep::Enhances + 1];
    bool orGroup = false;
    for (pkgCache::DepIterator Dep = Ver.DependsList(); Dep.end() == false; ++Dep)
    {
-      if (Dep.IsMultiArchImplicit() == true)
+      if (Dep.IsImplicit() == true)
 	 continue;
       if (orGroup == false)
 	 dependencies[Dep->Type].append(", ");
-      dependencies[Dep->Type].append(Dep.TargetPkg().Name());
+      dependencies[Dep->Type].append(Dep.TargetPkg().FullName((Dep->CompareOp & pkgCache::Dep::ArchSpecific) != pkgCache::Dep::ArchSpecific));
       if (Dep->Version != 0)
 	 dependencies[Dep->Type].append(" (").append(pkgCache::CompTypeDeb(Dep->CompareOp)).append(" ").append(Dep.TargetVer()).append(")");
       if ((Dep->CompareOp & pkgCache::Dep::Or) == pkgCache::Dep::Or)
@@ -183,8 +125,8 @@ void EDSP::WriteScenarioDependency( FILE* output, pkgCache::VerIterator const &V
       fprintf(output, "Provides: %s\n", provides.c_str()+2);
 }
 									/*}}}*/
-// EDSP::WriteScenarioLimitedDependency					/*{{{*/
-void EDSP::WriteScenarioLimitedDependency(FILE* output,
+// WriteScenarioLimitedDependency					/*{{{*/
+static void WriteScenarioLimitedDependency(FILE* output,
 					  pkgCache::VerIterator const &Ver,
 					  APT::PackageSet const &pkgset)
 {
@@ -192,7 +134,7 @@ void EDSP::WriteScenarioLimitedDependency(FILE* output,
    bool orGroup = false;
    for (pkgCache::DepIterator Dep = Ver.DependsList(); Dep.end() == false; ++Dep)
    {
-      if (Dep.IsMultiArchImplicit() == true)
+      if (Dep.IsImplicit() == true)
 	 continue;
       if (orGroup == false)
       {
@@ -208,7 +150,7 @@ void EDSP::WriteScenarioLimitedDependency(FILE* output,
 	 orGroup = false;
 	 continue;
       }
-      dependencies[Dep->Type].append(Dep.TargetPkg().Name());
+      dependencies[Dep->Type].append(Dep.TargetPkg().FullName((Dep->CompareOp & pkgCache::Dep::ArchSpecific) != pkgCache::Dep::ArchSpecific));
       if (Dep->Version != 0)
 	 dependencies[Dep->Type].append(" (").append(pkgCache::CompTypeDeb(Dep->CompareOp)).append(" ").append(Dep.TargetVer()).append(")");
       if ((Dep->CompareOp & pkgCache::Dep::Or) == pkgCache::Dep::Or)
@@ -235,6 +177,52 @@ void EDSP::WriteScenarioLimitedDependency(FILE* output,
       fprintf(output, "Provides: %s\n", provides.c_str()+2);
 }
 									/*}}}*/
+// EDSP::WriteScenario - to the given file descriptor			/*{{{*/
+bool EDSP::WriteScenario(pkgDepCache &Cache, FILE* output, OpProgress *Progress)
+{
+   if (Progress != NULL)
+      Progress->SubProgress(Cache.Head().VersionCount, _("Send scenario to solver"));
+   unsigned long p = 0;
+   std::vector<std::string> archs = APT::Configuration::getArchitectures();
+   for (pkgCache::PkgIterator Pkg = Cache.PkgBegin(); Pkg.end() == false; ++Pkg)
+   {
+      std::string const arch = Pkg.Arch();
+      if (std::find(archs.begin(), archs.end(), arch) == archs.end())
+	 continue;
+      for (pkgCache::VerIterator Ver = Pkg.VersionList(); Ver.end() == false; ++Ver, ++p)
+      {
+	 WriteScenarioVersion(Cache, output, Pkg, Ver);
+	 WriteScenarioDependency(output, Ver);
+	 fprintf(output, "\n");
+	 if (Progress != NULL && p % 100 == 0)
+	    Progress->Progress(p);
+      }
+   }
+   return true;
+}
+									/*}}}*/
+// EDSP::WriteLimitedScenario - to the given file descriptor		/*{{{*/
+bool EDSP::WriteLimitedScenario(pkgDepCache &Cache, FILE* output,
+				APT::PackageSet const &pkgset,
+				OpProgress *Progress)
+{
+   if (Progress != NULL)
+      Progress->SubProgress(Cache.Head().VersionCount, _("Send scenario to solver"));
+   unsigned long p  = 0;
+   for (APT::PackageSet::const_iterator Pkg = pkgset.begin(); Pkg != pkgset.end(); ++Pkg, ++p)
+      for (pkgCache::VerIterator Ver = Pkg.VersionList(); Ver.end() == false; ++Ver)
+      {
+	 WriteScenarioVersion(Cache, output, Pkg, Ver);
+	 WriteScenarioLimitedDependency(output, Ver, pkgset);
+	 fprintf(output, "\n");
+	 if (Progress != NULL && p % 100 == 0)
+	    Progress->Progress(p);
+      }
+   if (Progress != NULL)
+      Progress->Done();
+   return true;
+}
+									/*}}}*/
 // EDSP::WriteRequest - to the given file descriptor			/*{{{*/
 bool EDSP::WriteRequest(pkgDepCache &Cache, FILE* output, bool const Upgrade,
 			bool const DistUpgrade, bool const AutoRemove,
@@ -365,13 +353,13 @@ bool EDSP::ReadResponse(int const input, pkgDepCache &Cache, OpProgress *Progres
 	return true;
 }
 									/*}}}*/
-// EDSP::ReadLine - first line from the given file descriptor		/*{{{*/
+// ReadLine - first line from the given file descriptor			/*{{{*/
 // ---------------------------------------------------------------------
 /* Little helper method to read a complete line into a string. Similar to
    fgets but we need to use the low-level read() here as otherwise the
    listparser will be confused later on as mixing of fgets and read isn't
    a supported action according to the manpages and results are undefined */
-bool EDSP::ReadLine(int const input, std::string &line) {
+static bool ReadLine(int const input, std::string &line) {
 	char one;
 	ssize_t data = 0;
 	line.erase();
@@ -390,11 +378,11 @@ bool EDSP::ReadLine(int const input, std::string &line) {
 	return false;
 }
 									/*}}}*/
-// EDSP::StringToBool - convert yes/no to bool				/*{{{*/
+// StringToBool - convert yes/no to bool				/*{{{*/
 // ---------------------------------------------------------------------
 /* we are not as lazy as we are in the global StringToBool as we really
    only accept yes/no here - but we will ignore leading spaces */
-bool EDSP::StringToBool(char const *answer, bool const defValue) {
+static bool StringToBool(char const *answer, bool const defValue) {
    for (; isspace(*answer) != 0; ++answer);
    if (strncasecmp(answer, "yes", 3) == 0)
       return true;
@@ -443,11 +431,11 @@ bool EDSP::ReadRequest(int const input, std::list<std::string> &install,
 	    request = &remove;
 	 }
 	 else if (line.compare(0, 8, "Upgrade:") == 0)
-	    upgrade = EDSP::StringToBool(line.c_str() + 9, false);
+	    upgrade = StringToBool(line.c_str() + 9, false);
 	 else if (line.compare(0, 13, "Dist-Upgrade:") == 0)
-	    distUpgrade = EDSP::StringToBool(line.c_str() + 14, false);
+	    distUpgrade = StringToBool(line.c_str() + 14, false);
 	 else if (line.compare(0, 11, "Autoremove:") == 0)
-	    autoRemove = EDSP::StringToBool(line.c_str() + 12, false);
+	    autoRemove = StringToBool(line.c_str() + 12, false);
 	 else if (line.compare(0, 13, "Architecture:") == 0)
 	    _config->Set("APT::Architecture", line.c_str() + 14);
 	 else if (line.compare(0, 14, "Architectures:") == 0)

+ 14 - 30
apt-pkg/edsp.h

@@ -27,24 +27,8 @@
 class pkgDepCache;
 class OpProgress;
 
-class EDSP								/*{{{*/
+namespace EDSP								/*{{{*/
 {
-	// we could use pkgCache::DepType and ::Priority, but these would be localized strings…
-	static const char * const PrioMap[];
-	static const char * const DepMap[];
-
-	APT_HIDDEN bool static ReadLine(int const input, std::string &line);
-	APT_HIDDEN bool static StringToBool(char const *answer, bool const defValue);
-
-	APT_HIDDEN void static WriteScenarioVersion(pkgDepCache &Cache, FILE* output,
-					 pkgCache::PkgIterator const &Pkg,
-					 pkgCache::VerIterator const &Ver);
-	APT_HIDDEN void static WriteScenarioDependency(FILE* output,
-					    pkgCache::VerIterator const &Ver);
-	APT_HIDDEN void static WriteScenarioLimitedDependency(FILE* output,
-						   pkgCache::VerIterator const &Ver,
-						   APT::PackageSet const &pkgset);
-public:
 	/** \brief creates the EDSP request stanza
 	 *
 	 *  In the EDSP protocol the first thing send to the resolver is a stanza
@@ -61,7 +45,7 @@ public:
 	 *
 	 *  \return true if request was composed successfully, otherwise false
 	 */
-	bool static WriteRequest(pkgDepCache &Cache, FILE* output,
+	bool WriteRequest(pkgDepCache &Cache, FILE* output,
 				 bool const upgrade = false,
 				 bool const distUpgrade = false,
 				 bool const autoRemove = false,
@@ -84,7 +68,7 @@ public:
 	 *
 	 *  \return true if universe was composed successfully, otherwise false
 	 */
-	bool static WriteScenario(pkgDepCache &Cache, FILE* output, OpProgress *Progress = NULL);
+	bool WriteScenario(pkgDepCache &Cache, FILE* output, OpProgress *Progress = NULL);
 
 	/** \brief creates a limited scenario representing the package universe
 	 *
@@ -101,7 +85,7 @@ public:
 	 *
 	 *  \return true if universe was composed successfully, otherwise false
 	 */
-	bool static WriteLimitedScenario(pkgDepCache &Cache, FILE* output,
+	bool WriteLimitedScenario(pkgDepCache &Cache, FILE* output,
 					 APT::PackageSet const &pkgset,
 					 OpProgress *Progress = NULL);
 
@@ -118,7 +102,7 @@ public:
 	 *
 	 *  \return true if a solution is found and applied correctly, otherwise false
 	 */
-	bool static ReadResponse(int const input, pkgDepCache &Cache, OpProgress *Progress = NULL);
+	bool ReadResponse(int const input, pkgDepCache &Cache, OpProgress *Progress = NULL);
 
 	/** \brief search and read the request stanza for action later
 	 *
@@ -136,7 +120,7 @@ public:
 	 *
 	 *  \return true if the request could be found and worked on, otherwise false
 	 */
-	bool static ReadRequest(int const input, std::list<std::string> &install,
+	bool ReadRequest(int const input, std::list<std::string> &install,
 			std::list<std::string> &remove, bool &upgrade,
 			bool &distUpgrade, bool &autoRemove);
 
@@ -152,7 +136,7 @@ public:
 	 *
 	 *  \return false if the request couldn't be applied, true otherwise
 	 */
-	bool static ApplyRequest(std::list<std::string> const &install,
+	bool ApplyRequest(std::list<std::string> const &install,
 				 std::list<std::string> const &remove,
 				 pkgDepCache &Cache);
 
@@ -168,7 +152,7 @@ public:
 	 *
 	 *  \return true if solution could be written, otherwise false
 	 */
-	bool static WriteSolution(pkgDepCache &Cache, FILE* output);
+	bool WriteSolution(pkgDepCache &Cache, FILE* output);
 
 	/** \brief sends a progress report
 	 *
@@ -176,7 +160,7 @@ public:
 	 *  \param message the solver wants the user to see
 	 *  \param output the front-end listens for progress report
 	 */
-	bool static WriteProgress(unsigned short const percent, const char* const message, FILE* output);
+	bool WriteProgress(unsigned short const percent, const char* const message, FILE* output);
 
 	/** \brief sends an error report
 	 *
@@ -193,7 +177,7 @@ public:
 	 *  \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);
+	bool WriteError(char const * const uuid, std::string const &message, FILE* output);
 
 
 	/** \brief executes the given solver and returns the pipe ends
@@ -207,8 +191,8 @@ public:
 	 *
 	 *  \return PID of the started solver or 0 if failure occurred
 	 */
-	pid_t static ExecuteSolver(const char* const solver, int * const solver_in, int * const solver_out, bool /*overload*/);
-	APT_DEPRECATED bool static ExecuteSolver(const char* const solver, int *solver_in, int *solver_out);
+	pid_t ExecuteSolver(const char* const solver, int * const solver_in, int * const solver_out, bool /*overload*/);
+	APT_DEPRECATED bool ExecuteSolver(const char* const solver, int *solver_in, int *solver_out);
 
 	/** \brief call an external resolver to handle the request
 	 *
@@ -224,9 +208,9 @@ public:
 	 *  \return true if the solver has successfully solved the problem,
 	 *  otherwise false
 	 */
-	bool static ResolveExternal(const char* const solver, pkgDepCache &Cache,
+	bool ResolveExternal(const char* const solver, pkgDepCache &Cache,
 				    bool const upgrade, bool const distUpgrade,
 				    bool const autoRemove, OpProgress *Progress = NULL);
-};
+}
 									/*}}}*/
 #endif

+ 43 - 40
apt-pkg/edsp/edspindexfile.cc

@@ -12,13 +12,8 @@
 #include <apt-pkg/edsplistparser.h>
 #include <apt-pkg/error.h>
 #include <apt-pkg/fileutl.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 <stddef.h>
@@ -26,59 +21,67 @@
 #include <string>
 									/*}}}*/
 
-// edspIndex::edspIndex - Constructor					/*{{{*/
-// ---------------------------------------------------------------------
-/* */
-edspIndex::edspIndex(std::string File) : debStatusIndex(File)
+// EDSP Index								/*{{{*/
+edspIndex::edspIndex(std::string const &File) : pkgDebianIndexRealFile(File, true), d(NULL)
 {
 }
-									/*}}}*/
-// StatusIndex::Merge - Load the index file into a cache		/*{{{*/
-bool edspIndex::Merge(pkgCacheGenerator &Gen,OpProgress *Prog) const
+std::string edspIndex::GetComponent() const
+{
+   return "edsp";
+}
+std::string edspIndex::GetArchitecture() const
+{
+   return std::string();
+}
+bool edspIndex::HasPackages() const
+{
+   return true;
+}
+bool edspIndex::Exists() const
 {
-   FileFd Pkg;
-   if (File != "stdin")
-      Pkg.Open(File, FileFd::ReadOnly);
-   else
-      Pkg.OpenDescriptor(STDIN_FILENO, FileFd::ReadOnly);
-   if (_error->PendingError() == true)
-      return false;
-   edspListParser Parser(&Pkg);
-   if (_error->PendingError() == true)
-      return false;
-
-   if (Prog != NULL)
-      Prog->SubProgress(0,File);
-   if (Gen.SelectFile(File,std::string(),*this) == false)
-      return _error->Error("Problem with SelectFile %s",File.c_str());
-
-   // Store the IMS information
-   pkgCache::PkgFileIterator CFile = Gen.GetCurFile();
-   CFile->Size = Pkg.FileSize();
-   CFile->mtime = Pkg.ModificationTime();
-   map_stringitem_t const storage = Gen.StoreString(pkgCacheGenerator::MIXED, "edsp::scenario");
-   CFile->Archive = storage;
-
-   if (Gen.MergeList(Parser) == false)
-      return _error->Error("Problem with MergeList %s",File.c_str());
    return true;
+}
+uint8_t edspIndex::GetIndexFlags() const
+{
+   return 0;
+}
+bool edspIndex::OpenListFile(FileFd &Pkg, std::string const &FileName)
+{
+   if (FileName.empty() == false && FileName != "stdin")
+      return pkgDebianIndexRealFile::OpenListFile(Pkg, FileName);
+   if (Pkg.OpenDescriptor(STDIN_FILENO, FileFd::ReadOnly) == false)
+      return _error->Error("Problem opening %s",FileName.c_str());
+   return true;
+}
+pkgCacheListParser * edspIndex::CreateListParser(FileFd &Pkg)
+{
+   if (Pkg.IsOpen() == false)
+      return NULL;
+   _error->PushToStack();
+   pkgCacheListParser * const Parser = new edspListParser(&Pkg);
+   bool const newError = _error->PendingError();
+   _error->MergeWithStack();
+   return newError ? NULL : Parser;
 }
 									/*}}}*/
+
 // Index File types for APT						/*{{{*/
 class APT_HIDDEN edspIFType: public pkgIndexFile::Type
 {
    public:
-   virtual pkgRecords::Parser *CreatePkgParser(pkgCache::PkgFileIterator) const
+   virtual pkgRecords::Parser *CreatePkgParser(pkgCache::PkgFileIterator const &) const APT_OVERRIDE
    {
       // we don't have a record parser for this type as the file is not presistent
       return NULL;
    };
    edspIFType() {Label = "EDSP scenario file";};
 };
-APT_HIDDEN edspIFType _apt_Universe;
+APT_HIDDEN edspIFType _apt_Edsp;
 
 const pkgIndexFile::Type *edspIndex::GetType() const
 {
-   return &_apt_Universe;
+   return &_apt_Edsp;
 }
 									/*}}}*/
+
+edspIndex::~edspIndex() {}

+ 17 - 10
apt-pkg/edsp/edspindexfile.h

@@ -18,18 +18,25 @@
 class OpProgress;
 class pkgCacheGenerator;
 
-class APT_HIDDEN edspIndex : public debStatusIndex
+class APT_HIDDEN edspIndex : public pkgDebianIndexRealFile
 {
    /** \brief dpointer placeholder (for later in case we need it) */
-   void *d;
-
-   public:
-
-   virtual const Type *GetType() const APT_CONST;
-
-   virtual bool Merge(pkgCacheGenerator &Gen,OpProgress *Prog) const;
-
-   edspIndex(std::string File);
+   void * const d;
+
+protected:
+   APT_HIDDEN virtual pkgCacheListParser * CreateListParser(FileFd &Pkg) APT_OVERRIDE;
+   virtual bool OpenListFile(FileFd &Pkg, std::string const &File) APT_OVERRIDE;
+   virtual uint8_t GetIndexFlags() const APT_OVERRIDE;
+   virtual std::string GetComponent() const APT_OVERRIDE;
+   virtual std::string GetArchitecture() const APT_OVERRIDE;
+public:
+
+   virtual const Type *GetType() const APT_OVERRIDE APT_CONST;
+   virtual bool Exists() const APT_OVERRIDE;
+   virtual bool HasPackages() const APT_OVERRIDE;
+
+   edspIndex(std::string const &File);
+   virtual ~edspIndex();
 };
 
 #endif

+ 5 - 4
apt-pkg/edsp/edsplistparser.cc

@@ -18,11 +18,10 @@
 #include <apt-pkg/cacheiterators.h>
 #include <apt-pkg/tagfile.h>
 
-#include <string>
 									/*}}}*/
 
 // ListParser::edspListParser - Constructor				/*{{{*/
-edspListParser::edspListParser(FileFd *File, std::string const &Arch) : debListParser(File, Arch)
+edspListParser::edspListParser(FileFd *File) : debListParser(File), d(NULL)
 {}
 									/*}}}*/
 // ListParser::NewVersion - Fill in the version structure		/*{{{*/
@@ -86,9 +85,11 @@ bool edspListParser::ParseStatus(pkgCache::PkgIterator &Pkg,
 }
 									/*}}}*/
 // ListParser::LoadReleaseInfo - Load the release information		/*{{{*/
-APT_CONST bool edspListParser::LoadReleaseInfo(pkgCache::PkgFileIterator & /*FileI*/,
-				    FileFd & /*File*/, std::string /*component*/)
+APT_CONST bool edspListParser::LoadReleaseInfo(pkgCache::RlsFileIterator & /*FileI*/,
+				    FileFd & /*File*/, std::string const &/*component*/)
 {
    return true;
 }
 									/*}}}*/
+
+edspListParser::~edspListParser() {}

+ 9 - 7
apt-pkg/edsp/edsplistparser.h

@@ -27,20 +27,22 @@ class FileFd;
 
 class APT_HIDDEN edspListParser : public debListParser
 {
+   void * const d;
    public:
-   virtual bool NewVersion(pkgCache::VerIterator &Ver);
+   virtual bool NewVersion(pkgCache::VerIterator &Ver) APT_OVERRIDE;
    virtual std::string Description();
    virtual std::string DescriptionLanguage();
-   virtual MD5SumValue Description_md5();
-   virtual unsigned short VersionHash();
+   virtual MD5SumValue Description_md5() APT_OVERRIDE;
+   virtual unsigned short VersionHash() APT_OVERRIDE;
 
-   bool LoadReleaseInfo(pkgCache::PkgFileIterator &FileI,FileFd &File,
-			std::string section);
+   bool LoadReleaseInfo(pkgCache::RlsFileIterator &FileI,FileFd &File,
+			std::string const &section);
 
-   edspListParser(FileFd *File, std::string const &Arch = "");
+   edspListParser(FileFd *File);
+   virtual ~edspListParser();
 
    protected:
-   virtual bool ParseStatus(pkgCache::PkgIterator &Pkg,pkgCache::VerIterator &Ver);
+   virtual bool ParseStatus(pkgCache::PkgIterator &Pkg,pkgCache::VerIterator &Ver) APT_OVERRIDE;
 
 };
 

+ 5 - 16
apt-pkg/edsp/edspsystem.cc

@@ -15,7 +15,6 @@
 #include <apt-pkg/debversion.h>
 #include <apt-pkg/edspindexfile.h>
 #include <apt-pkg/edspsystem.h>
-#include <apt-pkg/fileutl.h>
 #include <apt-pkg/pkgcache.h>
 #include <apt-pkg/cacheiterators.h>
 
@@ -23,16 +22,11 @@
 #include <string>
 #include <vector>
 
-#include <apti18n.h>
 									/*}}}*/
 
-// System::debSystem - Constructor					/*{{{*/
-edspSystem::edspSystem()
+// System::edspSystem - Constructor					/*{{{*/
+edspSystem::edspSystem() : pkgSystem("Debian APT solver interface", &debVS), d(NULL), StatusFile(NULL)
 {
-   StatusFile = 0;
-
-   Label = "Debian APT solver interface";
-   VS = &debVS;
 }
 									/*}}}*/
 // System::~debSystem - Destructor					/*{{{*/
@@ -85,18 +79,13 @@ bool edspSystem::ArchiveSupported(const char * /*Type*/)
    return false;
 }
 									/*}}}*/
-// System::Score - Determine if we should use the edsp system		/*{{{*/
-signed edspSystem::Score(Configuration const &Cnf)
+// System::Score - Never use the EDSP system automatically		/*{{{*/
+signed edspSystem::Score(Configuration const &)
 {
-   if (Cnf.Find("edsp::scenario", "") == "stdin")
-      return 1000;
-   if (RealFileExists(Cnf.FindFile("edsp::scenario","")) == true)
-      return 1000;
    return -1000;
 }
 									/*}}}*/
-// System::AddStatusFiles - Register the status files			/*{{{*/
-bool edspSystem::AddStatusFiles(std::vector<pkgIndexFile *> &List)
+bool edspSystem::AddStatusFiles(std::vector<pkgIndexFile *> &List)	/*{{{*/
 {
    if (StatusFile == 0)
    {

+ 12 - 10
apt-pkg/edsp/edspsystem.h

@@ -16,6 +16,8 @@
 
 #include <vector>
 
+#include <apt-pkg/macros.h>
+
 class Configuration;
 class pkgDepCache;
 class pkgIndexFile;
@@ -25,24 +27,24 @@ class edspIndex;
 class APT_HIDDEN edspSystem : public pkgSystem
 {
    /** \brief dpointer placeholder (for later in case we need it) */
-   void *d;
+   void * const d;
 
    edspIndex *StatusFile;
 
    public:
 
-   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) APT_CONST;
-   virtual signed Score(Configuration const &Cnf);
-   virtual bool AddStatusFiles(std::vector<pkgIndexFile *> &List);
+   virtual bool Lock() APT_OVERRIDE APT_CONST;
+   virtual bool UnLock(bool NoErrors = false) APT_OVERRIDE APT_CONST;
+   virtual pkgPackageManager *CreatePM(pkgDepCache *Cache) const APT_OVERRIDE APT_CONST;
+   virtual bool Initialize(Configuration &Cnf) APT_OVERRIDE;
+   virtual bool ArchiveSupported(const char *Type) APT_OVERRIDE APT_CONST;
+   virtual signed Score(Configuration const &Cnf) APT_OVERRIDE;
+   virtual bool AddStatusFiles(std::vector<pkgIndexFile *> &List) APT_OVERRIDE;
    virtual bool FindIndex(pkgCache::PkgFileIterator File,
-			  pkgIndexFile *&Found) const;
+			  pkgIndexFile *&Found) const APT_OVERRIDE;
 
    edspSystem();
-   ~edspSystem();
+   virtual ~edspSystem();
 };
 
 #endif

+ 21 - 10
apt-pkg/indexcopy.cc

@@ -19,18 +19,19 @@
 #include <apt-pkg/aptconfiguration.h>
 #include <apt-pkg/configuration.h>
 #include <apt-pkg/tagfile.h>
-#include <apt-pkg/indexrecords.h>
+#include <apt-pkg/metaindex.h>
 #include <apt-pkg/cdrom.h>
 #include <apt-pkg/gpgv.h>
 #include <apt-pkg/hashes.h>
+#include <apt-pkg/debmetaindex.h>
 
 #include <iostream>
-#include <sstream>
 #include <unistd.h>
 #include <sys/stat.h>
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
+#include <sstream>
 
 #include "indexcopy.h"
 #include <apti18n.h>
@@ -424,7 +425,6 @@ bool PackageCopy::GetFile(string &File,unsigned long long &Size)
 // PackageCopy::RewriteEntry - Rewrite the entry with a new filename	/*{{{*/
 bool PackageCopy::RewriteEntry(FileFd &Target,string const &File)
 {
-   string const Dir(File,0,File.rfind('/'));
    std::vector<pkgTagSection::Tag> Changes;
    Changes.push_back(pkgTagSection::Tag::Rewrite("Filename", File));
 
@@ -477,9 +477,9 @@ bool SourceCopy::RewriteEntry(FileFd &Target, std::string const &File)
 }
 									/*}}}*/
 // SigVerify::Verify - Verify a files md5sum against its metaindex	/*{{{*/
-bool SigVerify::Verify(string prefix, string file, indexRecords *MetaIndex)
+bool SigVerify::Verify(string prefix, string file, metaIndex *MetaIndex)
 {
-   const indexRecords::checkSum *Record = MetaIndex->Lookup(file);
+   const metaIndex::checkSum *Record = MetaIndex->Lookup(file);
    bool const Debug = _config->FindB("Debug::aptcdrom",false);
 
    // we skip non-existing files in the verifcation of the Release file
@@ -546,11 +546,11 @@ bool SigVerify::CopyAndVerify(string CDROM,string Name,vector<string> &SigList,
 
    // Read all Release files
    for (vector<string>::iterator I = SigList.begin(); I != SigList.end(); ++I)
-   { 
+   {
       if(Debug)
 	 cout << "Signature verify for: " << *I << endl;
 
-      indexRecords *MetaIndex = new indexRecords;
+      metaIndex *MetaIndex = new debReleaseIndex("","");
       string prefix = *I; 
 
       string const releasegpg = *I+"Release.gpg";
@@ -592,12 +592,13 @@ bool SigVerify::CopyAndVerify(string CDROM,string Name,vector<string> &SigList,
       }
 
       // Open the Release file and add it to the MetaIndex
-      if(!MetaIndex->Load(release))
+      std::string ErrorText;
+      if(MetaIndex->Load(release, &ErrorText) == false)
       {
-	 _error->Error("%s",MetaIndex->ErrorText.c_str());
+	 _error->Error("%s", ErrorText.c_str());
 	 return false;
       }
-      
+
       // go over the Indexfiles and see if they verify
       // if so, remove them from our copy of the lists
       vector<string> keys = MetaIndex->MetaKeys();
@@ -770,4 +771,14 @@ bool TranslationsCopy::CopyTranslations(string CDROM,string Name,	/*{{{*/
 }
 									/*}}}*/
 
+IndexCopy::IndexCopy() : d(NULL) {}
 APT_CONST IndexCopy::~IndexCopy() {}
+
+PackageCopy::PackageCopy() : IndexCopy(), d(NULL) {}
+APT_CONST PackageCopy::~PackageCopy() {}
+SourceCopy::SourceCopy() : IndexCopy(), d(NULL) {}
+APT_CONST SourceCopy::~SourceCopy() {}
+TranslationsCopy::TranslationsCopy() : d(NULL) {}
+APT_CONST TranslationsCopy::~TranslationsCopy() {}
+SigVerify::SigVerify() : d(NULL) {}
+APT_CONST SigVerify::~SigVerify() {}

+ 33 - 16
apt-pkg/indexcopy.h

@@ -1,6 +1,5 @@
 // -*- mode: cpp; mode: fold -*-
 // Description								/*{{{*/
-// $Id: indexcopy.h,v 1.3 2001/05/27 04:46:54 jgg Exp $
 /* ######################################################################
 
    Index Copying - Aid for copying and verifying the index files
@@ -11,8 +10,10 @@
 #define INDEXCOPY_H
 
 #include <vector>
+#ifndef APT_11_CLEAN_HEADERS
 #include <string>
 #include <stdio.h>
+#endif
 
 #include <apt-pkg/macros.h>
 
@@ -26,14 +27,14 @@ using std::vector;
 #endif
 
 class pkgTagSection;
-class indexRecords;
 class pkgCdromStatus;
 class FileFd;
+class metaIndex;
 
 class IndexCopy								/*{{{*/
 {
    /** \brief dpointer placeholder (for later in case we need it) */
-   void *d;
+   void * const d;
 
    protected:
    
@@ -54,47 +55,60 @@ class IndexCopy								/*{{{*/
 
    bool CopyPackages(std::string CDROM,std::string Name,std::vector<std::string> &List,
 		     pkgCdromStatus *log);
+   IndexCopy();
    virtual ~IndexCopy();
 };
 									/*}}}*/
 class PackageCopy : public IndexCopy					/*{{{*/
 {
+   void * const d;
    protected:
-   
-   virtual bool GetFile(std::string &Filename,unsigned long long &Size);
-   virtual bool RewriteEntry(FileFd &Target, std::string const &File);
-   virtual const char *GetFileName() {return "Packages";};
-   virtual const char *Type() {return "Package";};
-   
+
+   virtual bool GetFile(std::string &Filename,unsigned long long &Size) APT_OVERRIDE;
+   virtual bool RewriteEntry(FileFd &Target, std::string const &File) APT_OVERRIDE;
+   virtual const char *GetFileName() APT_OVERRIDE {return "Packages";};
+   virtual const char *Type() APT_OVERRIDE {return "Package";};
+
+   public:
+   PackageCopy();
+   virtual ~PackageCopy();
 };
 									/*}}}*/
 class SourceCopy : public IndexCopy					/*{{{*/
 {
+   void * const d;
    protected:
    
-   virtual bool GetFile(std::string &Filename,unsigned long long &Size);
-   virtual bool RewriteEntry(FileFd &Target, std::string const &File);
-   virtual const char *GetFileName() {return "Sources";};
-   virtual const char *Type() {return "Source";};
-   
+   virtual bool GetFile(std::string &Filename,unsigned long long &Size) APT_OVERRIDE;
+   virtual bool RewriteEntry(FileFd &Target, std::string const &File) APT_OVERRIDE;
+   virtual const char *GetFileName() APT_OVERRIDE {return "Sources";};
+   virtual const char *Type() APT_OVERRIDE {return "Source";};
+
+   public:
+   SourceCopy();
+   virtual ~SourceCopy();
 };
 									/*}}}*/
 class TranslationsCopy							/*{{{*/
 {
+   void * const d;
    protected:
    pkgTagSection *Section;
 
    public:
    bool CopyTranslations(std::string CDROM,std::string Name,std::vector<std::string> &List,
 			 pkgCdromStatus *log);
+
+   TranslationsCopy();
+   virtual ~TranslationsCopy();
 };
 									/*}}}*/
 class SigVerify								/*{{{*/
 {
    /** \brief dpointer placeholder (for later in case we need it) */
-   void *d;
+   void * const d;
 
-   APT_HIDDEN bool Verify(std::string prefix,std::string file, indexRecords *records);
+   APT_HIDDEN bool Verify(std::string prefix,std::string file, metaIndex *records);
    APT_HIDDEN bool CopyMetaIndex(std::string CDROM, std::string CDName,
 		      std::string prefix, std::string file);
 
@@ -106,6 +120,9 @@ class SigVerify								/*{{{*/
 		       int const &statusfd, int fd[2]);
    APT_DEPRECATED static bool RunGPGV(std::string const &File, std::string const &FileOut,
 			      int const &statusfd = -1);
+
+   SigVerify();
+   virtual ~SigVerify();
 };
 									/*}}}*/
 

+ 280 - 8
apt-pkg/indexfile.cc

@@ -10,18 +10,27 @@
 // Include Files							/*{{{*/
 #include<config.h>
 
+#include <apt-pkg/configuration.h>
 #include <apt-pkg/indexfile.h>
 #include <apt-pkg/error.h>
+#include <apt-pkg/fileutl.h>
 #include <apt-pkg/aptconfiguration.h>
 #include <apt-pkg/pkgcache.h>
+#include <apt-pkg/pkgcachegen.h>
 #include <apt-pkg/cacheiterators.h>
 #include <apt-pkg/srcrecords.h>
+#include <apt-pkg/progress.h>
 #include <apt-pkg/macros.h>
 
+#include <apt-pkg/deblistparser.h>
+
+#include <sys/stat.h>
+
 #include <string>
 #include <vector>
 #include <clocale>
 #include <cstring>
+#include <memory>
 									/*}}}*/
 
 // Global list of Item supported
@@ -48,27 +57,26 @@ pkgIndexFile::Type *pkgIndexFile::Type::GetType(const char *Type)
       if (strcmp(GlobalList[I]->Label,Type) == 0)
 	 return GlobalList[I];
    return 0;
+}
+									/*}}}*/
+pkgIndexFile::pkgIndexFile(bool const Trusted) :			/*{{{*/
+   d(NULL), Trusted(Trusted)
+{
 }
 									/*}}}*/
 // IndexFile::ArchiveInfo - Stub					/*{{{*/
-// ---------------------------------------------------------------------
-/* */
-std::string pkgIndexFile::ArchiveInfo(pkgCache::VerIterator /*Ver*/) const
+std::string pkgIndexFile::ArchiveInfo(pkgCache::VerIterator const &/*Ver*/) const
 {
    return std::string();
 }
 									/*}}}*/
 // IndexFile::FindInCache - Stub					/*{{{*/
-// ---------------------------------------------------------------------
-/* */
 pkgCache::PkgFileIterator pkgIndexFile::FindInCache(pkgCache &Cache) const
 {
    return pkgCache::PkgFileIterator(Cache);
 }
 									/*}}}*/
 // IndexFile::SourceIndex - Stub					/*{{{*/
-// ---------------------------------------------------------------------
-/* */
 std::string pkgIndexFile::SourceInfo(pkgSrcRecords::Parser const &/*Record*/,
 				pkgSrcRecords::File const &/*File*/) const
 {
@@ -88,7 +96,7 @@ bool pkgIndexFile::TranslationsAvailable() {
    is already done in getLanguages(). Note also that this check is
    rather bad (doesn't take three character like ast into account).
    TODO: Remove method with next API break */
-APT_DEPRECATED bool pkgIndexFile::CheckLanguageCode(const char *Lang)
+APT_DEPRECATED bool pkgIndexFile::CheckLanguageCode(const char * const Lang)
 {
   if (strlen(Lang) == 2 || (strlen(Lang) == 5 && Lang[2] == '_'))
     return true;
@@ -110,3 +118,267 @@ APT_DEPRECATED std::string pkgIndexFile::LanguageCode() {
 	return APT::Configuration::getLanguages()[0];
 }
 									/*}}}*/
+
+// IndexTarget - Constructor						/*{{{*/
+IndexTarget::IndexTarget(std::string const &MetaKey, std::string const &ShortDesc,
+      std::string const &LongDesc, std::string const &URI, bool const IsOptional,
+      bool const KeepCompressed, std::map<std::string, std::string> const &Options) :
+   URI(URI), Description(LongDesc), ShortDesc(ShortDesc), MetaKey(MetaKey),
+   IsOptional(IsOptional), KeepCompressed(KeepCompressed), Options(Options)
+{
+}
+									/*}}}*/
+std::string IndexTarget::Option(OptionKeys const EnumKey) const		/*{{{*/
+{
+   std::string Key;
+   switch (EnumKey)
+   {
+#define APT_CASE(X) case X: Key = #X; break
+      APT_CASE(SITE);
+      APT_CASE(RELEASE);
+      APT_CASE(COMPONENT);
+      APT_CASE(LANGUAGE);
+      APT_CASE(ARCHITECTURE);
+      APT_CASE(BASE_URI);
+      APT_CASE(REPO_URI);
+      APT_CASE(TARGET_OF);
+      APT_CASE(CREATED_BY);
+#undef APT_CASE
+      case FILENAME: return _config->FindDir("Dir::State::lists") + URItoFileName(URI);
+      case EXISTING_FILENAME:
+	 std::string const filename = Option(FILENAME);
+	 std::vector<std::string> const types = APT::Configuration::getCompressionTypes();
+	 for (std::vector<std::string>::const_iterator t = types.begin(); t != types.end(); ++t)
+	 {
+	    if (t->empty())
+	       continue;
+	    std::string const file = (*t == "uncompressed") ? filename : (filename + "." + *t);
+	    if (FileExists(file))
+	       return file;
+	 }
+	 return "";
+   }
+   std::map<std::string,std::string>::const_iterator const M = Options.find(Key);
+   if (M == Options.end())
+      return "";
+   return M->second;
+}
+									/*}}}*/
+std::string IndexTarget::Format(std::string format) const		/*{{{*/
+{
+   for (std::map<std::string, std::string>::const_iterator O = Options.begin(); O != Options.end(); ++O)
+   {
+      format = SubstVar(format, std::string("$(") + O->first + ")", O->second);
+   }
+   format = SubstVar(format, "$(METAKEY)", MetaKey);
+   format = SubstVar(format, "$(SHORTDESC)", ShortDesc);
+   format = SubstVar(format, "$(DESCRIPTION)", Description);
+   format = SubstVar(format, "$(URI)", URI);
+   format = SubstVar(format, "$(FILENAME)", Option(IndexTarget::FILENAME));
+   return format;
+}
+									/*}}}*/
+
+pkgDebianIndexTargetFile::pkgDebianIndexTargetFile(IndexTarget const &Target, bool const Trusted) :/*{{{*/
+   pkgDebianIndexFile(Trusted), d(NULL), Target(Target)
+{
+}
+									/*}}}*/
+std::string pkgDebianIndexTargetFile::ArchiveURI(std::string const &File) const/*{{{*/
+{
+   return Target.Option(IndexTarget::REPO_URI) + File;
+}
+									/*}}}*/
+std::string pkgDebianIndexTargetFile::Describe(bool const Short) const	/*{{{*/
+{
+   if (Short)
+      return Target.Description;
+   return Target.Description + " (" + IndexFileName() + ")";
+}
+									/*}}}*/
+std::string pkgDebianIndexTargetFile::IndexFileName() const			/*{{{*/
+{
+   std::string const s = Target.Option(IndexTarget::FILENAME);
+   if (FileExists(s))
+      return s;
+
+   std::vector<std::string> types = APT::Configuration::getCompressionTypes();
+   for (std::vector<std::string>::const_iterator t = types.begin(); t != types.end(); ++t)
+   {
+      std::string p = s + '.' + *t;
+      if (FileExists(p))
+         return p;
+   }
+   return s;
+}
+									/*}}}*/
+unsigned long pkgDebianIndexTargetFile::Size() const				/*{{{*/
+{
+   unsigned long size = 0;
+
+   /* we need to ignore errors here; if the lists are absent, just return 0 */
+   _error->PushToStack();
+
+   FileFd f(IndexFileName(), FileFd::ReadOnly, FileFd::Extension);
+   if (!f.Failed())
+      size = f.Size();
+
+   if (_error->PendingError() == true)
+       size = 0;
+   _error->RevertToStack();
+
+   return size;
+}
+									/*}}}*/
+bool pkgDebianIndexTargetFile::Exists() const					/*{{{*/
+{
+   return FileExists(IndexFileName());
+}
+									/*}}}*/
+std::string pkgDebianIndexTargetFile::GetArchitecture() const			/*{{{*/
+{
+   return Target.Option(IndexTarget::ARCHITECTURE);
+}
+									/*}}}*/
+std::string pkgDebianIndexTargetFile::GetComponent() const			/*{{{*/
+{
+   return Target.Option(IndexTarget::COMPONENT);
+}
+									/*}}}*/
+bool pkgDebianIndexTargetFile::OpenListFile(FileFd &Pkg, std::string const &FileName)/*{{{*/
+{
+   if (Pkg.Open(FileName, FileFd::ReadOnly, FileFd::Extension) == false)
+      return _error->Error("Problem opening %s",FileName.c_str());
+   return true;
+}
+									/*}}}*/
+std::string pkgDebianIndexTargetFile::GetProgressDescription() const
+{
+   return Target.Description;
+}
+
+pkgDebianIndexRealFile::pkgDebianIndexRealFile(std::string const &File, bool const Trusted) :/*{{{*/
+   pkgDebianIndexFile(Trusted), d(NULL), File(flAbsPath(File))
+{
+}
+									/*}}}*/
+// IndexRealFile::Size - Return the size of the index			/*{{{*/
+unsigned long pkgDebianIndexRealFile::Size() const
+{
+   struct stat S;
+   if (stat(File.c_str(),&S) != 0)
+      return 0;
+   return S.st_size;
+}
+									/*}}}*/
+bool pkgDebianIndexRealFile::Exists() const					/*{{{*/
+{
+   return FileExists(File);
+}
+									/*}}}*/
+std::string pkgDebianIndexRealFile::Describe(bool const /*Short*/) const/*{{{*/
+{
+   return File;
+}
+									/*}}}*/
+std::string pkgDebianIndexRealFile::ArchiveURI(std::string const &/*File*/) const/*{{{*/
+{
+   return "file:" + File;
+}
+									/*}}}*/
+std::string pkgDebianIndexRealFile::IndexFileName() const			/*{{{*/
+{
+   return File;
+}
+									/*}}}*/
+std::string pkgDebianIndexRealFile::GetProgressDescription() const
+{
+   return File;
+}
+bool pkgDebianIndexRealFile::OpenListFile(FileFd &Pkg, std::string const &FileName)/*{{{*/
+{
+   if (Pkg.Open(FileName, FileFd::ReadOnly, FileFd::None) == false)
+      return _error->Error("Problem opening %s",FileName.c_str());
+   return true;
+}
+									/*}}}*/
+
+pkgDebianIndexFile::pkgDebianIndexFile(bool const Trusted) : pkgIndexFile(Trusted)
+{
+}
+pkgDebianIndexFile::~pkgDebianIndexFile()
+{
+}
+pkgCacheListParser * pkgDebianIndexFile::CreateListParser(FileFd &Pkg)
+{
+   if (Pkg.IsOpen() == false)
+      return NULL;
+   _error->PushToStack();
+   pkgCacheListParser * const Parser = new debListParser(&Pkg);
+   bool const newError = _error->PendingError();
+   _error->MergeWithStack();
+   return newError ? NULL : Parser;
+}
+bool pkgDebianIndexFile::Merge(pkgCacheGenerator &Gen,OpProgress * const Prog)
+{
+   std::string const PackageFile = IndexFileName();
+   FileFd Pkg;
+   if (OpenListFile(Pkg, PackageFile) == false)
+      return false;
+   _error->PushToStack();
+   std::unique_ptr<pkgCacheListParser> Parser(CreateListParser(Pkg));
+   bool const newError = _error->PendingError();
+   if (newError == false && Parser == nullptr)
+      return true;
+   if (Parser == NULL)
+      return false;
+
+   if (Prog != NULL)
+      Prog->SubProgress(0, GetProgressDescription());
+
+   if (Gen.SelectFile(PackageFile, *this, GetArchitecture(), GetComponent(), GetIndexFlags()) == false)
+      return _error->Error("Problem with SelectFile %s",PackageFile.c_str());
+
+   // Store the IMS information
+   pkgCache::PkgFileIterator File = Gen.GetCurFile();
+   pkgCacheGenerator::Dynamic<pkgCache::PkgFileIterator> DynFile(File);
+   File->Size = Pkg.FileSize();
+   File->mtime = Pkg.ModificationTime();
+
+   if (Gen.MergeList(*Parser) == false)
+      return _error->Error("Problem with MergeList %s",PackageFile.c_str());
+   return true;
+}
+pkgCache::PkgFileIterator pkgDebianIndexFile::FindInCache(pkgCache &Cache) const
+{
+   std::string const FileName = IndexFileName();
+   pkgCache::PkgFileIterator File = Cache.FileBegin();
+   for (; File.end() == false; ++File)
+   {
+       if (File.FileName() == NULL || FileName != File.FileName())
+	 continue;
+
+      struct stat St;
+      if (stat(File.FileName(),&St) != 0)
+      {
+         if (_config->FindB("Debug::pkgCacheGen", false))
+	    std::clog << "DebianIndexFile::FindInCache - stat failed on " << File.FileName() << std::endl;
+	 return pkgCache::PkgFileIterator(Cache);
+      }
+      if ((map_filesize_t)St.st_size != File->Size || St.st_mtime != File->mtime)
+      {
+         if (_config->FindB("Debug::pkgCacheGen", false))
+	    std::clog << "DebianIndexFile::FindInCache - size (" << St.st_size << " <> " << File->Size
+			<< ") or mtime (" << St.st_mtime << " <> " << File->mtime
+			<< ") doesn't match for " << File.FileName() << std::endl;
+	 return pkgCache::PkgFileIterator(Cache);
+      }
+      return File;
+   }
+
+   return File;
+}
+
+APT_CONST pkgIndexFile::~pkgIndexFile() {}
+APT_CONST pkgDebianIndexTargetFile::~pkgDebianIndexTargetFile() {}
+APT_CONST pkgDebianIndexRealFile::~pkgDebianIndexRealFile() {}

+ 126 - 19
apt-pkg/indexfile.h

@@ -1,6 +1,5 @@
 // -*- mode: cpp; mode: fold -*-
 // Description								/*{{{*/
-// $Id: indexfile.h,v 1.6.2.1 2003/12/24 23:09:17 mdz Exp $
 /* ######################################################################
 
    Index File - Abstraction for an index of archive/source file.
@@ -28,6 +27,7 @@
 #include <apt-pkg/cacheiterators.h>
 #include <apt-pkg/macros.h>
 
+#include <map>
 #include <string>
 
 #ifndef APT_8_CLEANER_HEADERS
@@ -38,28 +38,80 @@ class pkgAcquire;
 #endif
 
 class pkgCacheGenerator;
+class pkgCacheListParser;
 class OpProgress;
 
+class IndexTarget							/*{{{*/
+/** \brief Information about an index file. */
+{
+   public:
+   /** \brief A URI from which the index file can be downloaded. */
+   std::string URI;
+
+   /** \brief A description of the index file. */
+   std::string Description;
+
+   /** \brief A shorter description of the index file. */
+   std::string ShortDesc;
+
+   /** \brief The key by which this index file should be
+       looked up within the meta index file. */
+   std::string MetaKey;
+
+   /** \brief Is it okay if the file isn't found in the meta index */
+   bool IsOptional;
+
+   /** \brief If the file is downloaded compressed, do not unpack it */
+   bool KeepCompressed;
+
+   /** \brief options with which this target was created
+       Prefer the usage of #Option if at all possible.
+       Beware: Not all of these options are intended for public use */
+   std::map<std::string, std::string> Options;
+
+   IndexTarget(std::string const &MetaKey, std::string const &ShortDesc,
+	 std::string const &LongDesc, std::string const &URI, bool const IsOptional,
+	 bool const KeepCompressed, std::map<std::string, std::string> const &Options);
+
+   enum OptionKeys {
+      SITE,
+      RELEASE,
+      COMPONENT,
+      LANGUAGE,
+      ARCHITECTURE,
+      BASE_URI,
+      REPO_URI,
+      CREATED_BY,
+      TARGET_OF,
+      FILENAME,
+      EXISTING_FILENAME,
+   };
+   std::string Option(OptionKeys const Key) const;
+   std::string Format(std::string format) const;
+};
+									/*}}}*/
+
 class pkgIndexFile
 {
+   void * const d;
    protected:
    bool Trusted;
-     
+
    public:
 
    class Type
    {
       public:
-      
+
       // Global list of Items supported
       static Type **GlobalList;
       static unsigned long GlobalListLen;
-      static Type *GetType(const char *Type) APT_PURE;
+      static Type *GetType(const char * const Type) APT_PURE;
 
       const char *Label;
 
-      virtual pkgRecords::Parser *CreatePkgParser(pkgCache::PkgFileIterator /*File*/) const {return 0;};
-      virtual pkgSrcRecords::Parser *CreateSrcPkgParser(std::string /*File*/) const {return 0;};
+      virtual pkgRecords::Parser *CreatePkgParser(pkgCache::PkgFileIterator const &/*File*/) const {return 0;};
+      virtual pkgSrcRecords::Parser *CreateSrcPkgParser(std::string const &/*File*/) const {return 0;};
       Type();
       virtual ~Type() {};
    };
@@ -67,13 +119,13 @@ class pkgIndexFile
    virtual const Type *GetType() const = 0;
    
    // Return descriptive strings of various sorts
-   virtual std::string ArchiveInfo(pkgCache::VerIterator Ver) const;
+   virtual std::string ArchiveInfo(pkgCache::VerIterator const &Ver) const;
    virtual std::string SourceInfo(pkgSrcRecords::Parser const &Record,
 			     pkgSrcRecords::File const &File) const;
-   virtual std::string Describe(bool Short = false) const = 0;   
+   virtual std::string Describe(bool const Short = false) const = 0;
 
    // Interface for acquire
-   virtual std::string ArchiveURI(std::string /*File*/) const {return std::string();};
+   virtual std::string ArchiveURI(std::string const &/*File*/) const {return std::string();};
 
    // Interface for the record parsers
    virtual pkgSrcRecords::Parser *CreateSrcParser() const {return 0;};
@@ -82,22 +134,77 @@ class pkgIndexFile
    virtual bool Exists() const = 0;
    virtual bool HasPackages() const = 0;
    virtual unsigned long Size() const = 0;
-   virtual bool Merge(pkgCacheGenerator &/*Gen*/, OpProgress* /*Prog*/) const { return false; };
-   APT_DEPRECATED virtual bool Merge(pkgCacheGenerator &Gen, OpProgress &Prog) const
-      { return Merge(Gen, &Prog); };
-   virtual bool MergeFileProvides(pkgCacheGenerator &/*Gen*/,OpProgress* /*Prog*/) const {return true;};
-   APT_DEPRECATED virtual bool MergeFileProvides(pkgCacheGenerator &Gen, OpProgress &Prog) const
-      {return MergeFileProvides(Gen, &Prog);};
+   virtual bool Merge(pkgCacheGenerator &/*Gen*/, OpProgress* const /*Prog*/) { return true; };
    virtual pkgCache::PkgFileIterator FindInCache(pkgCache &Cache) const;
 
    static bool TranslationsAvailable();
-   static bool CheckLanguageCode(const char *Lang);
+   static bool CheckLanguageCode(const char * const Lang);
    static std::string LanguageCode();
 
    bool IsTrusted() const { return Trusted; };
-   
-   pkgIndexFile(bool Trusted): Trusted(Trusted) {};
-   virtual ~pkgIndexFile() {};
+
+   explicit pkgIndexFile(bool const Trusted);
+   virtual ~pkgIndexFile();
+};
+
+class pkgDebianIndexFile : public pkgIndexFile
+{
+protected:
+   virtual std::string IndexFileName() const = 0;
+   virtual std::string GetComponent() const = 0;
+   virtual std::string GetArchitecture() const = 0;
+   virtual std::string GetProgressDescription() const = 0;
+   virtual uint8_t GetIndexFlags() const = 0;
+   virtual bool OpenListFile(FileFd &Pkg, std::string const &FileName) = 0;
+   APT_HIDDEN virtual pkgCacheListParser * CreateListParser(FileFd &Pkg);
+
+public:
+   virtual bool Merge(pkgCacheGenerator &Gen, OpProgress* const Prog) APT_OVERRIDE;
+   virtual pkgCache::PkgFileIterator FindInCache(pkgCache &Cache) const APT_OVERRIDE;
+
+   pkgDebianIndexFile(bool const Trusted);
+   virtual ~pkgDebianIndexFile();
+};
+
+class pkgDebianIndexTargetFile : public pkgDebianIndexFile
+{
+   void * const d;
+protected:
+   IndexTarget const Target;
+
+   virtual std::string IndexFileName() const APT_OVERRIDE;
+   virtual std::string GetComponent() const APT_OVERRIDE;
+   virtual std::string GetArchitecture() const APT_OVERRIDE;
+   virtual std::string GetProgressDescription() const APT_OVERRIDE;
+   virtual bool OpenListFile(FileFd &Pkg, std::string const &FileName) APT_OVERRIDE;
+
+public:
+   virtual std::string ArchiveURI(std::string const &File) const APT_OVERRIDE;
+   virtual std::string Describe(bool const Short = false) const APT_OVERRIDE;
+   virtual bool Exists() const APT_OVERRIDE;
+   virtual unsigned long Size() const APT_OVERRIDE;
+
+   pkgDebianIndexTargetFile(IndexTarget const &Target, bool const Trusted);
+   virtual ~pkgDebianIndexTargetFile();
+};
+
+class pkgDebianIndexRealFile : public pkgDebianIndexFile
+{
+   void * const d;
+protected:
+   std::string File;
+
+   virtual std::string IndexFileName() const APT_OVERRIDE;
+   virtual std::string GetProgressDescription() const APT_OVERRIDE;
+   virtual bool OpenListFile(FileFd &Pkg, std::string const &FileName) APT_OVERRIDE;
+public:
+   virtual std::string Describe(bool const /*Short*/ = false) const APT_OVERRIDE;
+   virtual bool Exists() const APT_OVERRIDE;
+   virtual unsigned long Size() const APT_OVERRIDE;
+   virtual std::string ArchiveURI(std::string const &/*File*/) const APT_OVERRIDE;
+
+   pkgDebianIndexRealFile(std::string const &File, bool const Trusted);
+   virtual ~pkgDebianIndexRealFile();
 };
 
 #endif

+ 0 - 296
apt-pkg/indexrecords.cc

@@ -1,296 +0,0 @@
-// -*- mode: cpp; mode: fold -*-
-// Description								/*{{{*/
-// $Id: indexrecords.cc,v 1.1.2.4 2003/12/30 02:11:43 mdz Exp $
-									/*}}}*/
-// Include Files							/*{{{*/
-#include<config.h>
-
-#include <apt-pkg/indexrecords.h>
-#include <apt-pkg/tagfile.h>
-#include <apt-pkg/error.h>
-#include <apt-pkg/strutl.h>
-#include <apt-pkg/configuration.h>
-#include <apt-pkg/fileutl.h>
-#include <apt-pkg/hashes.h>
-#include <apt-pkg/gpgv.h>
-
-#include <stdlib.h>
-#include <time.h>
-#include <clocale>
-#include <map>
-#include <string>
-#include <utility>
-#include <vector>
-
-#include <apti18n.h>
-									/*}}}*/
-
-using std::string;
-
-APT_PURE string indexRecords::GetDist() const
-{
-   return this->Dist;
-}
-
-APT_PURE string indexRecords::GetSuite() const
-{
-   return this->Suite;
-}
-
-APT_PURE bool indexRecords::GetSupportsAcquireByHash() const
-{
-   return this->SupportsAcquireByHash;
-}
-
-APT_PURE bool indexRecords::CheckDist(const string MaybeDist) const
-{
-   return (this->Dist == MaybeDist
-	   || this->Suite == MaybeDist);
-}
-
-APT_PURE string indexRecords::GetExpectedDist() const
-{
-   return this->ExpectedDist;
-}
-
-APT_PURE time_t indexRecords::GetValidUntil() const
-{
-   return this->ValidUntil;
-}
-
-APT_PURE time_t indexRecords::GetDate() const
-{
-   return this->Date;
-}
-
-APT_PURE indexRecords::checkSum *indexRecords::Lookup(const string MetaKey)
-{
-   std::map<std::string, indexRecords::checkSum* >::const_iterator sum = Entries.find(MetaKey);
-   if (sum == Entries.end())
-      return NULL;
-   return sum->second;
-}
-
-APT_PURE bool indexRecords::Exists(string const &MetaKey) const
-{
-   return Entries.count(MetaKey) == 1;
-}
-
-bool indexRecords::Load(const string Filename)				/*{{{*/
-{
-   FileFd Fd;
-   if (OpenMaybeClearSignedFile(Filename, Fd) == false)
-      return false;
-
-   pkgTagFile TagFile(&Fd, Fd.Size());
-   if (_error->PendingError() == true)
-   {
-      strprintf(ErrorText, _("Unable to parse Release file %s"),Filename.c_str());
-      return false;
-   }
-
-   pkgTagSection Section;
-   const char *Start, *End;
-   if (TagFile.Step(Section) == false)
-   {
-      strprintf(ErrorText, _("No sections in Release file %s"), Filename.c_str());
-      return false;
-   }
-   // FIXME: find better tag name
-   SupportsAcquireByHash = Section.FindB("Acquire-By-Hash", false);
-
-   Suite = Section.FindS("Suite");
-   Dist = Section.FindS("Codename");
-
-   bool FoundHashSum = false;
-   for (int i=0;HashString::SupportedHashes()[i] != NULL; i++)
-   {
-      if (!Section.Find(HashString::SupportedHashes()[i], Start, End))
-	 continue;
-
-      string Name;
-      string Hash;
-      unsigned long long Size;
-      while (Start < End)
-      {
-	 if (!parseSumData(Start, End, Name, Hash, Size))
-	    return false;
-
-         if (Entries.find(Name) == Entries.end())
-         {
-            indexRecords::checkSum *Sum = new indexRecords::checkSum;
-            Sum->MetaKeyFilename = Name;
-            Sum->Size = Size;
-	    std::string SizeStr;
-	    strprintf(SizeStr, "%llu", Size);
-	    Sum->Hashes.push_back(HashString("Checksum-FileSize", SizeStr));
-            APT_IGNORE_DEPRECATED(Sum->Hash = HashString(HashString::SupportedHashes()[i],Hash);)
-            Entries[Name] = Sum;
-         }
-         Entries[Name]->Hashes.push_back(HashString(HashString::SupportedHashes()[i],Hash));
-         FoundHashSum = true;
-      }
-   }
-
-   if(FoundHashSum == false)
-   {
-      strprintf(ErrorText, _("No Hash entry in Release file %s"), Filename.c_str());
-      return false;
-   }
-
-   string const StrDate = Section.FindS("Date");
-   if (RFC1123StrToTime(StrDate.c_str(), Date) == false)
-   {
-      strprintf(ErrorText, _("Invalid 'Date' entry in Release file %s"), Filename.c_str());
-      return false;
-   }
-
-   string const Label = Section.FindS("Label");
-   string const StrValidUntil = Section.FindS("Valid-Until");
-
-   // if we have a Valid-Until header in the Release file, use it as default
-   if (StrValidUntil.empty() == false)
-   {
-      if(RFC1123StrToTime(StrValidUntil.c_str(), ValidUntil) == false)
-      {
-	 strprintf(ErrorText, _("Invalid 'Valid-Until' entry in Release file %s"), Filename.c_str());
-	 return false;
-      }
-   }
-   // get the user settings for this archive and use what expires earlier
-   int MaxAge = _config->FindI("Acquire::Max-ValidTime", 0);
-   if (Label.empty() == false)
-      MaxAge = _config->FindI(("Acquire::Max-ValidTime::" + Label).c_str(), MaxAge);
-   int MinAge = _config->FindI("Acquire::Min-ValidTime", 0);
-   if (Label.empty() == false)
-      MinAge = _config->FindI(("Acquire::Min-ValidTime::" + Label).c_str(), MinAge);
-
-   if(MaxAge == 0 &&
-      (MinAge == 0 || ValidUntil == 0)) // No user settings, use the one from the Release file
-      return true;
-
-   if (MinAge != 0 && ValidUntil != 0) {
-      time_t const min_date = Date + MinAge;
-      if (ValidUntil < min_date)
-	 ValidUntil = min_date;
-   }
-   if (MaxAge != 0) {
-      time_t const max_date = Date + MaxAge;
-      if (ValidUntil == 0 || ValidUntil > max_date)
-	 ValidUntil = max_date;
-   }
-
-   return true;
-}
-									/*}}}*/
-std::vector<string> indexRecords::MetaKeys()				/*{{{*/
-{
-   std::vector<std::string> keys;
-   std::map<string,checkSum *>::iterator I = Entries.begin();
-   while(I != Entries.end()) {
-      keys.push_back((*I).first);
-      ++I;
-   }
-   return keys;
-}
-									/*}}}*/
-bool indexRecords::parseSumData(const char *&Start, const char *End,	/*{{{*/
-				   string &Name, string &Hash, unsigned long long &Size)
-{
-   Name = "";
-   Hash = "";
-   Size = 0;
-   /* Skip over the first blank */
-   while ((*Start == '\t' || *Start == ' ' || *Start == '\n' || *Start == '\r')
-	  && Start < End)
-      Start++;
-   if (Start >= End)
-      return false;
-
-   /* Move EntryEnd to the end of the first entry (the hash) */
-   const char *EntryEnd = Start;
-   while ((*EntryEnd != '\t' && *EntryEnd != ' ')
-	  && EntryEnd < End)
-      EntryEnd++;
-   if (EntryEnd == End)
-      return false;
-
-   Hash.append(Start, EntryEnd-Start);
-
-   /* Skip over intermediate blanks */
-   Start = EntryEnd;
-   while (*Start == '\t' || *Start == ' ')
-      Start++;
-   if (Start >= End)
-      return false;
-   
-   EntryEnd = Start;
-   /* Find the end of the second entry (the size) */
-   while ((*EntryEnd != '\t' && *EntryEnd != ' ' )
-	  && EntryEnd < End)
-      EntryEnd++;
-   if (EntryEnd == End)
-      return false;
-   
-   Size = strtoull (Start, NULL, 10);
-      
-   /* Skip over intermediate blanks */
-   Start = EntryEnd;
-   while (*Start == '\t' || *Start == ' ')
-      Start++;
-   if (Start >= End)
-      return false;
-   
-   EntryEnd = Start;
-   /* Find the end of the third entry (the filename) */
-   while ((*EntryEnd != '\t' && *EntryEnd != ' ' && 
-           *EntryEnd != '\n' && *EntryEnd != '\r')
-	  && EntryEnd < End)
-      EntryEnd++;
-
-   Name.append(Start, EntryEnd-Start);
-   Start = EntryEnd; //prepare for the next round
-   return true;
-}
-									/*}}}*/
-
-APT_PURE bool indexRecords::IsAlwaysTrusted() const
-{
-   if (Trusted == ALWAYS_TRUSTED)
-      return true;
-   return false;
-}
-APT_PURE bool indexRecords::IsNeverTrusted() const
-{
-   if (Trusted == NEVER_TRUSTED)
-      return true;
-   return false;
-}
-void indexRecords::SetTrusted(bool const Trusted)
-{
-   if (Trusted == true)
-      this->Trusted = ALWAYS_TRUSTED;
-   else
-      this->Trusted = NEVER_TRUSTED;
-}
-
-#if APT_PKG_ABI >= 413
-indexRecords::indexRecords(const string &ExpectedDist) :
-   Trusted(CHECK_TRUST), d(NULL), ExpectedDist(ExpectedDist), ValidUntil(0),
-   SupportsAcquireByHash(false)
-{
-}
-#else
-indexRecords::indexRecords() :
-   Trusted(CHECK_TRUST), d(NULL), ExpectedDist(""), ValidUntil(0),
-   SupportsAcquireByHash(false)
-{
-}
-indexRecords::indexRecords(const string ExpectedDist) :
-   Trusted(CHECK_TRUST), d(NULL), ExpectedDist(ExpectedDist), ValidUntil(0),
-   SupportsAcquireByHash(false)
-{
-}
-#endif
-
-indexRecords::~indexRecords() {}

+ 0 - 96
apt-pkg/indexrecords.h

@@ -1,96 +0,0 @@
-// -*- mode: cpp; mode: fold -*-
-// Description								/*{{{*/
-// $Id: indexrecords.h,v 1.1.2.1 2003/12/24 23:09:17 mdz Exp $
-									/*}}}*/
-#ifndef PKGLIB_INDEXRECORDS_H
-#define PKGLIB_INDEXRECORDS_H
-
-#include <apt-pkg/hashes.h>
-
-#include <map>
-#include <vector>
-#include <ctime>
-#include <string>
-
-#ifndef APT_8_CLEANER_HEADERS
-#include <apt-pkg/fileutl.h>
-#endif
-#ifndef APT_10_CLEANER_HEADERS
-#include <apt-pkg/pkgcache.h>
-#endif
-
-class indexRecords
-{
-   APT_HIDDEN bool parseSumData(const char *&Start, const char *End, std::string &Name,
-		     std::string &Hash, unsigned long long &Size);
-   public:
-   struct checkSum;
-   std::string ErrorText;
-
-   private:
-   enum APT_HIDDEN { ALWAYS_TRUSTED, NEVER_TRUSTED, CHECK_TRUST } Trusted;
-   // dpointer (for later)
-   void * d;
-
-   protected:
-   std::string Dist;
-   std::string Suite;
-   std::string ExpectedDist;
-   time_t Date;
-   time_t ValidUntil;
-   bool SupportsAcquireByHash;
-
-   std::map<std::string,checkSum *> Entries;
-
-   public:
-#if APT_PKG_ABI >= 413
-   indexRecords(const std::string &ExpectedDist = "");
-#else
-   indexRecords();
-   indexRecords(const std::string ExpectedDist);
-#endif
-
-   // Lookup function
-   virtual checkSum *Lookup(const std::string MetaKey);
-   /** \brief tests if a checksum for this file is available */
-   bool Exists(std::string const &MetaKey) const;
-   std::vector<std::string> MetaKeys();
-
-   virtual bool Load(std::string Filename);
-   virtual bool CheckDist(const std::string MaybeDist) const;
-
-   std::string GetDist() const;
-   std::string GetSuite() const;
-   bool GetSupportsAcquireByHash() const;
-   time_t GetValidUntil() const;
-   time_t GetDate() const;
-   std::string GetExpectedDist() const;
-
-   /** \brief check if source is marked as always trusted */
-   bool IsAlwaysTrusted() const;
-   /** \brief check if source is marked as never trusted */
-   bool IsNeverTrusted() const;
-
-   /** \brief sets an explicit trust value
-    *
-    * \b true means that the source should always be considered trusted,
-    * while \b false marks a source as always untrusted, even if we have
-    * a valid signature and everything.
-    */
-   void SetTrusted(bool const Trusted);
-
-   virtual ~indexRecords();
-};
-
-APT_IGNORE_DEPRECATED_PUSH
-struct indexRecords::checkSum
-{
-   std::string MetaKeyFilename;
-   HashStringList Hashes;
-   unsigned long long Size;
-
-   APT_DEPRECATED HashString Hash;
-};
-APT_IGNORE_DEPRECATED_POP
-
-#endif

+ 24 - 4
apt-pkg/init.cc

@@ -18,7 +18,6 @@
 #include <apt-pkg/macros.h>
 
 #include <string.h>
-#include <string>
 #include <cstdlib>
 
 #include <apti18n.h>
@@ -62,8 +61,6 @@ bool pkgInitConfig(Configuration &Cnf)
    Cnf.CndSet("Dir::Etc","etc/apt/");
    Cnf.CndSet("Dir::Etc::sourcelist","sources.list");
    Cnf.CndSet("Dir::Etc::sourceparts","sources.list.d");
-   Cnf.CndSet("Dir::Etc::vendorlist","vendors.list");
-   Cnf.CndSet("Dir::Etc::vendorparts","vendors.list.d");
    Cnf.CndSet("Dir::Etc::main","apt.conf");
    Cnf.CndSet("Dir::Etc::netrc", "auth.conf");
    Cnf.CndSet("Dir::Etc::parts","apt.conf.d");
@@ -101,8 +98,31 @@ bool pkgInitConfig(Configuration &Cnf)
    // The default user we drop to in the methods
    Cnf.CndSet("APT::Sandbox::User", "_apt");
 
+   Cnf.CndSet("Acquire::IndexTargets::deb::Packages::MetaKey", "$(COMPONENT)/binary-$(ARCHITECTURE)/Packages");
+   Cnf.CndSet("Acquire::IndexTargets::deb::Packages::flatMetaKey", "Packages");
+   Cnf.CndSet("Acquire::IndexTargets::deb::Packages::ShortDescription", "Packages");
+   Cnf.CndSet("Acquire::IndexTargets::deb::Packages::Description", "$(RELEASE)/$(COMPONENT) $(ARCHITECTURE) Packages");
+   Cnf.CndSet("Acquire::IndexTargets::deb::Packages::flatDescription", "$(RELEASE) Packages");
+   Cnf.CndSet("Acquire::IndexTargets::deb::Packages::Optional", false);
+   Cnf.CndSet("Acquire::IndexTargets::deb::Translations::MetaKey", "$(COMPONENT)/i18n/Translation-$(LANGUAGE)");
+   Cnf.CndSet("Acquire::IndexTargets::deb::Translations::flatMetaKey", "$(LANGUAGE)");
+   Cnf.CndSet("Acquire::IndexTargets::deb::Translations::ShortDescription", "Translation-$(LANGUAGE)");
+   Cnf.CndSet("Acquire::IndexTargets::deb::Translations::Description", "$(RELEASE)/$(COMPONENT) Translation-$(LANGUAGE)");
+   Cnf.CndSet("Acquire::IndexTargets::deb::Translations::flatDescription", "$(RELEASE) Translation-$(LANGUAGE)");
+   Cnf.CndSet("Acquire::IndexTargets::deb-src::Sources::MetaKey", "$(COMPONENT)/source/Sources");
+   Cnf.CndSet("Acquire::IndexTargets::deb-src::Sources::flatMetaKey", "Sources");
+   Cnf.CndSet("Acquire::IndexTargets::deb-src::Sources::ShortDescription", "Sources");
+   Cnf.CndSet("Acquire::IndexTargets::deb-src::Sources::Description", "$(RELEASE)/$(COMPONENT) Sources");
+   Cnf.CndSet("Acquire::IndexTargets::deb-src::Sources::flatDescription", "$(RELEASE) Sources");
+   Cnf.CndSet("Acquire::IndexTargets::deb-src::Sources::Optional", false);
+
+   Cnf.CndSet("Acquire::Changelogs::URI::Origin::Debian", "http://metadata.ftp-master.debian.org/changelogs/CHANGEPATH_changelog");
+   Cnf.CndSet("Acquire::Changelogs::URI::Origin::Tanglu", "http://metadata.tanglu.org/changelogs/CHANGEPATH_changelog");
+   Cnf.CndSet("Acquire::Changelogs::URI::Origin::Ubuntu", "http://changelogs.ubuntu.com/changelogs/pool/CHANGEPATH/changelog");
+   Cnf.CndSet("Acquire::Changelogs::URI::Origin::Ultimedia", "http://packages.ultimediaos.com/changelogs/pool/CHANGEPATH/changelog.txt");
+
    bool Res = true;
-   
+
    // Read an alternate config file
    const char *Cfg = getenv("APT_CONFIG");
    if (Cfg != 0 && strlen(Cfg) != 0)

+ 14 - 9
apt-pkg/install-progress.cc

@@ -8,13 +8,12 @@
 #include <signal.h>
 #include <unistd.h>
 #include <iostream>
-#include <string>
 #include <vector>
 #include <sys/ioctl.h>
-#include <sstream>
 #include <fcntl.h>
 #include <algorithm>
 #include <stdio.h>
+#include <sstream>
 
 #include <apti18n.h>
 
@@ -65,10 +64,11 @@ bool PackageManager::StatusChanged(std::string /*PackageName*/,
 }
 
 PackageManagerProgressFd::PackageManagerProgressFd(int progress_fd)
-   : StepsDone(0), StepsTotal(1)
+   : d(NULL), StepsDone(0), StepsTotal(1)
 {
    OutStatusFd = progress_fd;
 }
+PackageManagerProgressFd::~PackageManagerProgressFd() {}
 
 void PackageManagerProgressFd::WriteToStatusFd(std::string s)
 {
@@ -153,10 +153,11 @@ bool PackageManagerProgressFd::StatusChanged(std::string PackageName,
 
 
 PackageManagerProgressDeb822Fd::PackageManagerProgressDeb822Fd(int progress_fd)
-   : StepsDone(0), StepsTotal(1)
+   : d(NULL), StepsDone(0), StepsTotal(1)
 {
    OutStatusFd = progress_fd;
 }
+PackageManagerProgressDeb822Fd::~PackageManagerProgressDeb822Fd() {}
 
 void PackageManagerProgressDeb822Fd::WriteToStatusFd(std::string s)
 {
@@ -233,7 +234,7 @@ bool PackageManagerProgressDeb822Fd::StatusChanged(std::string PackageName,
 
 
 PackageManagerFancy::PackageManagerFancy()
-   : child_pty(-1)
+   : d(NULL), child_pty(-1)
 {
    // setup terminal size
    old_SIGWINCH = signal(SIGWINCH, PackageManagerFancy::staticSIGWINCH);
@@ -285,13 +286,13 @@ void PackageManagerFancy::SetupTerminalScrollArea(int nr_rows)
      std::cout << "\n";
          
      // save cursor
-     std::cout << "\033[s";
+     std::cout << "\0337";
          
      // set scroll region (this will place the cursor in the top left)
      std::cout << "\033[0;" << nr_rows - 1 << "r";
             
      // restore cursor but ensure its inside the scrolling area
-     std::cout << "\033[u";
+     std::cout << "\0338";
      static const char *move_cursor_up = "\033[1A";
      std::cout << move_cursor_up;
 
@@ -373,8 +374,8 @@ bool PackageManagerFancy::DrawStatusLine()
    if (unlikely(size.rows < 1 || size.columns < 1))
       return false;
 
-   static std::string save_cursor = "\033[s";
-   static std::string restore_cursor = "\033[u";
+   static std::string save_cursor = "\0337";
+   static std::string restore_cursor = "\0338";
 
    // green
    static std::string set_bg_color = DeQuoteString(
@@ -433,6 +434,10 @@ bool PackageManagerText::StatusChanged(std::string PackageName,
    return true;
 }
 
+PackageManagerText::PackageManagerText() : PackageManager(), d(NULL) {}
+PackageManagerText::~PackageManagerText() {}
+
+
 
 
 } // namespace progress

+ 27 - 18
apt-pkg/install-progress.h

@@ -18,7 +18,7 @@ namespace Progress {
  {
  private:
     /** \brief dpointer placeholder */
-    void *d;
+    void * const d;
 
  protected:
     std::string progress_str;
@@ -61,6 +61,7 @@ namespace Progress {
 
  class PackageManagerProgressFd : public PackageManager
  {
+    void * const d;
  protected:
     int OutStatusFd;
     int StepsDone;
@@ -68,28 +69,30 @@ namespace Progress {
     void WriteToStatusFd(std::string msg);
 
  public:
-    PackageManagerProgressFd(int progress_fd);
+    explicit PackageManagerProgressFd(int progress_fd);
+    virtual ~PackageManagerProgressFd();
 
-    virtual void StartDpkg();
-    virtual void Stop();
+    virtual void StartDpkg() APT_OVERRIDE;
+    virtual void Stop() APT_OVERRIDE;
 
     virtual bool StatusChanged(std::string PackageName,
                                unsigned int StepsDone,
                                unsigned int TotalSteps,
-                               std::string HumanReadableAction);
+                               std::string HumanReadableAction) APT_OVERRIDE;
     virtual void Error(std::string PackageName,
                        unsigned int StepsDone,
                        unsigned int TotalSteps,
-                          std::string ErrorMessage);
+                          std::string ErrorMessage) APT_OVERRIDE;
     virtual void ConffilePrompt(std::string PackageName,
                                 unsigned int StepsDone,
                                 unsigned int TotalSteps,
-                                   std::string ConfMessage);
+                                   std::string ConfMessage) APT_OVERRIDE;
 
  };
 
  class PackageManagerProgressDeb822Fd : public PackageManager
  {
+    void * const d;
  protected:
     int OutStatusFd;
     int StepsDone;
@@ -97,27 +100,29 @@ namespace Progress {
     void WriteToStatusFd(std::string msg);
 
  public:
-    PackageManagerProgressDeb822Fd(int progress_fd);
+    explicit PackageManagerProgressDeb822Fd(int progress_fd);
+    virtual ~PackageManagerProgressDeb822Fd();
 
-    virtual void StartDpkg();
-    virtual void Stop();
+    virtual void StartDpkg() APT_OVERRIDE;
+    virtual void Stop() APT_OVERRIDE;
 
     virtual bool StatusChanged(std::string PackageName,
                                unsigned int StepsDone,
                                unsigned int TotalSteps,
-                               std::string HumanReadableAction);
+                               std::string HumanReadableAction) APT_OVERRIDE;
     virtual void Error(std::string PackageName,
                        unsigned int StepsDone,
                        unsigned int TotalSteps,
-                          std::string ErrorMessage);
+                          std::string ErrorMessage) APT_OVERRIDE;
     virtual void ConffilePrompt(std::string PackageName,
                                 unsigned int StepsDone,
                                 unsigned int TotalSteps,
-                                   std::string ConfMessage);
+                                   std::string ConfMessage) APT_OVERRIDE;
  };
 
  class PackageManagerFancy : public PackageManager
  {
+    void * const d;
  private:
     APT_HIDDEN static void staticSIGWINCH(int);
     static std::vector<PackageManagerFancy*> instances;
@@ -138,13 +143,13 @@ namespace Progress {
 
  public:
     PackageManagerFancy();
-    ~PackageManagerFancy();
-    virtual void Start(int child_pty=-1);
-    virtual void Stop();
+    virtual ~PackageManagerFancy();
+    virtual void Start(int child_pty=-1) APT_OVERRIDE;
+    virtual void Stop() APT_OVERRIDE;
     virtual bool StatusChanged(std::string PackageName,
                                unsigned int StepsDone,
                                unsigned int TotalSteps,
-                               std::string HumanReadableAction);
+                               std::string HumanReadableAction) APT_OVERRIDE;
 
     // return a progress bar of the given size for the given progress 
     // percent between 0.0 and 1.0 in the form "[####...]"
@@ -153,11 +158,15 @@ namespace Progress {
 
  class PackageManagerText : public PackageManager
  {
+    void * const d;
  public:
     virtual bool StatusChanged(std::string PackageName,
                                unsigned int StepsDone,
                                unsigned int TotalSteps,
-                               std::string HumanReadableAction);
+                               std::string HumanReadableAction) APT_OVERRIDE;
+
+    PackageManagerText();
+    virtual ~PackageManagerText();
  };
 
 

+ 72 - 13
apt-pkg/metaindex.cc

@@ -1,30 +1,31 @@
 // Include Files                                                       /*{{{*/
+#include <apt-pkg/pkgcachegen.h>
 #include <apt-pkg/indexfile.h>
 #include <apt-pkg/metaindex.h>
 
-#include <stddef.h>
-
 #include <string>
 #include <vector>
                                                                        /*}}}*/
 
-#if (APT_PKG_MAJOR >= 4 && APT_PKG_MINOR >= 13)
-std::string metaIndex::LocalFileName() const { return ""; }
-#else
-#include <apt-pkg/debmetaindex.h>
-std::string metaIndex::LocalFileName() const
+std::string metaIndex::Describe() const
 {
-   debReleaseIndex const * deb = dynamic_cast<debReleaseIndex const*>(this);
-   if (deb != NULL)
-      return deb->LocalFileName();
+   return "Release";
+}
 
-   return "";
+pkgCache::RlsFileIterator metaIndex::FindInCache(pkgCache &Cache, bool const) const
+{
+   return pkgCache::RlsFileIterator(Cache);
+}
+
+bool metaIndex::Merge(pkgCacheGenerator &Gen,OpProgress *) const
+{
+   return Gen.SelectReleaseFile("", "");
 }
-#endif
 
 metaIndex::metaIndex(std::string const &URI, std::string const &Dist,
       char const * const Type)
-: Indexes(NULL), Type(Type), URI(URI), Dist(Dist), Trusted(false)
+: d(NULL), Indexes(NULL), Type(Type), URI(URI), Dist(Dist), Trusted(TRI_UNSET),
+   Date(0), ValidUntil(0), SupportsAcquireByHash(false), LoadedSuccessfully(TRI_UNSET)
 {
    /* nothing */
 }
@@ -38,3 +39,61 @@ metaIndex::~metaIndex()
       delete *I;
    delete Indexes;
 }
+
+// one line Getters for public fields					/*{{{*/
+APT_PURE std::string metaIndex::GetURI() const { return URI; }
+APT_PURE std::string metaIndex::GetDist() const { return Dist; }
+APT_PURE const char* metaIndex::GetType() const { return Type; }
+APT_PURE metaIndex::TriState metaIndex::GetTrusted() const { return Trusted; }
+APT_PURE std::string metaIndex::GetSignedBy() const { return SignedBy; }
+APT_PURE std::string metaIndex::GetCodename() const { return Codename; }
+APT_PURE std::string metaIndex::GetSuite() const { return Suite; }
+APT_PURE bool metaIndex::GetSupportsAcquireByHash() const { return SupportsAcquireByHash; }
+APT_PURE time_t metaIndex::GetValidUntil() const { return ValidUntil; }
+APT_PURE time_t metaIndex::GetDate() const { return this->Date; }
+APT_PURE metaIndex::TriState metaIndex::GetLoadedSuccessfully() const { return LoadedSuccessfully; }
+
+APT_PURE bool metaIndex::CheckDist(string const &MaybeDist) const
+{
+   return (this->Codename == MaybeDist
+	   || this->Suite == MaybeDist);
+}
+APT_PURE std::string metaIndex::GetExpectedDist() const
+{
+   // TODO: Used to be an explicit value set in the constructor
+   return "";
+}
+									/*}}}*/
+APT_PURE metaIndex::checkSum *metaIndex::Lookup(string const &MetaKey) const /*{{{*/
+{
+   std::map<std::string, metaIndex::checkSum* >::const_iterator sum = Entries.find(MetaKey);
+   if (sum == Entries.end())
+      return NULL;
+   return sum->second;
+}
+									/*}}}*/
+APT_PURE bool metaIndex::Exists(string const &MetaKey) const		/*{{{*/
+{
+   return Entries.find(MetaKey) != Entries.end();
+}
+									/*}}}*/
+std::vector<std::string> metaIndex::MetaKeys() const			/*{{{*/
+{
+   std::vector<std::string> keys;
+   std::map<string,checkSum *>::const_iterator I = Entries.begin();
+   while(I != Entries.end()) {
+      keys.push_back((*I).first);
+      ++I;
+   }
+   return keys;
+}
+									/*}}}*/
+void metaIndex::swapLoad(metaIndex * const OldMetaIndex)		/*{{{*/
+{
+   std::swap(Entries, OldMetaIndex->Entries);
+   std::swap(Date, OldMetaIndex->Date);
+   std::swap(ValidUntil, OldMetaIndex->ValidUntil);
+   std::swap(SupportsAcquireByHash, OldMetaIndex->SupportsAcquireByHash);
+   std::swap(LoadedSuccessfully, OldMetaIndex->LoadedSuccessfully);
+}
+									/*}}}*/

+ 67 - 16
apt-pkg/metaindex.h

@@ -17,41 +17,92 @@ class OpProgress;
 #ifndef APT_8_CLEANER_HEADERS
 #include <apt-pkg/srcrecords.h>
 #include <apt-pkg/pkgrecords.h>
-#include <apt-pkg/vendor.h>
 using std::string;
 #endif
 
 class pkgAcquire;
+class IndexTarget;
+class pkgCacheGenerator;
+class OpProgress;
 
 class metaIndex
 {
-   protected:
+public:
+   APT_IGNORE_DEPRECATED_PUSH
+   struct checkSum
+   {
+      std::string MetaKeyFilename;
+      HashStringList Hashes;
+      unsigned long long Size;
+
+      APT_DEPRECATED HashString Hash;
+   };
+   APT_IGNORE_DEPRECATED_POP
+
+   enum APT_HIDDEN TriState {
+      TRI_YES, TRI_DONTCARE, TRI_NO, TRI_UNSET
+   };
+private:
+   void * const d;
+protected:
    std::vector <pkgIndexFile *> *Indexes;
+   // parsed from the sources.list
    const char *Type;
    std::string URI;
    std::string Dist;
-   bool Trusted;
+   TriState Trusted;
+   std::string SignedBy;
 
-   public:
+   // parsed from a file
+   std::string Suite;
+   std::string Codename;
+   time_t Date;
+   time_t ValidUntil;
+   bool SupportsAcquireByHash;
+   std::map<std::string, checkSum *> Entries;
+   TriState LoadedSuccessfully;
 
+public:
    // Various accessors
-   virtual std::string GetURI() const {return URI;}
-   virtual std::string GetDist() const {return Dist;}
-   virtual const char* GetType() const {return Type;}
-
-   // interface to to query it
-#if APT_PKG_ABI >= 413
-   /** \return the path of the local file (or "" if its not available) */
-   virtual std::string LocalFileName() const;
-#else
-   std::string LocalFileName() const;
-#endif
+   std::string GetURI() const;
+   std::string GetDist() const;
+   const char* GetType() const;
+   TriState GetTrusted() const;
+   std::string GetSignedBy() const;
+
+   std::string GetCodename() const;
+   std::string GetSuite() const;
+   bool GetSupportsAcquireByHash() const;
+   time_t GetValidUntil() const;
+   time_t GetDate() const;
+
+   std::string GetExpectedDist() const;
+   bool CheckDist(std::string const &MaybeDist) const;
 
    // Interface for acquire
+   virtual std::string Describe() const;
    virtual std::string ArchiveURI(std::string const& File) const = 0;
-   virtual bool GetIndexes(pkgAcquire *Owner, bool const &GetAll=false) const = 0;
+   virtual bool GetIndexes(pkgAcquire *Owner, bool const &GetAll=false) = 0;
+   virtual std::vector<IndexTarget> GetIndexTargets() const = 0;
    virtual std::vector<pkgIndexFile *> *GetIndexFiles() = 0;
    virtual bool IsTrusted() const = 0;
+   virtual bool Load(std::string const &Filename, std::string * const ErrorText) = 0;
+   /** @return a new metaIndex object based on this one, but without information from #Load */
+   virtual metaIndex * UnloadedClone() const = 0;
+   // the given metaIndex is potentially invalid after this call and should be deleted
+   void swapLoad(metaIndex * const OldMetaIndex);
+
+   // Lookup functions for parsed Hashes
+   checkSum *Lookup(std::string const &MetaKey) const;
+   /** \brief tests if a checksum for this file is available */
+   bool Exists(std::string const &MetaKey) const;
+   std::vector<std::string> MetaKeys() const;
+   TriState GetLoadedSuccessfully() const;
+
+   // Interfaces for pkgCacheGen
+   virtual pkgCache::RlsFileIterator FindInCache(pkgCache &Cache, bool const ModifyCheck) const;
+   virtual bool Merge(pkgCacheGenerator &Gen,OpProgress *Prog) const;
+
 
    metaIndex(std::string const &URI, std::string const &Dist,
              char const * const Type);

+ 12 - 14
apt-pkg/orderlist.cc

@@ -68,14 +68,12 @@
 #include <apt-pkg/orderlist.h>
 #include <apt-pkg/depcache.h>
 #include <apt-pkg/error.h>
-#include <apt-pkg/sptr.h>
 #include <apt-pkg/configuration.h>
 #include <apt-pkg/cacheiterators.h>
 #include <apt-pkg/pkgcache.h>
 
 #include <stdlib.h>
 #include <string.h>
-#include <string>
 #include <iostream>
 									/*}}}*/
 
@@ -86,7 +84,7 @@ pkgOrderList *pkgOrderList::Me = 0;
 // OrderList::pkgOrderList - Constructor				/*{{{*/
 // ---------------------------------------------------------------------
 /* */
-pkgOrderList::pkgOrderList(pkgDepCache *pCache) : Cache(*pCache),
+pkgOrderList::pkgOrderList(pkgDepCache *pCache) : d(NULL), Cache(*pCache),
 						  Primary(NULL), Secondary(NULL),
 						  RevDepends(NULL), Remove(NULL),
 						  AfterEnd(NULL), FileList(NULL),
@@ -142,9 +140,9 @@ bool pkgOrderList::DoRun()
 {   
    // Temp list
    unsigned long Size = Cache.Head().PackageCount;
-   SPtrArray<Package *> NList = new Package *[Size];
-   SPtrArray<Package *> AfterList = new Package *[Size];
-   AfterEnd = AfterList;
+   std::unique_ptr<Package *[]> NList(new Package *[Size]);
+   std::unique_ptr<Package *[]> AfterList(new Package *[Size]);
+   AfterEnd = AfterList.get();
    
    Depth = 0;
    WipeFlags(Added | AddPending | Loop | InList);
@@ -154,7 +152,7 @@ bool pkgOrderList::DoRun()
 
    // Rebuild the main list into the temp list.
    iterator OldEnd = End;
-   End = NList;
+   End = NList.get();
    for (iterator I = List; I != OldEnd; ++I)
       if (VisitNode(PkgIterator(Cache,*I), "DoRun") == false)
       {
@@ -163,12 +161,12 @@ bool pkgOrderList::DoRun()
       }
    
    // Copy the after list to the end of the main list
-   for (Package **I = AfterList; I != AfterEnd; I++)
+   for (Package **I = AfterList.get(); I != AfterEnd; I++)
       *End++ = *I;
    
    // Swap the main list to the new list
    delete [] List;
-   List = NList.UnGuard();
+   List = NList.release();
    return true;
 }
 									/*}}}*/
@@ -512,8 +510,8 @@ bool pkgOrderList::VisitRProvides(DepFunc F,VerIterator Ver)
    against it! */
 bool pkgOrderList::VisitProvides(DepIterator D,bool Critical)
 {
-   SPtrArray<Version *> List = D.AllTargets();
-   for (Version **I = List; *I != 0; ++I)
+   std::unique_ptr<Version *[]> List(D.AllTargets());
+   for (Version **I = List.get(); *I != 0; ++I)
    {
       VerIterator Ver(Cache,*I);
       PkgIterator Pkg = Ver.ParentPkg();
@@ -541,7 +539,7 @@ bool pkgOrderList::VisitProvides(DepIterator D,bool Critical)
    }
    if (D.IsNegative() == false)
       return true;
-   for (Version **I = List; *I != 0; ++I)
+   for (Version **I = List.get(); *I != 0; ++I)
    {
       VerIterator Ver(Cache,*I);
       PkgIterator Pkg = Ver.ParentPkg();
@@ -1075,9 +1073,9 @@ void pkgOrderList::WipeFlags(unsigned long F)
    this fails to produce a suitable result. */
 bool pkgOrderList::CheckDep(DepIterator D)
 {
-   SPtrArray<Version *> List = D.AllTargets();
+   std::unique_ptr<Version *[]> List(D.AllTargets());
    bool Hit = false;
-   for (Version **I = List; *I != 0; I++)
+   for (Version **I = List.get(); *I != 0; I++)
    {
       VerIterator Ver(Cache,*I);
       PkgIterator Pkg = Ver.ParentPkg();

+ 3 - 3
apt-pkg/orderlist.h

@@ -1,6 +1,5 @@
 // -*- mode: cpp; mode: fold -*-
 // Description								/*{{{*/
-// $Id: orderlist.h,v 1.9 2001/02/20 07:03:17 jgg Exp $
 /* ######################################################################
 
    Order List - Represents and Manipulates an ordered list of packages.
@@ -25,6 +24,7 @@
 class pkgDepCache;
 class pkgOrderList : protected pkgCache::Namespace
 {
+   void * const d;
    protected:
 
    pkgDepCache &Cache;   
@@ -122,8 +122,8 @@ class pkgOrderList : protected pkgCache::Namespace
 
    int Score(PkgIterator Pkg);
 
-   pkgOrderList(pkgDepCache *Cache);
-   ~pkgOrderList();
+   explicit pkgOrderList(pkgDepCache *Cache);
+   virtual ~pkgOrderList();
 };
 
 #endif

+ 13 - 38
apt-pkg/packagemanager.cc

@@ -23,7 +23,6 @@
 #include <apt-pkg/acquire-item.h>
 #include <apt-pkg/algorithms.h>
 #include <apt-pkg/configuration.h>
-#include <apt-pkg/sptr.h>
 #include <apt-pkg/macros.h>
 #include <apt-pkg/pkgcache.h>
 #include <apt-pkg/cacheiterators.h>
@@ -45,7 +44,7 @@ bool pkgPackageManager::SigINTStop = false;
 // ---------------------------------------------------------------------
 /* */
 pkgPackageManager::pkgPackageManager(pkgDepCache *pCache) : Cache(*pCache),
-							    List(NULL), Res(Incomplete)
+							    List(NULL), Res(Incomplete), d(NULL)
 {
    FileNames = new string[Cache.Head().PackageCount];
    Debug = _config->FindB("Debug::pkgPackageManager",false);
@@ -390,9 +389,9 @@ bool pkgPackageManager::SmartConfigure(PkgIterator Pkg, int const Depth)
          // to do anything at all
 	 for (DepIterator Cur = Start; true; ++Cur)
 	 {
-	    SPtrArray<Version *> VList = Cur.AllTargets();
+	    std::unique_ptr<Version *> VList(Cur.AllTargets());
 
-	    for (Version **I = VList; *I != 0; ++I)
+	    for (Version **I = VList.get(); *I != 0; ++I)
 	    {
 	       VerIterator Ver(Cache,*I);
 	       PkgIterator DepPkg = Ver.ParentPkg();
@@ -440,9 +439,9 @@ bool pkgPackageManager::SmartConfigure(PkgIterator Pkg, int const Depth)
          // probably due to loops.
 	 for (DepIterator Cur = Start; true; ++Cur)
 	 {
-	    SPtrArray<Version *> VList = Cur.AllTargets();
+	    std::unique_ptr<Version *> VList(Cur.AllTargets());
 
-	    for (Version **I = VList; *I != 0; ++I)
+	    for (Version **I = VList.get(); *I != 0; ++I)
 	    {
 	       VerIterator Ver(Cache,*I);
 	       PkgIterator DepPkg = Ver.ParentPkg();
@@ -515,9 +514,9 @@ bool pkgPackageManager::SmartConfigure(PkgIterator Pkg, int const Depth)
 	 // Search for dependencies which are unpacked but aren't configured yet (maybe loops)
 	 for (DepIterator Cur = Start; true; ++Cur)
 	 {
-	    SPtrArray<Version *> VList = Cur.AllTargets();
+	    std::unique_ptr<Version *> VList(Cur.AllTargets());
 
-	    for (Version **I = VList; *I != 0; ++I)
+	    for (Version **I = VList.get(); *I != 0; ++I)
 	    {
 	       VerIterator Ver(Cache,*I);
 	       PkgIterator DepPkg = Ver.ParentPkg();
@@ -726,8 +725,8 @@ bool pkgPackageManager::SmartUnPack(PkgIterator Pkg, bool const Immediate, int c
 	    // Look for easy targets: packages that are already okay
 	    for (DepIterator Cur = Start; Bad == true; ++Cur)
 	    {
-	       SPtrArray<Version *> VList = Cur.AllTargets();
-	       for (Version **I = VList; *I != 0; ++I)
+	       std::unique_ptr<Version *> VList(Cur.AllTargets());
+	       for (Version **I = VList.get(); *I != 0; ++I)
 	       {
 		  VerIterator Ver(Cache,*I);
 		  PkgIterator Pkg = Ver.ParentPkg();
@@ -750,8 +749,8 @@ bool pkgPackageManager::SmartUnPack(PkgIterator Pkg, bool const Immediate, int c
 	    // Look for something that could be configured.
 	    for (DepIterator Cur = Start; Bad == true && Cur.end() == false; ++Cur)
 	    {
-	       SPtrArray<Version *> VList = Cur.AllTargets();
-	       for (Version **I = VList; *I != 0; ++I)
+	       std::unique_ptr<Version *[]> VList(Cur.AllTargets());
+	       for (Version **I = VList.get(); *I != 0; ++I)
 	       {
 		  VerIterator Ver(Cache,*I);
 		  PkgIterator DepPkg = Ver.ParentPkg();
@@ -806,8 +805,8 @@ bool pkgPackageManager::SmartUnPack(PkgIterator Pkg, bool const Immediate, int c
 		  End->Type == pkgCache::Dep::Obsoletes ||
 		  End->Type == pkgCache::Dep::DpkgBreaks)
 	 {
-	    SPtrArray<Version *> VList = End.AllTargets();
-	    for (Version **I = VList; *I != 0; ++I)
+	    std::unique_ptr<Version *[]> VList(End.AllTargets());
+	    for (Version **I = VList.get(); *I != 0; ++I)
 	    {
 	       VerIterator Ver(Cache,*I);
 	       PkgIterator ConflictPkg = Ver.ParentPkg();
@@ -1085,7 +1084,6 @@ pkgPackageManager::OrderResult pkgPackageManager::OrderInstall()
 // PM::DoInstallPostFork - compat /*{{{*/
 // ---------------------------------------------------------------------
 									/*}}}*/
-#if APT_PKG_ABI >= 413
 pkgPackageManager::OrderResult
 pkgPackageManager::DoInstallPostFork(int statusFd)
 {
@@ -1107,22 +1105,10 @@ pkgPackageManager::DoInstallPostFork(APT::Progress::PackageManager *progress)
    
    return Res;
 }
-#else
-pkgPackageManager::OrderResult
-pkgPackageManager::DoInstallPostFork(int statusFd)
-{
-   bool goResult = Go(statusFd);
-   if(goResult == false) 
-      return Failed;
-   
-   return Res;
-}
-#endif
 									/*}}}*/	
 // PM::DoInstall - Does the installation				/*{{{*/
 // ---------------------------------------------------------------------
 /* compat */
-#if APT_PKG_ABI >= 413
 pkgPackageManager::OrderResult 
 pkgPackageManager::DoInstall(int statusFd)
 {
@@ -1132,21 +1118,11 @@ pkgPackageManager::DoInstall(int statusFd)
     delete progress;
     return res;
  }
-#else
-pkgPackageManager::OrderResult pkgPackageManager::DoInstall(int statusFd)
-{
-   if(DoInstallPreFork() == Failed)
-      return Failed;
-
-   return DoInstallPostFork(statusFd);
-}
-#endif
 									/*}}}*/	
 // PM::DoInstall - Does the installation				/*{{{*/
 // ---------------------------------------------------------------------
 /* This uses the filenames in FileNames and the information in the
    DepCache to perform the installation of packages.*/
-#if APT_PKG_ABI >= 413
 pkgPackageManager::OrderResult 
 pkgPackageManager::DoInstall(APT::Progress::PackageManager *progress)
 {
@@ -1155,5 +1131,4 @@ pkgPackageManager::DoInstall(APT::Progress::PackageManager *progress)
    
    return DoInstallPostFork(progress);
 }
-#endif
 									/*}}}*/	      

+ 2 - 12
apt-pkg/packagemanager.h

@@ -1,6 +1,5 @@
 // -*- mode: cpp; mode: fold -*-
 // Description								/*{{{*/
-// $Id: packagemanager.h,v 1.14 2001/05/07 04:24:08 jgg Exp $
 /* ######################################################################
 
    Package Manager - Abstacts the package manager
@@ -96,9 +95,7 @@ class pkgPackageManager : protected pkgCache::Namespace
    virtual bool Install(PkgIterator /*Pkg*/,std::string /*File*/) {return false;};
    virtual bool Configure(PkgIterator /*Pkg*/) {return false;};
    virtual bool Remove(PkgIterator /*Pkg*/,bool /*Purge*/=false) {return false;};
-#if APT_PKG_ABI >= 413
    virtual bool Go(APT::Progress::PackageManager * /*progress*/) {return true;};
-#endif
    virtual bool Go(int /*statusFd*/=-1) {return true;};
 
    virtual void Reset() {};
@@ -113,13 +110,9 @@ class pkgPackageManager : protected pkgCache::Namespace
 		    pkgRecords *Recs);
 
    // Do the installation
-#if APT_PKG_ABI >= 413
    OrderResult DoInstall(APT::Progress::PackageManager *progress);
    // compat
    APT_DEPRECATED OrderResult DoInstall(int statusFd=-1);
-#else
-   OrderResult DoInstall(int statusFd=-1);
-#endif
 
    // stuff that needs to be done before the fork() of a library that
    // uses apt
@@ -127,14 +120,10 @@ class pkgPackageManager : protected pkgCache::Namespace
       Res = OrderInstall();
       return Res;
    };
-#if APT_PKG_ABI >= 413
    // stuff that needs to be done after the fork
    OrderResult DoInstallPostFork(APT::Progress::PackageManager *progress);
    // compat
    APT_DEPRECATED OrderResult DoInstallPostFork(int statusFd=-1);
-#else
-   OrderResult DoInstallPostFork(int statusFd=-1);
-#endif
 
    // ?
    bool FixMissing();
@@ -142,10 +131,11 @@ class pkgPackageManager : protected pkgCache::Namespace
    /** \brief returns all packages dpkg let disappear */
    inline std::set<std::string> GetDisappearedPackages() { return disappearedPkgs; };
 
-   pkgPackageManager(pkgDepCache *Cache);
+   explicit pkgPackageManager(pkgDepCache *Cache);
    virtual ~pkgPackageManager();
 
    private:
+   void * const d;
    enum APT_HIDDEN SmartAction { UNPACK_IMMEDIATE, UNPACK, CONFIGURE };
    APT_HIDDEN bool NonLoopingSmart(SmartAction const action, pkgCache::PkgIterator &Pkg,
       pkgCache::PkgIterator DepPkg, int const Depth, bool const PkgLoop,

+ 160 - 144
apt-pkg/pkgcache.cc

@@ -34,7 +34,8 @@
 
 #include <stddef.h>
 #include <string.h>
-#include <ostream>
+#include <sstream>
+#include <algorithm>
 #include <vector>
 #include <string>
 #include <sys/stat.h>
@@ -50,41 +51,45 @@ using std::string;
 /* Simply initialize the header */
 pkgCache::Header::Header()
 {
-   Signature = 0x98FE76DC;
-   
+#define APT_HEADER_SET(X,Y) X = Y; static_assert(std::numeric_limits<decltype(X)>::max() > Y, "Size violation detected in pkgCache::Header")
+   APT_HEADER_SET(Signature, 0x98FE76DC);
+
    /* Whenever the structures change the major version should be bumped,
       whenever the generator changes the minor version should be bumped. */
-   MajorVersion = 10;
-   MinorVersion = 0;
-   Dirty = false;
-   
-   HeaderSz = sizeof(pkgCache::Header);
-   GroupSz = sizeof(pkgCache::Group);
-   PackageSz = sizeof(pkgCache::Package);
-   PackageFileSz = sizeof(pkgCache::PackageFile);
-   VersionSz = sizeof(pkgCache::Version);
-   DescriptionSz = sizeof(pkgCache::Description);
-   DependencySz = sizeof(pkgCache::Dependency);
-   ProvidesSz = sizeof(pkgCache::Provides);
-   VerFileSz = sizeof(pkgCache::VerFile);
-   DescFileSz = sizeof(pkgCache::DescFile);
-   
+   APT_HEADER_SET(MajorVersion, 10);
+   APT_HEADER_SET(MinorVersion, 0);
+   APT_HEADER_SET(Dirty, false);
+
+   APT_HEADER_SET(HeaderSz, sizeof(pkgCache::Header));
+   APT_HEADER_SET(GroupSz, sizeof(pkgCache::Group));
+   APT_HEADER_SET(PackageSz, sizeof(pkgCache::Package));
+   APT_HEADER_SET(ReleaseFileSz, sizeof(pkgCache::ReleaseFile));
+   APT_HEADER_SET(PackageFileSz, sizeof(pkgCache::PackageFile));
+   APT_HEADER_SET(VersionSz, sizeof(pkgCache::Version));
+   APT_HEADER_SET(DescriptionSz, sizeof(pkgCache::Description));
+   APT_HEADER_SET(DependencySz, sizeof(pkgCache::Dependency));
+   APT_HEADER_SET(DependencyDataSz, sizeof(pkgCache::DependencyData));
+   APT_HEADER_SET(ProvidesSz, sizeof(pkgCache::Provides));
+   APT_HEADER_SET(VerFileSz, sizeof(pkgCache::VerFile));
+   APT_HEADER_SET(DescFileSz, sizeof(pkgCache::DescFile));
+#undef APT_HEADER_SET
+
    GroupCount = 0;
    PackageCount = 0;
    VersionCount = 0;
    DescriptionCount = 0;
    DependsCount = 0;
+   DependsDataCount = 0;
+   ReleaseFileCount = 0;
    PackageFileCount = 0;
    VerFileCount = 0;
    DescFileCount = 0;
    ProvidesCount = 0;
    MaxVerFileSize = 0;
    MaxDescFileSize = 0;
-   
+
    FileList = 0;
-#if APT_PKG_ABI < 413
-   APT_IGNORE_DEPRECATED(StringList = 0;)
-#endif
+   RlsFileList = 0;
    VerSysName = 0;
    Architecture = 0;
    SetArchitectures(0);
@@ -102,10 +107,12 @@ bool pkgCache::Header::CheckSizes(Header &Against) const
    if (HeaderSz == Against.HeaderSz &&
        GroupSz == Against.GroupSz &&
        PackageSz == Against.PackageSz &&
+       ReleaseFileSz == Against.ReleaseFileSz &&
        PackageFileSz == Against.PackageFileSz &&
        VersionSz == Against.VersionSz &&
        DescriptionSz == Against.DescriptionSz &&
        DependencySz == Against.DependencySz &&
+       DependencyDataSz == Against.DependencyDataSz &&
        VerFileSz == Against.VerFileSz &&
        DescFileSz == Against.DescFileSz &&
        ProvidesSz == Against.ProvidesSz)
@@ -118,7 +125,7 @@ bool pkgCache::Header::CheckSizes(Header &Against) const
 // ---------------------------------------------------------------------
 /* */
 APT_IGNORE_DEPRECATED_PUSH
-pkgCache::pkgCache(MMap *Map, bool DoMap) : Map(*Map)
+pkgCache::pkgCache(MMap *Map, bool DoMap) : Map(*Map), d(NULL)
 {
    // call getArchitectures() with cached=false to ensure that the 
    // architectures cache is re-evaulated. this is needed in cases
@@ -140,11 +147,13 @@ bool pkgCache::ReMap(bool const &Errorchecks)
    PkgP = (Package *)Map.Data();
    VerFileP = (VerFile *)Map.Data();
    DescFileP = (DescFile *)Map.Data();
+   RlsFileP = (ReleaseFile *)Map.Data();
    PkgFileP = (PackageFile *)Map.Data();
    VerP = (Version *)Map.Data();
    DescP = (Description *)Map.Data();
    ProvideP = (Provides *)Map.Data();
    DepP = (Dependency *)Map.Data();
+   DepDataP = (DependencyData *)Map.Data();
    StrP = (char *)Map.Data();
 
    if (Errorchecks == false)
@@ -403,10 +412,10 @@ pkgCache::PkgIterator pkgCache::GrpIterator::NextPkg(pkgCache::PkgIterator const
 	return PkgIterator(*Owner, Owner->PkgP + LastPkg->NextPackage);
 }
 									/*}}}*/
-// GrpIterator::operator ++ - Postfix incr				/*{{{*/
+// GrpIterator::operator++ - Prefix incr				/*{{{*/
 // ---------------------------------------------------------------------
 /* This will advance to the next logical group in the hash table. */
-void pkgCache::GrpIterator::operator ++(int)
+pkgCache::GrpIterator& pkgCache::GrpIterator::operator++()
 {
    // Follow the current links
    if (S != Owner->GrpP)
@@ -415,15 +424,16 @@ void pkgCache::GrpIterator::operator ++(int)
    // Follow the hash table
    while (S == Owner->GrpP && (HashIndex+1) < (signed)Owner->HeaderP->GetHashTableSize())
    {
-      HashIndex++;
+      ++HashIndex;
       S = Owner->GrpP + Owner->HeaderP->GrpHashTableP()[HashIndex];
    }
+   return *this;
 }
 									/*}}}*/
-// PkgIterator::operator ++ - Postfix incr				/*{{{*/
+// PkgIterator::operator++ - Prefix incr				/*{{{*/
 // ---------------------------------------------------------------------
 /* This will advance to the next logical package in the hash table. */
-void pkgCache::PkgIterator::operator ++(int)
+pkgCache::PkgIterator& pkgCache::PkgIterator::operator++()
 {
    // Follow the current links
    if (S != Owner->PkgP)
@@ -432,9 +442,22 @@ void pkgCache::PkgIterator::operator ++(int)
    // Follow the hash table
    while (S == Owner->PkgP && (HashIndex+1) < (signed)Owner->HeaderP->GetHashTableSize())
    {
-      HashIndex++;
+      ++HashIndex;
       S = Owner->PkgP + Owner->HeaderP->PkgHashTableP()[HashIndex];
    }
+   return *this;
+}
+									/*}}}*/
+pkgCache::DepIterator& pkgCache::DepIterator::operator++()		/*{{{*/
+{
+   if (S == Owner->DepP)
+      return *this;
+   S = Owner->DepP + (Type == DepVer ? S->NextDepends : S->NextRevDepends);
+   if (S == Owner->DepP)
+      S2 = Owner->DepDataP;
+   else
+      S2 = Owner->DepDataP + S->DependencyData;
+   return *this;
 }
 									/*}}}*/
 // PkgIterator::State - Check the State of the package			/*{{{*/
@@ -536,8 +559,8 @@ std::string pkgCache::PkgIterator::FullName(bool const &Pretty) const
 bool pkgCache::DepIterator::IsCritical() const
 {
    if (IsNegative() == true ||
-       S->Type == pkgCache::Dep::Depends ||
-       S->Type == pkgCache::Dep::PreDepends)
+       S2->Type == pkgCache::Dep::Depends ||
+       S2->Type == pkgCache::Dep::PreDepends)
       return true;
    return false;
 }
@@ -548,9 +571,9 @@ bool pkgCache::DepIterator::IsCritical() const
    are negative like Conflicts which can and should be handled differently */
 bool pkgCache::DepIterator::IsNegative() const
 {
-   return S->Type == Dep::DpkgBreaks ||
-	  S->Type == Dep::Conflicts ||
-	  S->Type == Dep::Obsoletes;
+   return S2->Type == Dep::DpkgBreaks ||
+	  S2->Type == Dep::Conflicts ||
+	  S2->Type == Dep::Obsoletes;
 }
 									/*}}}*/
 // DepIterator::SmartTargetPkg - Resolve dep target pointers w/provides	/*{{{*/
@@ -679,8 +702,8 @@ void pkgCache::DepIterator::GlobOr(DepIterator &Start,DepIterator &End)
    End = *this;
    for (bool LastOR = true; end() == false && LastOR == true;)
    {
-      LastOR = (S->CompareOp & pkgCache::Dep::Or) == pkgCache::Dep::Or;
-      (*this)++;
+      LastOR = (S2->CompareOp & pkgCache::Dep::Or) == pkgCache::Dep::Or;
+      ++(*this);
       if (LastOR == true)
 	 End = (*this);
    }
@@ -690,31 +713,22 @@ void pkgCache::DepIterator::GlobOr(DepIterator &Start,DepIterator &End)
 // ---------------------------------------------------------------------
 /* Deps like self-conflicts should be ignored as well as implicit conflicts
    on virtual packages. */
-bool pkgCache::DepIterator::IsIgnorable(PkgIterator const &/*Pkg*/) const
+bool pkgCache::DepIterator::IsIgnorable(PkgIterator const &PT) const
 {
    if (IsNegative() == false)
       return false;
 
-   pkgCache::PkgIterator PP = ParentPkg();
-   pkgCache::PkgIterator PT = TargetPkg();
+   pkgCache::PkgIterator const PP = ParentPkg();
    if (PP->Group != PT->Group)
       return false;
    // self-conflict
    if (PP == PT)
       return true;
-   pkgCache::VerIterator PV = ParentVer();
+   pkgCache::VerIterator const PV = ParentVer();
    // ignore group-conflict on a M-A:same package - but not our implicit dependencies
    // so that we can have M-A:same packages conflicting with their own real name
    if ((PV->MultiArch & pkgCache::Version::Same) == pkgCache::Version::Same)
-   {
-      // Replaces: ${self}:other ( << ${binary:Version})
-      if (S->Type == pkgCache::Dep::Replaces && S->CompareOp == pkgCache::Dep::Less && strcmp(PV.VerStr(), TargetVer()) == 0)
-	 return false;
-      // Breaks: ${self}:other (!= ${binary:Version})
-      if (S->Type == pkgCache::Dep::DpkgBreaks && S->CompareOp == pkgCache::Dep::NotEquals && strcmp(PV.VerStr(), TargetVer()) == 0)
-	 return false;
-      return true;
-   }
+      return IsMultiArchImplicit() == false;
 
    return false;
 }
@@ -729,35 +743,34 @@ bool pkgCache::DepIterator::IsIgnorable(PrvIterator const &Prv) const
    if (Prv.OwnerPkg()->Group == Pkg->Group)
       return true;
    // Implicit group-conflicts should not be applied on providers of other groups
-   if (Pkg->Group == TargetPkg()->Group && Prv.OwnerPkg()->Group != Pkg->Group)
+   if (IsMultiArchImplicit() && Prv.OwnerPkg()->Group != Pkg->Group)
       return true;
 
    return false;
 }
 									/*}}}*/
-// DepIterator::IsMultiArchImplicit - added by the cache generation	/*{{{*/
-// ---------------------------------------------------------------------
-/* MultiArch can be translated to SingleArch for an resolver and we did so,
-   by adding dependencies to help the resolver understand the problem, but
-   sometimes it is needed to identify these to ignore them… */
-bool pkgCache::DepIterator::IsMultiArchImplicit() const
-{
-   if (ParentPkg()->Arch != TargetPkg()->Arch &&
-       (S->Type == pkgCache::Dep::Replaces ||
-	S->Type == pkgCache::Dep::DpkgBreaks ||
-	S->Type == pkgCache::Dep::Conflicts))
-      return true;
-   return false;
-}
-									/*}}}*/
 // DepIterator::IsSatisfied - check if a version satisfied the dependency /*{{{*/
 bool pkgCache::DepIterator::IsSatisfied(VerIterator const &Ver) const
 {
-   return Owner->VS->CheckDep(Ver.VerStr(),S->CompareOp,TargetVer());
+   return Owner->VS->CheckDep(Ver.VerStr(),S2->CompareOp,TargetVer());
 }
 bool pkgCache::DepIterator::IsSatisfied(PrvIterator const &Prv) const
 {
-   return Owner->VS->CheckDep(Prv.ProvideVersion(),S->CompareOp,TargetVer());
+   return Owner->VS->CheckDep(Prv.ProvideVersion(),S2->CompareOp,TargetVer());
+}
+									/*}}}*/
+// DepIterator::IsImplicit - added by the cache generation		/*{{{*/
+bool pkgCache::DepIterator::IsImplicit() const
+{
+   if (IsMultiArchImplicit() == true)
+      return true;
+   if (IsNegative() || S2->Type == pkgCache::Dep::Replaces)
+   {
+      if ((S2->CompareOp & pkgCache::Dep::ArchSpecific) != pkgCache::Dep::ArchSpecific &&
+	    strcmp(ParentPkg().Arch(), TargetPkg().Arch()) != 0)
+	 return true;
+   }
+   return false;
 }
 									/*}}}*/
 // ostream operator to handle string representation of a dependecy	/*{{{*/
@@ -814,7 +827,7 @@ APT_PURE bool pkgCache::VerIterator::Downloadable() const
 {
    VerFileIterator Files = FileList();
    for (; Files.end() == false; ++Files)
-      if ((Files.File()->Flags & pkgCache::Flag::NotSource) != pkgCache::Flag::NotSource)
+      if (Files.File().Flagged(pkgCache::Flag::NotSource) == false)
 	 return true;
    return false;
 }
@@ -828,7 +841,7 @@ APT_PURE bool pkgCache::VerIterator::Automatic() const
    VerFileIterator Files = FileList();
    for (; Files.end() == false; ++Files)
       // Do not check ButAutomaticUpgrades here as it is kind of automatic…
-      if ((Files.File()->Flags & pkgCache::Flag::NotAutomatic) != pkgCache::Flag::NotAutomatic)
+      if (Files.File().Flagged(pkgCache::Flag::NotAutomatic) == false)
 	 return true;
    return false;
 }
@@ -854,69 +867,54 @@ pkgCache::VerFileIterator pkgCache::VerIterator::NewestFile() const
 // ---------------------------------------------------------------------
 /* This describes the version from a release-centric manner. The output is a 
    list of Label:Version/Archive */
+static std::string PkgFileIteratorToRelString(pkgCache::PkgFileIterator const &File)
+{
+   std::string Res;
+   if (File.Label() != 0)
+      Res = Res + File.Label() + ':';
+
+   if (File.Archive() != 0)
+   {
+      if (File.Version() == 0)
+	 Res += File.Archive();
+      else
+	 Res = Res + File.Version() + '/' +  File.Archive();
+   }
+   else
+   {
+      // No release file, print the host name that this came from
+      if (File.Site() == 0 || File.Site()[0] == 0)
+	 Res += "localhost";
+      else
+	 Res += File.Site();
+   }
+   return Res;
+}
 string pkgCache::VerIterator::RelStr() const
 {
-   bool First = true;
-   string Res;
+   std::vector<std::string> RelStrs;
    for (pkgCache::VerFileIterator I = this->FileList(); I.end() == false; ++I)
    {
       // Do not print 'not source' entries'
-      pkgCache::PkgFileIterator File = I.File();
-      if ((File->Flags & pkgCache::Flag::NotSource) == pkgCache::Flag::NotSource)
+      pkgCache::PkgFileIterator const File = I.File();
+      if (File.Flagged(pkgCache::Flag::NotSource))
 	 continue;
 
-      // See if we have already printed this out..
-      bool Seen = false;
-      for (pkgCache::VerFileIterator J = this->FileList(); I != J; ++J)
-      {
-	 pkgCache::PkgFileIterator File2 = J.File();
-	 if (File2->Label == 0 || File->Label == 0)
-	    continue;
-
-	 if (strcmp(File.Label(),File2.Label()) != 0)
-	    continue;
-	 
-	 if (File2->Version == File->Version)
-	 {
-	    Seen = true;
-	    break;
-	 }
-	 if (File2->Version == 0 || File->Version == 0)
-	    break;
-	 if (strcmp(File.Version(),File2.Version()) == 0)
-	    Seen = true;
-      }
-      
-      if (Seen == true)
+      std::string const RS = PkgFileIteratorToRelString(File);
+      if (std::find(RelStrs.begin(), RelStrs.end(), RS) != RelStrs.end())
 	 continue;
-      
-      if (First == false)
-	 Res += ", ";
-      else
-	 First = false;
-      
-      if (File->Label != 0)
-	 Res = Res + File.Label() + ':';
 
-      if (File->Archive != 0)
-      {
-	 if (File->Version == 0)
-	    Res += File.Archive();
-	 else
-	    Res = Res + File.Version() + '/' +  File.Archive();
-      }
-      else
-      {
-	 // No release file, print the host name that this came from
-	 if (File->Site == 0 || File.Site()[0] == 0)
-	    Res += "localhost";
-	 else
-	    Res += File.Site();
-      }      
+      RelStrs.push_back(RS);
+   }
+   std::ostringstream os;
+   if (likely(RelStrs.empty() == false))
+   {
+      std::copy(RelStrs.begin(), RelStrs.end()-1, std::ostream_iterator<std::string>(os, ", "));
+      os << *RelStrs.rbegin();
    }
    if (S->ParentPkg != 0)
-      Res.append(" [").append(Arch()).append("]");
-   return Res;
+      os << " [" << Arch() << "]";
+   return os.str();
 }
 									/*}}}*/
 // VerIterator::MultiArchType - string representing MultiArch flag	/*{{{*/
@@ -931,12 +929,12 @@ const char * pkgCache::VerIterator::MultiArchType() const
    return "none";
 }
 									/*}}}*/
-// PkgFileIterator::IsOk - Checks if the cache is in sync with the file	/*{{{*/
+// RlsFileIterator::IsOk - Checks if the cache is in sync with the file	/*{{{*/
 // ---------------------------------------------------------------------
 /* This stats the file and compares its stats with the ones that were
-   stored during generation. Date checks should probably also be 
+   stored during generation. Date checks should probably also be
    included here. */
-bool pkgCache::PkgFileIterator::IsOk()
+bool pkgCache::RlsFileIterator::IsOk()
 {
    struct stat Buf;
    if (stat(FileName(),&Buf) != 0)
@@ -948,10 +946,8 @@ bool pkgCache::PkgFileIterator::IsOk()
    return true;
 }
 									/*}}}*/
-// PkgFileIterator::RelStr - Return the release string			/*{{{*/
-// ---------------------------------------------------------------------
-/* */
-string pkgCache::PkgFileIterator::RelStr()
+// RlsFileIterator::RelStr - Return the release string			/*{{{*/
+string pkgCache::RlsFileIterator::RelStr()
 {
    string Res;
    if (Version() != 0)
@@ -964,8 +960,40 @@ string pkgCache::PkgFileIterator::RelStr()
       Res = Res + (Res.empty() == true?"n=":",n=")  + Codename();
    if (Label() != 0)
       Res = Res + (Res.empty() == true?"l=":",l=")  + Label();
-   if (Component() != 0)
-      Res = Res + (Res.empty() == true?"c=":",c=")  + Component();
+   return Res;
+}
+									/*}}}*/
+// PkgFileIterator::IsOk - Checks if the cache is in sync with the file	/*{{{*/
+// ---------------------------------------------------------------------
+/* This stats the file and compares its stats with the ones that were
+   stored during generation. Date checks should probably also be
+   included here. */
+bool pkgCache::PkgFileIterator::IsOk()
+{
+   struct stat Buf;
+   if (stat(FileName(),&Buf) != 0)
+      return false;
+
+   if (Buf.st_size != (signed)S->Size || Buf.st_mtime != S->mtime)
+      return false;
+
+   return true;
+}
+									/*}}}*/
+string pkgCache::PkgFileIterator::RelStr()				/*{{{*/
+{
+   std::string Res;
+   if (ReleaseFile() == 0)
+   {
+      if (Component() != 0)
+	 Res = Res + (Res.empty() == true?"a=":",a=")  + Component();
+   }
+   else
+   {
+      Res = ReleaseFile().RelStr();
+      if (Component() != 0)
+	 Res = Res + (Res.empty() == true?"c=":",c=")  + Component();
+   }
    if (Architecture() != 0)
       Res = Res + (Res.empty() == true?"b=":",b=")  + Architecture();
    return Res;
@@ -1010,17 +1038,5 @@ pkgCache::DescIterator pkgCache::VerIterator::TranslatedDescription() const
 }
 
 									/*}}}*/
-// PrvIterator::IsMultiArchImplicit - added by the cache generation	/*{{{*/
-// ---------------------------------------------------------------------
-/* MultiArch can be translated to SingleArch for an resolver and we did so,
-   by adding provides to help the resolver understand the problem, but
-   sometimes it is needed to identify these to ignore them… */
-bool pkgCache::PrvIterator::IsMultiArchImplicit() const
-{
-   pkgCache::PkgIterator const Owner = OwnerPkg();
-   pkgCache::PkgIterator const Parent = ParentPkg();
-   if (strcmp(Owner.Arch(), Parent.Arch()) != 0 || Owner.Group()->Name == Parent.Group()->Name)
-      return true;
-   return false;
-}
-									/*}}}*/
+
+pkgCache::~pkgCache() {}

+ 149 - 115
apt-pkg/pkgcache.h

@@ -85,45 +85,21 @@
 using std::string;
 #endif
 
-#if APT_PKG_ABI >= 413
+// size of (potentially big) files like debs or the install size of them
+typedef uint64_t map_filesize_t;
 // storing file sizes of indexes, which are way below 4 GB for now
-typedef uint32_t map_filesize_t;
-typedef map_filesize_t should_be_map_filesize_t;
-#else
-typedef unsigned long map_filesize_t;
-typedef unsigned int should_be_map_filesize_t;
-#endif
-#if APT_PKG_ABI >= 413
+typedef uint32_t map_filesize_small_t;
 // each package/group/dependency gets an id
 typedef uint32_t map_id_t;
-typedef map_id_t should_be_map_id_t;
-#else
-typedef unsigned long map_id_t;
-typedef unsigned int should_be_map_id_t;
-#endif
-#if APT_PKG_ABI >= 413
 // some files get an id, too, but in far less absolute numbers
 typedef uint16_t map_fileid_t;
-typedef map_fileid_t should_be_map_fileid_t;
-#else
-typedef unsigned long map_fileid_t;
-typedef unsigned int should_be_map_fileid_t;
-#endif
-#if APT_PKG_ABI >= 413
 // relative pointer from cache start
 typedef uint32_t map_pointer_t;
-#else
-typedef unsigned int map_pointer_t;
-#endif
 // same as the previous, but documented to be to a string item
 typedef map_pointer_t map_stringitem_t;
-#if APT_PKG_ABI >= 413
-typedef uint64_t should_be_uint64_t;
-typedef uint64_t should_be_uint64_small_t;
-#else
-typedef unsigned long long should_be_uint64_t;
-typedef unsigned long should_be_uint64_small_t;
-#endif
+// we have only a small amount of flags for each item
+typedef uint8_t map_flags_t;
+typedef uint8_t map_number_t;
 
 class pkgVersioningSystem;
 class pkgCache								/*{{{*/
@@ -133,11 +109,13 @@ class pkgCache								/*{{{*/
    struct Header;
    struct Group;
    struct Package;
+   struct ReleaseFile;
    struct PackageFile;
    struct Version;
    struct Description;
    struct Provides;
    struct Dependency;
+   struct DependencyData;
    struct StringItem;
    struct VerFile;
    struct DescFile;
@@ -150,6 +128,7 @@ class pkgCache								/*{{{*/
    class DescIterator;
    class DepIterator;
    class PrvIterator;
+   class RlsFileIterator;
    class PkgFileIterator;
    class VerFileIterator;
    class DescFileIterator;
@@ -170,8 +149,12 @@ class pkgCache								/*{{{*/
           The lower 4 bits are used to indicate what operator is being specified and
           the upper 4 bits are flags. OR indicates that the next package is
           or'd with the current package. */
-      enum DepCompareOp {Or=0x10,NoOp=0,LessEq=0x1,GreaterEq=0x2,Less=0x3,
-	 Greater=0x4,Equals=0x5,NotEquals=0x6};
+      enum DepCompareOp {NoOp=0,LessEq=0x1,GreaterEq=0x2,Less=0x3,
+	 Greater=0x4,Equals=0x5,NotEquals=0x6,
+	 Or=0x10, /*!< or'ed with the next dependency */
+	 MultiArchImplicit=0x20, /*!< generated internally, not spelled out in the index */
+	 ArchSpecific=0x40 /*!< was decorated with an explicit architecture in index */
+      };
    };
    
    struct State
@@ -190,7 +173,19 @@ class pkgCache								/*{{{*/
    struct Flag
    {
       enum PkgFlags {Auto=(1<<0),Essential=(1<<3),Important=(1<<4)};
-      enum PkgFFlags {NotSource=(1<<0),NotAutomatic=(1<<1),ButAutomaticUpgrades=(1<<2)};
+      enum PkgFFlags {
+	 NotSource=(1<<0), /*!< packages can't be fetched from here, e.g. dpkg/status file */
+	 LocalSource=(1<<1), /*!< local sources can't and will not be verified by hashes */
+	 NoPackages=(1<<2), /*!< the file includes no package records itself, but additions like Translations */
+      };
+      enum ReleaseFileFlags {
+	 NotAutomatic=(1<<0), /*!< archive has a default pin of 1 */
+	 ButAutomaticUpgrades=(1<<1), /*!< (together with the previous) archive has a default pin of 100 */
+      };
+      enum ProvidesFlags {
+	 MultiArchImplicit=pkgCache::Dep::MultiArchImplicit, /*!< generated internally, not spelled out in the index */
+	 ArchSpecific=pkgCache::Dep::ArchSpecific /*!< was decorated with an explicit architecture in index */
+      };
    };
    
    protected:
@@ -210,11 +205,13 @@ class pkgCache								/*{{{*/
    Package *PkgP;
    VerFile *VerFileP;
    DescFile *DescFileP;
+   ReleaseFile *RlsFileP;
    PackageFile *PkgFileP;
    Version *VerP;
    Description *DescP;
    Provides *ProvideP;
    Dependency *DepP;
+   DependencyData *DepDataP;
    APT_DEPRECATED StringItem *StringItemP;
    char *StrP;
 
@@ -228,7 +225,7 @@ class pkgCache								/*{{{*/
    inline map_id_t Hash(const char *S) const {return sHash(S);}
 
    // Useful transformation things
-   const char *Priority(unsigned char Priority);
+   static const char *Priority(unsigned char Priority);
    
    // Accessors
    GrpIterator FindGrp(const std::string &Name);
@@ -242,6 +239,8 @@ class pkgCache								/*{{{*/
    inline PkgIterator PkgEnd();
    inline PkgFileIterator FileBegin();
    inline PkgFileIterator FileEnd();
+   inline RlsFileIterator RlsFileBegin();
+   inline RlsFileIterator RlsFileEnd();
 
    inline bool MultiArchCache() const { return MultiArchEnabled; }
    inline char const * NativeArch();
@@ -253,11 +252,12 @@ class pkgCache								/*{{{*/
    static const char *CompTypeDeb(unsigned char Comp) APT_CONST;
    static const char *CompType(unsigned char Comp) APT_CONST;
    static const char *DepType(unsigned char Dep);
-   
+
    pkgCache(MMap *Map,bool DoMap = true);
-   virtual ~pkgCache() {}
+   virtual ~pkgCache();
 
 private:
+   void * const d;
    bool MultiArchEnabled;
    APT_HIDDEN PkgIterator SingleArchFindPkg(const std::string &Name);
 };
@@ -270,10 +270,10 @@ struct pkgCache::Header
        This must contain the hex value 0x98FE76DC which is designed to
        verify that the system loading the image has the same byte order
        and byte size as the system saving the image */
-   unsigned long Signature;
+   uint32_t Signature;
    /** These contain the version of the cache file */
-   short MajorVersion;
-   short MinorVersion;
+   map_number_t MajorVersion;
+   map_number_t MinorVersion;
    /** \brief indicates if the cache should be erased
 
        Dirty is true if the cache file was opened for reading, the client
@@ -288,16 +288,18 @@ struct pkgCache::Header
 
        If any of the size values do not exactly match what the client expects
        then the client should refuse the load the file. */
-   unsigned short HeaderSz;
-   unsigned short GroupSz;
-   unsigned short PackageSz;
-   unsigned short PackageFileSz;
-   unsigned short VersionSz;
-   unsigned short DescriptionSz;
-   unsigned short DependencySz;
-   unsigned short ProvidesSz;
-   unsigned short VerFileSz;
-   unsigned short DescFileSz;
+   uint16_t HeaderSz;
+   map_number_t GroupSz;
+   map_number_t PackageSz;
+   map_number_t ReleaseFileSz;
+   map_number_t PackageFileSz;
+   map_number_t VersionSz;
+   map_number_t DescriptionSz;
+   map_number_t DependencySz;
+   map_number_t DependencyDataSz;
+   map_number_t ProvidesSz;
+   map_number_t VerFileSz;
+   map_number_t DescFileSz;
 
    /** \brief Structure counts
 
@@ -309,6 +311,8 @@ struct pkgCache::Header
    map_id_t VersionCount;
    map_id_t DescriptionCount;
    map_id_t DependsCount;
+   map_id_t DependsDataCount;
+   map_fileid_t ReleaseFileCount;
    map_fileid_t PackageFileCount;
    map_fileid_t VerFileCount;
    map_fileid_t DescFileCount;
@@ -319,17 +323,15 @@ struct pkgCache::Header
        The PackageFile structures are singly linked lists that represent
        all package files that have been merged into the cache. */
    map_pointer_t FileList;
-#if APT_PKG_ABI < 413
-   APT_DEPRECATED map_pointer_t StringList;
-#endif
+   /** \brief index of the first ReleaseFile structure */
+   map_pointer_t RlsFileList;
+
    /** \brief String representing the version system used */
    map_pointer_t VerSysName;
    /** \brief native architecture the cache was built against */
    map_pointer_t Architecture;
-#if APT_PKG_ABI >= 413
    /** \brief all architectures the cache was built against */
    map_pointer_t Architectures;
-#endif
    /** \brief The maximum size of a raw entry from the original Package file */
    map_filesize_t MaxVerFileSize;
    /** \brief The maximum size of a raw entry from the original Translation file */
@@ -343,7 +345,7 @@ struct pkgCache::Header
        the same number of pools as there are structure types. The generator
        stores this information so future additions can make use of any unused pool
        blocks. */
-   DynamicMMap::Pool Pools[9];
+   DynamicMMap::Pool Pools[12];
 
    /** \brief hash tables providing rapid group/package name lookup
 
@@ -355,26 +357,16 @@ struct pkgCache::Header
        In the PkgHashTable is it possible that multiple packages have the same name -
        these packages are stored as a sequence in the list.
        The size of both tables is the same. */
-#if APT_PKG_ABI >= 413
-   unsigned int HashTableSize;
-   unsigned int GetHashTableSize() const { return HashTableSize; }
+   uint32_t HashTableSize;
+   uint32_t GetHashTableSize() const { return HashTableSize; }
    void SetHashTableSize(unsigned int const sz) { HashTableSize = sz; }
    map_pointer_t GetArchitectures() const { return Architectures; }
    void SetArchitectures(map_pointer_t const idx) { Architectures = idx; }
-#else
-   // BEWARE: these tables are pretty much empty and just here for abi compat
-   map_ptrloc PkgHashTable[2*1048];
-   map_ptrloc GrpHashTable[2*1048];
-   unsigned int GetHashTableSize() const { return PkgHashTable[0]; }
-   void SetHashTableSize(unsigned int const sz) { PkgHashTable[0] = sz; }
-   map_pointer_t GetArchitectures() const { return PkgHashTable[1]; }
-   void SetArchitectures(map_pointer_t const idx) { PkgHashTable[1] = idx; }
-#endif
    map_pointer_t * PkgHashTableP() const { return (map_pointer_t*) (this + 1); }
    map_pointer_t * GrpHashTableP() const { return PkgHashTableP() + GetHashTableSize(); }
 
    /** \brief Size of the complete cache file */
-   should_be_uint64_small_t CacheFileSize;
+   map_filesize_small_t CacheFileSize;
 
    bool CheckSizes(Header &Against) const APT_PURE;
    Header();
@@ -400,7 +392,7 @@ struct pkgCache::Group
    /** \brief Link to the next Group */
    map_pointer_t Next;		// Group
    /** \brief unique sequel ID */
-   should_be_map_id_t ID;
+   map_id_t ID;
 
 };
 									/*}}}*/
@@ -437,12 +429,6 @@ struct pkgCache::Package
    map_pointer_t VersionList;       // Version
    /** \brief index to the installed version */
    map_pointer_t CurrentVer;        // Version
-   /** \brief indicates nothing (consistently)
-       This field used to contain ONE section the package belongs to,
-       if those differs between versions it is a RANDOM one.
-       The Section() method tries to reproduce it, but the only sane
-       thing to do is use the Section field from the version! */
-   APT_DEPRECATED map_ptrloc Section; // StringItem
    /** \brief index of the group this package belongs to */
    map_pointer_t Group;             // Group the Package belongs to
 
@@ -456,15 +442,15 @@ struct pkgCache::Package
 
    // Install/Remove/Purge etc
    /** \brief state that the user wishes the package to be in */
-   unsigned char SelectedState;     // What
+   map_number_t SelectedState;     // What
    /** \brief installation state of the package
 
        This should be "ok" but in case the installation failed
        it will be different.
    */
-   unsigned char InstState;         // Flags
+   map_number_t InstState;         // Flags
    /** \brief indicates if the package is installed */
-   unsigned char CurrentState;      // State
+   map_number_t CurrentState;      // State
 
    /** \brief unique sequel ID
 
@@ -472,20 +458,19 @@ struct pkgCache::Package
        This allows clients to create an array of size PackageCount and use it to store
        state information for the package map. For instance the status file emitter uses
        this to track which packages have been emitted already. */
-   should_be_map_id_t ID;
+   map_id_t ID;
    /** \brief some useful indicators of the package's state */
-   unsigned long Flags;
+   map_flags_t Flags;
 };
 									/*}}}*/
-// Package File structure						/*{{{*/
-/** \brief stores information about the files used to generate the cache
+// Release File structure						/*{{{*/
+/** \brief stores information about the release files used to generate the cache
 
-    Package files are referenced by Version structures to be able to know
-    after the generation still from which Packages file includes this Version
-    as we need this information later on e.g. for pinning. */
-struct pkgCache::PackageFile
+    PackageFiles reference ReleaseFiles as we need to keep record of which
+    version belongs to which release e.g. for pinning. */
+struct pkgCache::ReleaseFile
 {
-   /** \brief physical disk file that this PackageFile represents */
+   /** \brief physical disk file that this ReleaseFile represents */
    map_stringitem_t FileName;
    /** \brief the release information
 
@@ -493,13 +478,47 @@ struct pkgCache::PackageFile
        release information means. */
    map_stringitem_t Archive;
    map_stringitem_t Codename;
-   map_stringitem_t Component;
    map_stringitem_t Version;
    map_stringitem_t Origin;
    map_stringitem_t Label;
-   map_stringitem_t Architecture;
    /** \brief The site the index file was fetched from */
    map_stringitem_t Site;
+
+   /** \brief Size of the file
+
+       Used together with the modification time as a
+       simple check to ensure that the Packages
+       file has not been altered since Cache generation. */
+   map_filesize_t Size;
+   /** \brief Modification time for the file */
+   time_t mtime;
+
+   /** @TODO document PackageFile::Flags */
+   map_flags_t Flags;
+
+   // Linked list
+   /** \brief Link to the next ReleaseFile in the Cache */
+   map_pointer_t NextFile;
+   /** \brief unique sequel ID */
+   map_fileid_t ID;
+};
+									/*}}}*/
+// Package File structure						/*{{{*/
+/** \brief stores information about the files used to generate the cache
+
+    Package files are referenced by Version structures to be able to know
+    after the generation still from which Packages file includes this Version
+    as we need this information later on e.g. for pinning. */
+struct pkgCache::PackageFile
+{
+   /** \brief physical disk file that this PackageFile represents */
+   map_stringitem_t FileName;
+   /** \brief the release information */
+   map_pointer_t Release;
+
+   map_stringitem_t Component;
+   map_stringitem_t Architecture;
+
    /** \brief indicates what sort of index file this is
 
        @TODO enumerate at least the possible indexes */
@@ -514,13 +533,13 @@ struct pkgCache::PackageFile
    time_t mtime;
 
    /** @TODO document PackageFile::Flags */
-   unsigned long Flags;
+   map_flags_t Flags;
 
    // Linked list
    /** \brief Link to the next PackageFile in the Cache */
    map_pointer_t NextFile;        // PackageFile
    /** \brief unique sequel ID */
-   should_be_map_fileid_t ID;
+   map_fileid_t ID;
 };
 									/*}}}*/
 // VerFile structure							/*{{{*/
@@ -535,7 +554,7 @@ struct pkgCache::VerFile
    /** \brief next step in the linked list */
    map_pointer_t NextFile;       // PkgVerFile
    /** \brief position in the package file */
-   should_be_map_filesize_t Offset;         // File offset
+   map_filesize_t Offset;         // File offset
    /** @TODO document pkgCache::VerFile::Size */
    map_filesize_t Size;
 };
@@ -549,7 +568,7 @@ struct pkgCache::DescFile
    /** \brief next step in the linked list */
    map_pointer_t NextFile;       // PkgVerFile
    /** \brief position in the file */
-   should_be_map_filesize_t Offset;         // File offset
+   map_filesize_t Offset;         // File offset
    /** @TODO document pkgCache::DescFile::Size */
    map_filesize_t Size;
 };
@@ -566,28 +585,30 @@ struct pkgCache::Version
    map_stringitem_t VerStr;
    /** \brief section this version is filled in */
    map_stringitem_t Section;
-#if APT_PKG_ABI >= 413
    /** \brief source package name this version comes from
       Always contains the name, even if it is the same as the binary name */
    map_stringitem_t SourcePkgName;
    /** \brief source version this version comes from
       Always contains the version string, even if it is the same as the binary version */
    map_stringitem_t SourceVerStr;
-#endif
 
    /** \brief Multi-Arch capabilities of a package version */
-   enum VerMultiArch { None = 0, /*!< is the default and doesn't trigger special behaviour */
+   enum VerMultiArch { No = 0, /*!< is the default and doesn't trigger special behaviour */
 		       All = (1<<0), /*!< will cause that Ver.Arch() will report "all" */
 		       Foreign = (1<<1), /*!< can satisfy dependencies in another architecture */
 		       Same = (1<<2), /*!< can be co-installed with itself from other architectures */
 		       Allowed = (1<<3), /*!< other packages are allowed to depend on thispkg:any */
 		       AllForeign = All | Foreign,
 		       AllAllowed = All | Allowed };
+
+   /** \brief deprecated variant of No */
+   static const APT_DEPRECATED VerMultiArch None = No;
+
    /** \brief stores the MultiArch capabilities of this version
 
        Flags used are defined in pkgCache::Version::VerMultiArch
    */
-   unsigned char MultiArch;
+   map_number_t MultiArch;
 
    /** \brief references all the PackageFile's that this version came from
 
@@ -612,18 +633,18 @@ struct pkgCache::Version
    /** \brief archive size for this version
 
        For Debian this is the size of the .deb file. */
-   should_be_uint64_t Size; // These are the .deb size
+   map_filesize_t Size; // These are the .deb size
    /** \brief uncompressed size for this version */
-   should_be_uint64_t InstalledSize;
+   map_filesize_t InstalledSize;
    /** \brief characteristic value representing this version
 
        No two packages in existence should have the same VerStr
        and Hash with different contents. */
    unsigned short Hash;
    /** \brief unique sequel ID */
-   should_be_map_id_t ID;
+   map_id_t ID;
    /** \brief parsed priority value */
-   unsigned char Priority;
+   map_number_t Priority;
 };
 									/*}}}*/
 // Description structure						/*{{{*/
@@ -649,7 +670,7 @@ struct pkgCache::Description
    map_pointer_t ParentPkg;         // Package
 
    /** \brief unique sequel ID */
-   should_be_map_id_t ID;
+   map_id_t ID;
 };
 									/*}}}*/
 // Dependency structure							/*{{{*/
@@ -659,7 +680,7 @@ struct pkgCache::Description
     The base of the linked list is pkgCache::Version::DependsList.
     All forms of dependencies are recorded here including Depends,
     Recommends, Suggests, Enhances, Conflicts, Replaces and Breaks. */
-struct pkgCache::Dependency
+struct pkgCache::DependencyData
 {
    /** \brief string of the version the dependency is applied against */
    map_stringitem_t Version;
@@ -668,21 +689,28 @@ struct pkgCache::Dependency
        The generator will - if the package does not already exist -
        create a blank (no version records) package. */
    map_pointer_t Package;         // Package
-   /** \brief next dependency of this version */
-   map_pointer_t NextDepends;     // Dependency
-   /** \brief next reverse dependency of this package */
-   map_pointer_t NextRevDepends;  // Dependency
-   /** \brief version of the package which has the reverse depends */
-   map_pointer_t ParentVer;       // Version
 
-   /** \brief unique sequel ID */
-   should_be_map_id_t ID;
    /** \brief Dependency type - Depends, Recommends, Conflicts, etc */
-   unsigned char Type;
+   map_number_t Type;
    /** \brief comparison operator specified on the depends line
 
        If the high bit is set then it is a logical OR with the previous record. */
-   unsigned char CompareOp;
+   map_flags_t CompareOp;
+
+   map_pointer_t NextData;
+};
+struct pkgCache::Dependency
+{
+   map_pointer_t DependencyData;  // DependencyData
+   /** \brief version of the package which has the depends */
+   map_pointer_t ParentVer;       // Version
+   /** \brief next reverse dependency of this package */
+   map_pointer_t NextRevDepends;  // Dependency
+   /** \brief next dependency of this version */
+   map_pointer_t NextDepends;     // Dependency
+
+   /** \brief unique sequel ID */
+   map_id_t ID;
 };
 									/*}}}*/
 // Provides structure							/*{{{*/
@@ -703,9 +731,9 @@ struct pkgCache::Provides
    /** \brief version in the provides line (if any)
 
        This version allows dependencies to depend on specific versions of a
-       Provides, as well as allowing Provides to override existing packages.
-       This is experimental. Note that Debian doesn't allow versioned provides */
+       Provides, as well as allowing Provides to override existing packages. */
    map_stringitem_t ProvideVersion;
+   map_flags_t Flags;
    /** \brief next provides (based of package) */
    map_pointer_t NextProvides;     // Provides
    /** \brief next provides (based of version) */
@@ -739,6 +767,11 @@ inline pkgCache::PkgFileIterator pkgCache::FileBegin()
        {return PkgFileIterator(*this,PkgFileP + HeaderP->FileList);}
 inline pkgCache::PkgFileIterator pkgCache::FileEnd()
        {return PkgFileIterator(*this,PkgFileP);}
+inline pkgCache::RlsFileIterator pkgCache::RlsFileBegin()
+       {return RlsFileIterator(*this,RlsFileP + HeaderP->RlsFileList);}
+inline pkgCache::RlsFileIterator pkgCache::RlsFileEnd()
+       {return RlsFileIterator(*this,RlsFileP);}
+
 
 // Oh I wish for Real Name Space Support
 class pkgCache::Namespace						/*{{{*/
@@ -750,6 +783,7 @@ class pkgCache::Namespace						/*{{{*/
    typedef pkgCache::DescIterator DescIterator;
    typedef pkgCache::DepIterator DepIterator;
    typedef pkgCache::PrvIterator PrvIterator;
+   typedef pkgCache::RlsFileIterator RlsFileIterator;
    typedef pkgCache::PkgFileIterator PkgFileIterator;
    typedef pkgCache::VerFileIterator VerFileIterator;
    typedef pkgCache::Version Version;

Rozdílová data souboru nebyla zobrazena, protože soubor je příliš velký
+ 562 - 445
apt-pkg/pkgcachegen.cc


+ 32 - 39
apt-pkg/pkgcachegen.h

@@ -1,6 +1,5 @@
 // -*- mode: cpp; mode: fold -*-
 // Description								/*{{{*/
-// $Id: pkgcachegen.h,v 1.19 2002/07/08 03:13:30 jgg Exp $
 /* ######################################################################
    
    Package Cache Generator - Generator for the cache structure.
@@ -33,10 +32,10 @@ class FileFd;
 class pkgSourceList;
 class OpProgress;
 class pkgIndexFile;
+class pkgCacheListParser;
 
 class APT_HIDDEN pkgCacheGenerator					/*{{{*/
 {
-   private:
    APT_HIDDEN map_stringitem_t WriteStringInMap(std::string const &String) { return WriteStringInMap(String.c_str()); };
    APT_HIDDEN map_stringitem_t WriteStringInMap(const char *String);
    APT_HIDDEN map_stringitem_t WriteStringInMap(const char *String, const unsigned long &Len);
@@ -47,15 +46,15 @@ class APT_HIDDEN pkgCacheGenerator					/*{{{*/
    std::map<std::string,map_stringitem_t> strPkgNames;
    std::map<std::string,map_stringitem_t> strVersions;
 
+   friend class pkgCacheListParser;
+   typedef pkgCacheListParser ListParser;
+
    public:
-   
-   class ListParser;
-   friend class ListParser;
 
    template<typename Iter> class Dynamic {
       public:
       static std::vector<Iter*> toReMap;
-      Dynamic(Iter &I) {
+      explicit Dynamic(Iter &I) {
 	 toReMap.push_back(&I);
       }
 
@@ -69,29 +68,27 @@ class APT_HIDDEN pkgCacheGenerator					/*{{{*/
    DynamicMMap &Map;
    pkgCache Cache;
    OpProgress *Progress;
-   
+
+   std::string RlsFileName;
+   pkgCache::ReleaseFile *CurrentRlsFile;
    std::string PkgFileName;
    pkgCache::PackageFile *CurrentFile;
 
-   // Flag file dependencies
-   bool FoundFileDeps;
-   
    bool NewGroup(pkgCache::GrpIterator &Grp,const std::string &Name);
    bool NewPackage(pkgCache::PkgIterator &Pkg,const std::string &Name, const std::string &Arch);
    bool NewFileVer(pkgCache::VerIterator &Ver,ListParser &List);
    bool NewFileDesc(pkgCache::DescIterator &Desc,ListParser &List);
    bool NewDepends(pkgCache::PkgIterator &Pkg, pkgCache::VerIterator &Ver,
-		   std::string const &Version, unsigned int const &Op,
-		   unsigned int const &Type, map_pointer_t* &OldDepLast);
-   bool NewDepends(pkgCache::PkgIterator &Pkg, pkgCache::VerIterator &Ver,
-		   map_pointer_t const Version, unsigned int const &Op,
-		   unsigned int const &Type, map_pointer_t* &OldDepLast);
+		   map_pointer_t const Version, uint8_t const Op,
+		   uint8_t const Type, map_pointer_t* &OldDepLast);
    map_pointer_t NewVersion(pkgCache::VerIterator &Ver,const std::string &VerStr,map_pointer_t const Next) APT_DEPRECATED
    { return NewVersion(Ver, VerStr, 0, 0, Next); }
    map_pointer_t NewVersion(pkgCache::VerIterator &Ver,const std::string &VerStr,
 			    map_pointer_t const ParentPkg, unsigned short const Hash,
 			    map_pointer_t const Next);
    map_pointer_t NewDescription(pkgCache::DescIterator &Desc,const std::string &Lang,const MD5SumValue &md5sum,map_stringitem_t const idxmd5str);
+   bool NewProvides(pkgCache::VerIterator &Ver, pkgCache::PkgIterator &Pkg,
+		    map_stringitem_t const ProvidesVersion, uint8_t const Flags);
 
    public:
 
@@ -100,28 +97,26 @@ class APT_HIDDEN pkgCacheGenerator					/*{{{*/
    inline map_stringitem_t StoreString(enum StringType const type, const std::string &S) {return StoreString(type, S.c_str(),S.length());};
 
    void DropProgress() {Progress = 0;};
-   bool SelectFile(const std::string &File,const std::string &Site,pkgIndexFile const &Index,
-		   unsigned long Flags = 0);
+   bool SelectFile(const std::string &File,pkgIndexFile const &Index, std::string const &Architecture, std::string const &Component, unsigned long Flags = 0);
+   bool SelectReleaseFile(const std::string &File, const std::string &Site, unsigned long Flags = 0);
    bool MergeList(ListParser &List,pkgCache::VerIterator *Ver = 0);
    inline pkgCache &GetCache() {return Cache;};
-   inline pkgCache::PkgFileIterator GetCurFile() 
+   inline pkgCache::PkgFileIterator GetCurFile()
          {return pkgCache::PkgFileIterator(Cache,CurrentFile);};
-
-   bool HasFileDeps() {return FoundFileDeps;};
-   bool MergeFileProvides(ListParser &List);
-   bool FinishCache(OpProgress *Progress) APT_DEPRECATED APT_CONST;
+   inline pkgCache::RlsFileIterator GetCurRlsFile()
+         {return pkgCache::RlsFileIterator(Cache,CurrentRlsFile);};
 
    APT_PUBLIC static bool MakeStatusCache(pkgSourceList &List,OpProgress *Progress,
 			MMap **OutMap = 0,bool AllowMem = false);
    APT_PUBLIC static bool MakeOnlyStatusCache(OpProgress *Progress,DynamicMMap **OutMap);
-   APT_PUBLIC static DynamicMMap* CreateDynamicMMap(FileFd *CacheF, unsigned long Flags = 0);
 
    void ReMap(void const * const oldMap, void const * const newMap);
 
    pkgCacheGenerator(DynamicMMap *Map,OpProgress *Progress);
-   ~pkgCacheGenerator();
+   virtual ~pkgCacheGenerator();
 
    private:
+   void * const d;
    APT_HIDDEN bool MergeListGroup(ListParser &List, std::string const &GrpName);
    APT_HIDDEN bool MergeListPackage(ListParser &List, pkgCache::PkgIterator &Pkg);
    APT_HIDDEN bool MergeListVersion(ListParser &List, pkgCache::PkgIterator &Pkg,
@@ -136,18 +131,17 @@ class APT_HIDDEN pkgCacheGenerator					/*{{{*/
 };
 									/*}}}*/
 // This is the abstract package list parser class.			/*{{{*/
-class APT_HIDDEN pkgCacheGenerator::ListParser
+class APT_HIDDEN pkgCacheListParser
 {
    pkgCacheGenerator *Owner;
    friend class pkgCacheGenerator;
-   
+
    // Some cache items
    pkgCache::VerIterator OldDepVer;
    map_pointer_t *OldDepLast;
 
-   // Flag file dependencies
-   bool FoundFileDeps;
-      
+   void * const d;
+
    protected:
 
    inline map_stringitem_t StoreString(pkgCacheGenerator::StringType const type, std::string const &S) {return Owner->StoreString(type, S);};
@@ -156,10 +150,13 @@ class APT_HIDDEN pkgCacheGenerator::ListParser
    inline map_stringitem_t WriteString(const std::string &S) {return Owner->WriteStringInMap(S);};
    inline map_stringitem_t WriteString(const char *S,unsigned int Size) {return Owner->WriteStringInMap(S,Size);};
    bool NewDepends(pkgCache::VerIterator &Ver,const std::string &Package, const std::string &Arch,
-		   const std::string &Version,unsigned int Op,
-		   unsigned int Type);
+		   const std::string &Version,uint8_t const Op,
+		   uint8_t const Type);
    bool NewProvides(pkgCache::VerIterator &Ver,const std::string &PkgName,
-		    const std::string &PkgArch, const std::string &Version);
+		    const std::string &PkgArch, const std::string &Version,
+		    uint8_t const Flags);
+   bool NewProvidesAllArch(pkgCache::VerIterator &Ver, std::string const &Package,
+			   std::string const &Version, uint8_t const Flags);
    
    public:
    
@@ -178,10 +175,7 @@ class APT_HIDDEN pkgCacheGenerator::ListParser
     * \param Hash of the currently parsed version
     * \param Ver to compare with
     */
-#if APT_PKG_ABI >= 413
-   virtual
-#endif
-      APT_PURE bool SameVersion(unsigned short const Hash, pkgCache::VerIterator const &Ver);
+   virtual bool SameVersion(unsigned short const Hash, pkgCache::VerIterator const &Ver);
    virtual bool UsePackage(pkgCache::PkgIterator &Pkg,
 			   pkgCache::VerIterator &Ver) = 0;
    virtual map_filesize_t Offset() = 0;
@@ -189,12 +183,11 @@ class APT_HIDDEN pkgCacheGenerator::ListParser
    
    virtual bool Step() = 0;
    
-   inline bool HasFileDeps() {return FoundFileDeps;};
    virtual bool CollectFileProvides(pkgCache &/*Cache*/,
 				    pkgCache::VerIterator &/*Ver*/) {return true;};
 
-   ListParser() : Owner(NULL), OldDepLast(NULL), FoundFileDeps(false) {};
-   virtual ~ListParser() {};
+   pkgCacheListParser();
+   virtual ~pkgCacheListParser();
 };
 									/*}}}*/
 

+ 3 - 0
apt-pkg/pkgrecords.cc

@@ -76,3 +76,6 @@ pkgRecords::Parser &pkgRecords::Lookup(pkgCache::DescFileIterator const &Desc)
    return *Files[Desc.File()->ID];
 }
 									/*}}}*/
+
+pkgRecords::Parser::Parser() : d(NULL) {}
+pkgRecords::Parser::~Parser() {}

+ 7 - 12
apt-pkg/pkgrecords.h

@@ -31,7 +31,7 @@ class pkgRecords							/*{{{*/
    
    private:
    /** \brief dpointer placeholder (for later in case we need it) */
-   void *d;
+   void * const d;
    
    pkgCache &Cache;
    std::vector<Parser *>Files;
@@ -42,8 +42,8 @@ class pkgRecords							/*{{{*/
    Parser &Lookup(pkgCache::DescFileIterator const &Desc);
 
    // Construct destruct
-   pkgRecords(pkgCache &Cache);
-   ~pkgRecords();
+   explicit pkgRecords(pkgCache &Cache);
+   virtual ~pkgRecords();
 };
 									/*}}}*/
 class pkgRecords::Parser						/*{{{*/
@@ -68,17 +68,10 @@ class pkgRecords::Parser						/*{{{*/
     * choose the hash to be used.
     */
    virtual HashStringList Hashes() const { return HashStringList(); };
-#if APT_PKG_ABI >= 413
    APT_DEPRECATED std::string MD5Hash() const { return GetHashFromHashes("MD5Sum"); };
    APT_DEPRECATED std::string SHA1Hash() const { return GetHashFromHashes("SHA1"); };
    APT_DEPRECATED std::string SHA256Hash() const { return GetHashFromHashes("SHA256"); };
    APT_DEPRECATED std::string SHA512Hash() const { return GetHashFromHashes("SHA512"); };
-#else
-   APT_DEPRECATED std::string MD5Hash() { return GetHashFromHashes("MD5Sum"); };
-   APT_DEPRECATED std::string SHA1Hash() { return GetHashFromHashes("SHA1"); };
-   APT_DEPRECATED std::string SHA256Hash() { return GetHashFromHashes("SHA256"); };
-   APT_DEPRECATED std::string SHA512Hash() { return GetHashFromHashes("SHA512"); };
-#endif
 
    // These are some general stats about the package
    virtual std::string Maintainer() {return std::string();};
@@ -106,10 +99,12 @@ class pkgRecords::Parser						/*{{{*/
 
    // The record in binary form
    virtual void GetRec(const char *&Start,const char *&Stop) {Start = Stop = 0;};
-   
-   virtual ~Parser() {};
+
+   Parser();
+   virtual ~Parser();
 
    private:
+   void * const d;
    APT_HIDDEN std::string GetHashFromHashes(char const * const type) const
    {
       HashStringList const hashes = Hashes();

+ 4 - 1
apt-pkg/pkgsystem.cc

@@ -27,7 +27,8 @@ unsigned long pkgSystem::GlobalListLen = 0;
 // System::pkgSystem - Constructor					/*{{{*/
 // ---------------------------------------------------------------------
 /* Add it to the global list.. */
-pkgSystem::pkgSystem() : Label(NULL), VS(NULL)
+pkgSystem::pkgSystem(char const * const label, pkgVersioningSystem * const vs) :
+   Label(label), VS(vs), d(NULL)
 {
    assert(GlobalListLen < sizeof(SysList)/sizeof(*SysList));
    SysList[GlobalListLen] = this;
@@ -45,3 +46,5 @@ APT_PURE pkgSystem *pkgSystem::GetSystem(const char *Label)
    return 0;   
 }
 									/*}}}*/
+
+pkgSystem::~pkgSystem() {}

+ 0 - 0
apt-pkg/pkgsystem.h


Některé soubory nejsou zobrazeny, neboť je v těchto rozdílových datech změněno mnoho souborů