* apt-pkg/indexcopy.cc:
authorDavid Kalnischkies <kalnischkies@gmail.com>
Sun, 2 Sep 2012 16:31:07 +0000 (18:31 +0200)
committerDavid Kalnischkies <kalnischkies@gmail.com>
Sun, 2 Sep 2012 16:31:07 +0000 (18:31 +0200)
  - do not create duplicated flat-archive cdrom sources for foreign
    architectures on multi-arch cdroms

apt-pkg/indexcopy.cc
debian/changelog
test/libapt/indexcopytosourcelist_test.cc [new file with mode: 0644]
test/libapt/makefile

index c974453..24defd8 100644 (file)
@@ -350,9 +350,6 @@ bool IndexCopy::ReconstructChop(unsigned long &Chop,string Dir,string File)
  */
 void IndexCopy::ConvertToSourceList(string CD,string &Path)
 {
-   char S[300];
-   snprintf(S,sizeof(S),"binary-%s",_config->Find("Apt::Architecture").c_str());
-   
    // Strip the cdrom base path
    Path = string(Path,CD.length());
    if (Path.empty() == true)
@@ -388,7 +385,13 @@ void IndexCopy::ConvertToSourceList(string CD,string &Path)
         return;
       string Binary = string(Path,Slash+1,BinSlash - Slash-1);
       
-      if (Binary != S && Binary != "source")
+      if (strncmp(Binary.c_str(), "binary-", strlen("binary-")) == 0)
+      {
+        Binary.erase(0, strlen("binary-"));
+        if (APT::Configuration::checkArchitecture(Binary) == false)
+           continue;
+      }
+      else if (Binary != "source")
         continue;
 
       Path = Dist + ' ' + Comp;
index a673040..4533d27 100644 (file)
@@ -15,7 +15,9 @@ apt (0.9.7.5) UNRELEASED; urgency=low
   * doc/apt_preferences.5.xml:
     - use the correct interval (x <= P < y) for pin value documentation as
       these are the intervals used by the code (Closes: #685989)
-  * 
+  * apt-pkg/indexcopy.cc:
+    - do not create duplicated flat-archive cdrom sources for foreign
+      architectures on multi-arch cdroms
 
  -- David Kalnischkies <kalnischkies@gmail.com>  Sun, 26 Aug 2012 10:49:17 +0200
 
diff --git a/test/libapt/indexcopytosourcelist_test.cc b/test/libapt/indexcopytosourcelist_test.cc
new file mode 100644 (file)
index 0000000..69d8fae
--- /dev/null
@@ -0,0 +1,86 @@
+#include <apt-pkg/configuration.h>
+#include <apt-pkg/aptconfiguration.h>
+#include <apt-pkg/indexcopy.h>
+
+#include <string>
+
+#include "assert.h"
+
+class NoCopy : public IndexCopy {
+public:
+   std::string ConvertToSourceList(std::string CD,std::string Path) {
+      IndexCopy::ConvertToSourceList(CD, Path);
+      return Path;
+   }
+   bool GetFile(std::string &Filename,unsigned long long &Size) { return false; }
+   bool RewriteEntry(FILE *Target,std::string File) { return false; }
+   const char *GetFileName() { return NULL; }
+   const char *Type() { return NULL; }
+
+};
+
+int main(int argc, char const *argv[]) {
+   NoCopy ic;
+   std::string const CD("/media/cdrom/");
+
+   char const * Releases[] = { "unstable", "wheezy-updates", NULL };
+   char const * Components[] = { "main", "non-free", NULL };
+
+   for (char const ** Release = Releases; *Release != NULL; ++Release) {
+      for (char const ** Component = Components; *Component != NULL; ++Component) {
+        std::string const Path = std::string("dists/") + *Release + "/" + *Component + "/";
+        std::string const Binary = Path + "binary-";
+        std::string const A = Binary + "armel/";
+        std::string const B = Binary + "mips/";
+        std::string const C = Binary + "kfreebsd-mips/";
+        std::string const S = Path + "source/";
+        std::string const List = std::string(*Release) + " " + *Component;
+
+        _config->Clear("APT");
+        APT::Configuration::getArchitectures(false);
+        equals(ic.ConvertToSourceList("/media/cdrom/", CD + A), A);
+        equals(ic.ConvertToSourceList("/media/cdrom/", CD + B), B);
+        equals(ic.ConvertToSourceList("/media/cdrom/", CD + C), C);
+        equals(ic.ConvertToSourceList("/media/cdrom/", CD + S), List);
+
+        _config->Clear("APT");
+        _config->Set("APT::Architecture", "mips");
+        _config->Set("APT::Architectures::", "mips");
+        APT::Configuration::getArchitectures(false);
+        equals(ic.ConvertToSourceList("/media/cdrom/", CD + A), A);
+        equals(ic.ConvertToSourceList("/media/cdrom/", CD + B), List);
+        equals(ic.ConvertToSourceList("/media/cdrom/", CD + C), C);
+        equals(ic.ConvertToSourceList("/media/cdrom/", CD + S), List);
+
+        _config->Clear("APT");
+        _config->Set("APT::Architecture", "kfreebsd-mips");
+        _config->Set("APT::Architectures::", "kfreebsd-mips");
+        APT::Configuration::getArchitectures(false);
+        equals(ic.ConvertToSourceList("/media/cdrom/", CD + A), A);
+        equals(ic.ConvertToSourceList("/media/cdrom/", CD + B), B);
+        equals(ic.ConvertToSourceList("/media/cdrom/", CD + C), List);
+        equals(ic.ConvertToSourceList("/media/cdrom/", CD + S), List);
+
+        _config->Clear("APT");
+        _config->Set("APT::Architecture", "armel");
+        _config->Set("APT::Architectures::", "armel");
+        APT::Configuration::getArchitectures(false);
+        equals(ic.ConvertToSourceList("/media/cdrom/", CD + A), List);
+        equals(ic.ConvertToSourceList("/media/cdrom/", CD + B), B);
+        equals(ic.ConvertToSourceList("/media/cdrom/", CD + C), C);
+        equals(ic.ConvertToSourceList("/media/cdrom/", CD + S), List);
+
+        _config->Clear("APT");
+        _config->Set("APT::Architecture", "armel");
+        _config->Set("APT::Architectures::", "armel");
+        _config->Set("APT::Architectures::", "mips");
+        APT::Configuration::getArchitectures(false);
+        equals(ic.ConvertToSourceList("/media/cdrom/", CD + A), List);
+        equals(ic.ConvertToSourceList("/media/cdrom/", CD + B), List);
+        equals(ic.ConvertToSourceList("/media/cdrom/", CD + C), C);
+        equals(ic.ConvertToSourceList("/media/cdrom/", CD + S), List);
+      }
+   }
+
+   return 0;
+}
index b2e6db2..d4d7f17 100644 (file)
@@ -86,3 +86,9 @@ PROGRAM = CdromFindPackages${BASENAME}
 SLIBS = -lapt-pkg
 SOURCE = cdromfindpackages_test.cc
 include $(PROGRAM_H)
+
+# text IndexCopy::ConvertToSourceList
+PROGRAM = IndexCopyToSourceList${BASENAME}
+SLIBS = -lapt-pkg
+SOURCE = indexcopytosourcelist_test.cc
+include $(PROGRAM_H)