]> git.saurik.com Git - apt.git/blobdiff - cmdline/apt-get.cc
fix crash when P.Arch() was used but the cache got remapped
[apt.git] / cmdline / apt-get.cc
index b3ce54bb7bdf9ca54cbdf4e5e7bdc110e1b63bf6..a81e829e896a14cc234c66e0e2edc32f3b6fa69b 100644 (file)
@@ -135,6 +135,11 @@ bool YnPrompt(bool Default=true)
       c1out << _("Y") << endl;
       return true;
    }
+   else if (_config->FindB("APT::Get::Assume-No",false) == true)
+   {
+      c1out << _("N") << endl;
+      return false;
+   }
 
    char response[1024] = "";
    cin.getline(response, sizeof(response));
@@ -1894,8 +1899,7 @@ bool DoInstall(CommandLine &CmdL)
       {
         // Call the scored problem resolver
         Fix->InstallProtect();
-        if (Fix->Resolve(true) == false)
-           _error->Discard();
+        Fix->Resolve(true);
         delete Fix;
       }
 
@@ -1921,8 +1925,11 @@ bool DoInstall(CommandLine &CmdL)
         c1out << _("The following information may help to resolve the situation:") << endl;
         c1out << endl;
         ShowBroken(c1out,Cache,false);
-        return _error->Error(_("Broken packages"));
-      }   
+        if (_error->PendingError() == true)
+           return false;
+        else
+           return _error->Error(_("Broken packages"));
+      }
    }
    if (!DoAutomaticRemove(Cache)) 
       return false;
@@ -2281,7 +2288,7 @@ bool DoDownload(CommandLine &CmdL)
 
    pkgAcquire Fetcher;
    AcqTextStatus Stat(ScreenWidth, _config->FindI("quiet",0));
-   if (_config->FindB("APT::Get::Print-URIs") == true)
+   if (_config->FindB("APT::Get::Print-URIs") == false)
       Fetcher.Setup(&Stat);
 
    pkgRecords Recs(Cache);
@@ -2305,6 +2312,8 @@ bool DoDownload(CommandLine &CmdL)
       strprintf(descr, _("Downloading %s %s"), Pkg.Name(), Ver.VerStr());
       // get the most appropriate hash
       HashString hash;
+      if (rec.SHA512Hash() != "")
+         hash = HashString("sha512", rec.SHA512Hash());
       if (rec.SHA256Hash() != "")
          hash = HashString("sha256", rec.SHA256Hash());
       else if (rec.SHA1Hash() != "")
@@ -2620,12 +2629,17 @@ bool DoSource(CommandLine &CmdL)
         // Try to compile it with dpkg-buildpackage
         if (_config->FindB("APT::Get::Compile",false) == true)
         {
+           string buildopts = _config->Find("APT::Get::Host-Architecture");
+           if (buildopts.empty() == false)
+              buildopts = "-a " + buildopts + " ";
+           buildopts.append(_config->Find("DPkg::Build-Options","-b -uc"));
+
            // Call dpkg-buildpackage
            char S[500];
            snprintf(S,sizeof(S),"cd %s && %s %s",
                     Dir.c_str(),
                     _config->Find("Dir::Bin::dpkg-buildpackage","dpkg-buildpackage").c_str(),
-                    _config->Find("DPkg::Build-Options","-b -uc").c_str());
+                    buildopts.c_str());
            
            if (system(S) != 0)
            {
@@ -2687,8 +2701,19 @@ bool DoBuildDep(CommandLine &CmdL)
    if (Fetcher.Setup(&Stat) == false)
       return false;
 
+   bool StripMultiArch;
+   string hostArch = _config->Find("APT::Get::Host-Architecture");
+   if (hostArch.empty() == false)
+   {
+      std::vector<std::string> archs = APT::Configuration::getArchitectures();
+      if (std::find(archs.begin(), archs.end(), hostArch) == archs.end())
+        return _error->Error(_("No architecture information available for %s. See apt.conf(5) APT::Architectures for setup"), hostArch.c_str());
+      StripMultiArch = false;
+   }
+   else
+      StripMultiArch = true;
+
    unsigned J = 0;
-   bool const StripMultiArch = APT::Configuration::getArchitectures().size() <= 1;
    for (const char **I = CmdL.FileList + 1; *I != 0; I++, J++)
    {
       string Src;
@@ -2722,7 +2747,7 @@ bool DoBuildDep(CommandLine &CmdL)
         ioprintf(c1out,_("%s has no build depends.\n"),Src.c_str());
         continue;
       }
-      
+
       // Install the requested packages
       vector <pkgSrcRecords::Parser::BuildDepRec>::iterator D;
       pkgProblemResolver Fix(Cache);
@@ -2773,7 +2798,95 @@ bool DoBuildDep(CommandLine &CmdL)
             if (_config->FindB("Debug::BuildDeps",false) == true)
                  cout << "Looking for " << (*D).Package << "...\n";
 
-           pkgCache::PkgIterator Pkg = Cache->FindPkg((*D).Package);
+           pkgCache::PkgIterator Pkg;
+
+           // Cross-Building?
+           if (StripMultiArch == false)
+           {
+              size_t const colon = D->Package.find(":");
+              if (colon != string::npos &&
+                  (strcmp(D->Package.c_str() + colon, ":any") == 0 || strcmp(D->Package.c_str() + colon, ":native") == 0))
+                 Pkg = Cache->FindPkg(D->Package.substr(0,colon));
+              else
+                 Pkg = Cache->FindPkg(D->Package);
+
+              // We need to decide if host or build arch, so find a version we can look at
+              pkgCache::VerIterator Ver;
+
+              // a bad version either is invalid or doesn't satify dependency
+              #define BADVER(Ver) Ver.end() == true || \
+                                  (Ver.end() == false && D->Version.empty() == false && \
+                                   Cache->VS().CheckDep(Ver.VerStr(),D->Op,D->Version.c_str()) == false)
+
+              if (Pkg.end() == false)
+              {
+                 Ver = (*Cache)[Pkg].InstVerIter(*Cache);
+                 if (BADVER(Ver))
+                    Ver = (*Cache)[Pkg].CandidateVerIter(*Cache);
+              }
+              if (BADVER(Ver))
+              {
+                 pkgCache::PkgIterator HostPkg = Cache->FindPkg(D->Package, hostArch);
+                 if (HostPkg.end() == false)
+                 {
+                    Ver = (*Cache)[HostPkg].InstVerIter(*Cache);
+                    if (BADVER(Ver))
+                       Ver = (*Cache)[HostPkg].CandidateVerIter(*Cache);
+                 }
+              }
+              if ((BADVER(Ver)) == false)
+              {
+                 string forbidden;
+                 if (Ver->MultiArch == pkgCache::Version::None || Ver->MultiArch == pkgCache::Version::All);
+                 else if (Ver->MultiArch == pkgCache::Version::Same)
+                 {
+                    if (colon != string::npos)
+                       Pkg = Ver.ParentPkg().Group().FindPkg(hostArch);
+                    else if (strcmp(D->Package.c_str() + colon, ":any") == 0)
+                       forbidden = "Multi-Arch: same";
+                    // :native gets the buildArch
+                 }
+                 else if (Ver->MultiArch == pkgCache::Version::Foreign || Ver->MultiArch == pkgCache::Version::AllForeign)
+                 {
+                    if (colon != string::npos)
+                       forbidden = "Multi-Arch: foreign";
+                 }
+                 else if (Ver->MultiArch == pkgCache::Version::Allowed || Ver->MultiArch == pkgCache::Version::AllAllowed)
+                 {
+                    if (colon == string::npos)
+                       Pkg = Ver.ParentPkg().Group().FindPkg(hostArch);
+                    else if (strcmp(D->Package.c_str() + colon, ":any") == 0)
+                    {
+                       // prefer any installed over preferred non-installed architectures
+                       pkgCache::GrpIterator Grp = Ver.ParentPkg().Group();
+                       // we don't check for version here as we are better of with upgrading than remove and install
+                       for (Pkg = Grp.PackageList(); Pkg.end() == false; Pkg = Grp.NextPkg(Pkg))
+                          if (Pkg.CurrentVer().end() == false)
+                             break;
+                       if (Pkg.end() == true)
+                          Pkg = Grp.FindPreferredPkg(true);
+                    }
+                    // native gets buildArch
+                 }
+                 if (forbidden.empty() == false)
+                 {
+                    if (_config->FindB("Debug::BuildDeps",false) == true)
+                       cout << " :any is not allowed from M-A: same package " << (*D).Package << endl;
+                    if (hasAlternatives)
+                       continue;
+                    return _error->Error(_("%s dependency for %s can't be satisfied "
+                                           "because %s is not allowed on '%s' packages"),
+                                         Last->BuildDepType(D->Type), Src.c_str(),
+                                         D->Package.c_str(), "Multi-Arch: same");
+                 }
+              }
+              else if (_config->FindB("Debug::BuildDeps",false) == true)
+                 cout << " No multiarch info as we have no satisfying installed nor candidate for " << D->Package << " on build or host arch" << endl;
+              #undef BADVER
+           }
+           else
+              Pkg = Cache->FindPkg(D->Package);
+
            if (Pkg.end() == true)
             {
                if (_config->FindB("Debug::BuildDeps",false) == true)
@@ -3235,12 +3348,14 @@ int main(int argc,const char *argv[])                                   /*{{{*/
       {'s',"dry-run","APT::Get::Simulate",0},
       {'s',"no-act","APT::Get::Simulate",0},
       {'y',"yes","APT::Get::Assume-Yes",0},
-      {'y',"assume-yes","APT::Get::Assume-Yes",0},      
+      {'y',"assume-yes","APT::Get::Assume-Yes",0},
+      {0,"assume-no","APT::Get::Assume-No",0},
       {'f',"fix-broken","APT::Get::Fix-Broken",0},
       {'u',"show-upgraded","APT::Get::Show-Upgraded",0},
       {'m',"ignore-missing","APT::Get::Fix-Missing",0},
       {'t',"target-release","APT::Default-Release",CommandLine::HasArg},
       {'t',"default-release","APT::Default-Release",CommandLine::HasArg},
+      {'a',"host-architecture","APT::Get::Host-Architecture",CommandLine::HasArg},
       {0,"download","APT::Get::Download",0},
       {0,"fix-missing","APT::Get::Fix-Missing",0},
       {0,"ignore-hold","APT::Ignore-Hold",0},      
@@ -3264,6 +3379,7 @@ int main(int argc,const char *argv[])                                     /*{{{*/
       {0,"install-recommends","APT::Install-Recommends",CommandLine::Boolean},
       {0,"install-suggests","APT::Install-Suggests",CommandLine::Boolean},
       {0,"fix-policy","APT::Get::Fix-Policy-Broken",0},
+      {0,"solver","APT::Solver",CommandLine::HasArg},
       {'c',"config-file",0,CommandLine::ConfigFile},
       {'o',"option",0,CommandLine::ArbItem},
       {0,0,0,0}};