~ubuntu-branches/ubuntu/natty/apt/natty

« back to all changes in this revision

Viewing changes to apt-pkg/aptconfiguration.cc

  • Committer: Bazaar Package Importer
  • Author(s): Michael Vogt
  • Date: 2011-04-05 13:19:56 UTC
  • Revision ID: james.westby@ubuntu.com-20110405131956-u6sgfjr30zvy2fr3
Tags: 0.8.13.2ubuntu1
* merge fixes from debian-sid, most notable the handling of
  arch=all architectures in python-apt (LP: #733741)
* apt-pkg/aptconfiguration.cc:
  - fix comparing for a empty string

Show diffs side-by-side

added added

removed removed

Lines of Context:
17
17
 
18
18
#include <sys/types.h>
19
19
#include <dirent.h>
 
20
#include <stdio.h>
20
21
 
21
22
#include <algorithm>
22
23
#include <string>
314
315
        if (likely(Cached == true) && archs.empty() == false)
315
316
                return archs;
316
317
 
 
318
        string const arch = _config->Find("APT::Architecture");
317
319
        archs = _config->FindVector("APT::Architectures");
318
 
        string const arch = _config->Find("APT::Architecture");
 
320
 
319
321
        if (unlikely(arch.empty() == true))
320
322
                return archs;
321
323
 
 
324
        // FIXME: It is a bit unclean to have debian specific code here…
 
325
        if (archs.empty() == true) {
 
326
                archs.push_back(arch);
 
327
                string dpkgcall = _config->Find("Dir::Bin::dpkg", "dpkg");
 
328
                std::vector<string> const dpkgoptions = _config->FindVector("DPkg::options");
 
329
                for (std::vector<string>::const_iterator o = dpkgoptions.begin();
 
330
                     o != dpkgoptions.end(); ++o)
 
331
                        dpkgcall.append(" ").append(*o);
 
332
                dpkgcall.append(" --print-foreign-architectures 2> /dev/null");
 
333
                FILE *dpkg = popen(dpkgcall.c_str(), "r");
 
334
                char buf[1024];
 
335
                if(dpkg != NULL) {
 
336
                        if (fgets(buf, sizeof(buf), dpkg) != NULL) {
 
337
                                char* arch = strtok(buf, " ");
 
338
                                while (arch != NULL) {
 
339
                                        for (; isspace(*arch) != 0; ++arch);
 
340
                                        if (arch[0] != '\0') {
 
341
                                                char const* archend = arch;
 
342
                                                for (; isspace(*archend) == 0 && *archend != '\0'; ++archend);
 
343
                                                archs.push_back(string(arch, (archend - arch)));
 
344
                                        }
 
345
                                        arch = strtok(NULL, " ");
 
346
                                }
 
347
                        }
 
348
                        pclose(dpkg);
 
349
                }
 
350
                return archs;
 
351
        }
 
352
 
322
353
        if (archs.empty() == true ||
323
354
            std::find(archs.begin(), archs.end(), arch) == archs.end())
324
355
                archs.push_back(arch);