]> git.saurik.com Git - apt.git/blobdiff - apt-pkg/aptconfiguration.cc
* apt-pkg/packagemanager.cc:
[apt.git] / apt-pkg / aptconfiguration.cc
index ca602d4bfd1df5fa17938e32c0aee7b1eb28332f..b5ad74831d5c41918e8314e43b765a878a8c5635 100644 (file)
@@ -8,6 +8,8 @@
    ##################################################################### */
                                                                        /*}}}*/
 // Include Files                                                       /*{{{*/
+#include <config.h>
+
 #include <apt-pkg/aptconfiguration.h>
 #include <apt-pkg/configuration.h>
 #include <apt-pkg/error.h>
@@ -18,6 +20,7 @@
 #include <sys/types.h>
 #include <dirent.h>
 #include <stdio.h>
+#include <fcntl.h>
 
 #include <algorithm>
 #include <string>
@@ -53,14 +56,14 @@ const Configuration::getCompressionTypes(bool const &Cached) {
        // load the order setting into our vector
        std::vector<std::string> const order = _config->FindVector("Acquire::CompressionTypes::Order");
        for (std::vector<std::string>::const_iterator o = order.begin();
-            o != order.end(); o++) {
+            o != order.end(); ++o) {
                if ((*o).empty() == true)
                        continue;
                // ignore types we have no method ready to use
-               if (_config->Exists(string("Acquire::CompressionTypes::").append(*o)) == false)
+               if (_config->Exists(std::string("Acquire::CompressionTypes::").append(*o)) == false)
                        continue;
                // ignore types we have no app ready to use
-               string const appsetting = string("Dir::Bin::").append(*o);
+               std::string const appsetting = std::string("Dir::Bin::").append(*o);
                if (_config->Exists(appsetting) == true) {
                        std::string const app = _config->FindFile(appsetting.c_str(), "");
                        if (app.empty() == false && FileExists(app) == false)
@@ -81,7 +84,7 @@ const Configuration::getCompressionTypes(bool const &Cached) {
                if (std::find(types.begin(),types.end(),Types->Tag) != types.end())
                        continue;
                // ignore types we have no app ready to use
-               string const appsetting = string("Dir::Bin::").append(Types->Value);
+               std::string const appsetting = std::string("Dir::Bin::").append(Types->Value);
                if (appsetting.empty() == false && _config->Exists(appsetting) == true) {
                        std::string const app = _config->FindFile(appsetting.c_str(), "");
                        if (app.empty() == false && FileExists(app) == false)
@@ -93,7 +96,7 @@ const Configuration::getCompressionTypes(bool const &Cached) {
        // add the special "uncompressed" type
        if (std::find(types.begin(), types.end(), "uncompressed") == types.end())
        {
-               string const uncompr = _config->FindFile("Dir::Bin::uncompressed", "");
+               std::string const uncompr = _config->FindFile("Dir::Bin::uncompressed", "");
                if (uncompr.empty() == true || FileExists(uncompr) == true)
                        types.push_back("uncompressed");
        }
@@ -140,7 +143,7 @@ std::vector<std::string> const Configuration::getLanguages(bool const &All,
                for (struct dirent *Ent = readdir(D); Ent != 0; Ent = readdir(D)) {
                        string const name = Ent->d_name;
                        size_t const foundDash = name.rfind("-");
-                       size_t const foundUnderscore = name.rfind("_");
+                       size_t const foundUnderscore = name.rfind("_", foundDash);
                        if (foundDash == string::npos || foundUnderscore == string::npos ||
                            foundDash <= foundUnderscore ||
                            name.substr(foundUnderscore+1, foundDash-(foundUnderscore+1)) != "Translation")
@@ -151,7 +154,7 @@ std::vector<std::string> const Configuration::getLanguages(bool const &All,
                        // Skip unusual files, like backups or that alike
                        string::const_iterator s = c.begin();
                        for (;s != c.end(); ++s) {
-                               if (isalpha(*s) == 0)
+                               if (isalpha(*s) == 0 && *s != '_')
                                        break;
                        }
                        if (s != c.end())
@@ -224,7 +227,7 @@ std::vector<std::string> const Configuration::getLanguages(bool const &All,
                environment.push_back("en");
        }
 
-       // Support settings like Acquire::Translation=none on the command line to
+       // Support settings like Acquire::Languages=none on the command line to
        // override the configuration settings vector of languages.
        string const forceLang = _config->Find("Acquire::Languages","");
        if (forceLang.empty() == false) {
@@ -232,6 +235,8 @@ std::vector<std::string> const Configuration::getLanguages(bool const &All,
                        codes = environment;
                } else if (forceLang != "none")
                        codes.push_back(forceLang);
+               else //if (forceLang == "none")
+                       builtin.clear();
                allCodes = codes;
                for (std::vector<string>::const_iterator b = builtin.begin();
                     b != builtin.end(); ++b)
@@ -274,7 +279,7 @@ std::vector<std::string> const Configuration::getLanguages(bool const &All,
        // then needed and ensure the codes are not listed twice.
        bool noneSeen = false;
        for (std::vector<string>::const_iterator l = lang.begin();
-            l != lang.end(); l++) {
+            l != lang.end(); ++l) {
                if (*l == "environment") {
                        for (std::vector<string>::const_iterator e = environment.begin();
                             e != environment.end(); ++e) {
@@ -324,16 +329,63 @@ std::vector<std::string> const Configuration::getArchitectures(bool const &Cache
        // 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");
+
+               // Generate the base argument list for dpkg
+               std::vector<const char *> Args;
+               string Tmp = _config->Find("Dir::Bin::dpkg","dpkg");
+               {
+                       string const dpkgChrootDir = _config->FindDir("DPkg::Chroot-Directory", "/");
+                       size_t dpkgChrootLen = dpkgChrootDir.length();
+                       if (dpkgChrootDir != "/" && Tmp.find(dpkgChrootDir) == 0) {
+                               if (dpkgChrootDir[dpkgChrootLen - 1] == '/')
+                                       --dpkgChrootLen;
+                               Tmp = Tmp.substr(dpkgChrootLen);
+                       }
+               }
+               Args.push_back(Tmp.c_str());
+
+               // Stick in any custom dpkg options
+               ::Configuration::Item const *Opts = _config->Tree("DPkg::Options");
+               if (Opts != 0) {
+                       Opts = Opts->Child;
+                       for (; Opts != 0; Opts = Opts->Next)
+                       {
+                               if (Opts->Value.empty() == true)
+                                       continue;
+                               Args.push_back(Opts->Value.c_str());
+                       }
+               }
+
+               Args.push_back("--print-foreign-architectures");
+               Args.push_back(NULL);
+
+               int external[2] = {-1, -1};
+               if (pipe(external) != 0)
+               {
+                       _error->WarningE("getArchitecture", "Can't create IPC pipe for dpkg --print-foreign-architectures");
+                       return archs;
+               }
+
+               pid_t dpkgMultiArch = ExecFork();
+               if (dpkgMultiArch == 0) {
+                       close(external[0]);
+                       std::string const chrootDir = _config->FindDir("DPkg::Chroot-Directory");
+                       if (chrootDir != "/" && chroot(chrootDir.c_str()) != 0)
+                               _error->WarningE("getArchitecture", "Couldn't chroot into %s for dpkg --print-foreign-architectures", chrootDir.c_str());
+                       int const nullfd = open("/dev/null", O_RDONLY);
+                       dup2(nullfd, STDIN_FILENO);
+                       dup2(external[1], STDOUT_FILENO);
+                       dup2(nullfd, STDERR_FILENO);
+                       execv(Args[0], (char**) &Args[0]);
+                       _error->WarningE("getArchitecture", "Can't detect foreign architectures supported by dpkg!");
+                       _exit(100);
+               }
+               close(external[1]);
+
+               FILE *dpkg = fdopen(external[0], "r");
                char buf[1024];
                if(dpkg != NULL) {
-                       if (fgets(buf, sizeof(buf), dpkg) != NULL) {
+                       while (fgets(buf, sizeof(buf), dpkg) != NULL) {
                                char* arch = strtok(buf, " ");
                                while (arch != NULL) {
                                        for (; isspace(*arch) != 0; ++arch);
@@ -345,14 +397,15 @@ std::vector<std::string> const Configuration::getArchitectures(bool const &Cache
                                        arch = strtok(NULL, " ");
                                }
                        }
-                       pclose(dpkg);
+                       fclose(dpkg);
                }
+               ExecWait(dpkgMultiArch, "dpkg --print-foreign-architectures", true);
                return archs;
        }
 
        if (archs.empty() == true ||
            std::find(archs.begin(), archs.end(), arch) == archs.end())
-               archs.push_back(arch);
+               archs.insert(archs.begin(), arch);
 
        // erase duplicates and empty strings
        for (std::vector<string>::reverse_iterator a = archs.rbegin();
@@ -439,7 +492,7 @@ Configuration::Compressor::Compressor(char const *name, char const *extension,
                                      char const *binary,
                                      char const *compressArg, char const *uncompressArg,
                                      unsigned short const cost) {
-       std::string const config = string("APT:Compressor::").append(name).append("::");
+       std::string const config = std::string("APT:Compressor::").append(name).append("::");
        Name = _config->Find(std::string(config).append("Name"), name);
        Extension = _config->Find(std::string(config).append("Extension"), extension);
        Binary = _config->Find(std::string(config).append("Binary"), binary);