]> git.saurik.com Git - apt.git/commitdiff
* apt-pkg/aptconfiguration.cc:
authorDavid Kalnischkies <kalnischkies@gmail.com>
Sat, 26 Mar 2011 00:31:32 +0000 (01:31 +0100)
committerDavid Kalnischkies <kalnischkies@gmail.com>
Sat, 26 Mar 2011 00:31:32 +0000 (01:31 +0100)
  - use dpkg --print-foreign-architectures to get multiarch configuration
    if non is specified with APT::Architectures (Closes: #612958)

apt-pkg/aptconfiguration.cc
debian/changelog
test/integration/test-bug-612958-use-dpkg-multiarch-config [new file with mode: 0755]

index b23e12acb42e78175f4e78bc3d920cd5d5640652..14ee09e0d2ea7c5c34e6d5b6af02f5465a011edc 100644 (file)
@@ -17,6 +17,7 @@
 
 #include <sys/types.h>
 #include <dirent.h>
+#include <stdio.h>
 
 #include <algorithm>
 #include <string>
@@ -314,11 +315,41 @@ std::vector<std::string> const Configuration::getArchitectures(bool const &Cache
        if (likely(Cached == true) && archs.empty() == false)
                return archs;
 
-       archs = _config->FindVector("APT::Architectures");
        string const arch = _config->Find("APT::Architecture");
+       archs = _config->FindVector("APT::Architectures");
+
        if (unlikely(arch.empty() == true))
                return archs;
 
+       // FIXME: It is a bit unclean to have debian specific code hereā€¦
+       if (archs.empty() == true) {
+               archs.push_back(arch);
+               string dpkgcall = _config->Find("Dir::Bin::dpkg", "dpkg");
+               std::vector<string> const dpkgoptions = _config->FindVector("DPkg::options");
+               for (std::vector<string>::const_iterator o = dpkgoptions.begin();
+                    o != dpkgoptions.end(); ++o)
+                       dpkgcall.append(" ").append(*o);
+               dpkgcall.append(" --print-foreign-architectures 2> /dev/null");
+               FILE *dpkg = popen(dpkgcall.c_str(), "r");
+               char buf[1024];
+               if(dpkg != NULL) {
+                       if (fgets(buf, sizeof(buf), dpkg) != NULL) {
+                               char* arch = strtok(buf, " ");
+                               while (arch != NULL) {
+                                       for (; isspace(*arch) != 0; ++arch);
+                                       if (arch != '\0') {
+                                               char const* archend = arch;
+                                               for (; isspace(*archend) == 0 && *archend != '\0'; ++archend);
+                                               archs.push_back(string(arch, (archend - arch)));
+                                       }
+                                       arch = strtok(NULL, " ");
+                               }
+                       }
+                       pclose(dpkg);
+               }
+               return archs;
+       }
+
        if (archs.empty() == true ||
            std::find(archs.begin(), archs.end(), arch) == archs.end())
                archs.push_back(arch);
index b0bec1ba2e5c03d866f9e03604f90d03dd8a9a78..1c2cd9da77f85d8854e4bfbf3065db3887987296 100644 (file)
@@ -21,8 +21,11 @@ apt (0.8.13.1) UNRELEASED; urgency=low
   * apt-pkg/cacheiterator.h:
     - return "all" instead of native architecture without breaking the abi
       (too much) by extending enum instead of using bitflags (LP: #733741)
+  * apt-pkg/aptconfiguration.cc:
+    - use dpkg --print-foreign-architectures to get multiarch configuration
+      if non is specified with APT::Architectures (Closes: #612958)
 
- -- David Kalnischkies <kalnischkies@gmail.com>  Fri, 25 Mar 2011 22:07:59 +0100
+ -- David Kalnischkies <kalnischkies@gmail.com>  Sat, 26 Mar 2011 01:28:38 +0100
 
 apt (0.8.13) unstable; urgency=low
 
diff --git a/test/integration/test-bug-612958-use-dpkg-multiarch-config b/test/integration/test-bug-612958-use-dpkg-multiarch-config
new file mode 100755 (executable)
index 0000000..4f31c39
--- /dev/null
@@ -0,0 +1,59 @@
+#!/bin/sh
+set -e
+
+TESTDIR=$(readlink -f $(dirname $0))
+. $TESTDIR/framework
+setupenvironment
+configarchitecture 'i386'
+setupaptarchive
+
+insertinstalledpackage 'libapt' 'i386' '1.0'
+insertinstalledpackage 'libapt' 'amd64' '1.0'
+insertinstalledpackage 'libapt' 'armel' '1.0'
+
+testpass() {
+       rm rootdir/var/cache/apt/*.bin
+       msgtest 'Test architecture handling' "$1 with $2"
+       aptcache show libapt:$2 2> /dev/null > /dev/null && msgpass || msgfail
+}
+
+testfail() {
+       rm rootdir/var/cache/apt/*.bin
+       msgtest 'Test architecture handling' "$1 with $2"
+       aptcache show libapt:$2 2> /dev/null > /dev/null && msgfail || msgpass
+}
+
+testpass 'no config' 'i386'
+testfail 'no config' 'amd64'
+testfail 'no config' 'armel'
+
+CONFFILE=rootdir/etc/apt/apt.conf.d/99multiarch
+echo '#clear APT::Architectures;' >> $CONFFILE
+echo 'APT::Architectures:: "i386";' >> $CONFFILE
+echo 'APT::Architectures:: "amd64";' >> $CONFFILE
+
+testpass 'apt config' 'i386'
+testpass 'apt config' 'amd64'
+testfail 'apt config' 'armel'
+
+echo 'APT::Architectures:: "armel";' >> $CONFFILE
+
+testpass 'apt config' 'armel'
+
+rm $CONFFILE
+
+echo '#clear APT::Architectures;' >> $CONFFILE
+echo 'Dir::Bin::dpkg "./dpkg-printer";' >> $CONFFILE
+
+echo '#! /bin/sh
+echo "amd64"' > ./dpkg-printer
+chmod +x ./dpkg-printer
+
+testpass 'dpkg config' 'i386'
+testpass 'dpkg config' 'amd64'
+testfail 'dpkg config' 'armel'
+
+echo '#! /bin/sh
+echo "amd64 armel"' > ./dpkg-printer
+
+testpass 'dpkg config' 'armel'