]> git.saurik.com Git - apt.git/blobdiff - cmdline/apt-get.cc
avoid using global PendingError to avoid failing too often too soon
[apt.git] / cmdline / apt-get.cc
index 632c7cfeab881ad8ea9e53fd171c3a0a38bab372..ebc8c94c27dbc1f4378327ce86eea2262e300b1a 100644 (file)
@@ -39,7 +39,6 @@
 #include <apt-pkg/error.h>
 #include <apt-pkg/fileutl.h>
 #include <apt-pkg/indexfile.h>
-#include <apt-pkg/indexrecords.h>
 #include <apt-pkg/init.h>
 #include <apt-pkg/md5.h>
 #include <apt-pkg/metaindex.h>
@@ -56,6 +55,7 @@
 #include <apt-pkg/pkgcache.h>
 #include <apt-pkg/cacheiterators.h>
 #include <apt-pkg/upgrade.h>
+#include <apt-pkg/sptr.h>
 
 #include <apt-private/acqprogress.h>
 #include <apt-private/private-cacheset.h>
@@ -137,11 +137,9 @@ static bool TryToInstallBuildDep(pkgCache::PkgIterator Pkg,pkgCacheFile &Cache,
    return true;
 }
                                                                        /*}}}*/
-// GetReleaseForSourceRecord - Return Suite for the given srcrecord    /*{{{*/
-// ---------------------------------------------------------------------
-/* */
-static std::string GetReleaseForSourceRecord(pkgSourceList *SrcList,
-                                      pkgSrcRecords::Parser *Parse)
+// GetReleaseFileForSourceRecord - Return Suite for the given srcrecord        /*{{{*/
+static pkgCache::RlsFileIterator GetReleaseFileForSourceRecord(CacheFile &CacheFile,
+      pkgSourceList *SrcList, pkgSrcRecords::Parser *Parse)
 {
    // try to find release
    const pkgIndexFile& CurrentIndexFile = Parse->Index();
@@ -154,28 +152,16 @@ static std::string GetReleaseForSourceRecord(pkgSourceList *SrcList,
            IF != Indexes->end(); ++IF)
       {
          if (&CurrentIndexFile == (*IF))
-         {
-            std::string const path = (*S)->LocalFileName();
-            if (path != "")
-            {
-               indexRecords records;
-               records.Load(path);
-               return records.GetSuite();
-            }
-         }
+           return (*S)->FindInCache(CacheFile, false);
       }
    }
-   return "";
+   return pkgCache::RlsFileIterator(CacheFile);
 }
                                                                        /*}}}*/
 // FindSrc - Find a source record                                      /*{{{*/
 // ---------------------------------------------------------------------
 /* */
-#if APT_PKG_ABI >= 413
 static pkgSrcRecords::Parser *FindSrc(const char *Name,
-#else
-static pkgSrcRecords::Parser *FindSrc(const char *Name,pkgRecords &Recs,
-#endif
                               pkgSrcRecords &SrcRecs,string &Src,
                               CacheFile &CacheFile)
 {
@@ -285,19 +271,8 @@ static pkgSrcRecords::Parser *FindSrc(const char *Name,pkgRecords &Recs,
               {
                  // the Version we have is possibly fuzzy or includes binUploads,
                  // so we use the Version of the SourcePkg (empty if same as package)
-#if APT_PKG_ABI >= 413
                  Src = Ver.SourcePkgName();
                  VerTag = Ver.SourceVerStr();
-#else
-                 pkgRecords::Parser &Parse = Recs.Lookup(VF);
-                 Src = Parse.SourcePkg();
-                 // no SourcePkg name, so it is the "binary" name
-                 if (Src.empty() == true)
-                    Src = TmpSrc;
-                 VerTag = Parse.SourceVer();
-                 if (VerTag.empty() == true)
-                    VerTag = Ver.VerStr();
-#endif
                  break;
               }
            }
@@ -328,17 +303,10 @@ static pkgSrcRecords::Parser *FindSrc(const char *Name,pkgRecords &Recs,
         pkgCache::VerIterator Ver = Cache->GetCandidateVer(Pkg);
         if (Ver.end() == false) 
         {
-#if APT_PKG_ABI >= 413
            if (strcmp(Ver.SourcePkgName(),Ver.ParentPkg().Name()) != 0)
               Src = Ver.SourcePkgName();
            if (VerTag.empty() == true && strcmp(Ver.SourceVerStr(),Ver.VerStr()) != 0)
               VerTag = Ver.SourceVerStr();
-#else
-           pkgRecords::Parser &Parse = Recs.Lookup(Ver.FileList());
-           Src = Parse.SourcePkg();
-           if (VerTag.empty() == true)
-              VerTag = Parse.SourceVer();
-#endif
         }
       }
    }
@@ -379,13 +347,16 @@ static pkgSrcRecords::Parser *FindSrc(const char *Name,pkgRecords &Recs,
          // See if we need to look for a specific release tag
          if (RelTag != "" && UserRequestedVerTag == "")
          {
-            const string Rel = GetReleaseForSourceRecord(SrcList, Parse);
-
-            if (Rel == RelTag)
+           pkgCache::RlsFileIterator const Rls = GetReleaseFileForSourceRecord(CacheFile, SrcList, Parse);
+            if (Rls.end() == false)
             {
-               Last = Parse;
-               Offset = Parse->Offset();
-               Version = Ver;
+              if ((Rls->Archive != 0 && RelTag == Rls.Archive()) ||
+                    (Rls->Codename != 0 && RelTag == Rls.Codename()))
+              {
+                 Last = Parse;
+                 Offset = Parse->Offset();
+                 Version = Ver;
+              }
             }
          }
 
@@ -579,7 +550,7 @@ static bool DoClean(CommandLine &)
 class LogCleaner : public pkgArchiveCleaner
 {
    protected:
-   virtual void Erase(const char *File,string Pkg,string Ver,struct stat &St) 
+   virtual void Erase(const char *File,string Pkg,string Ver,struct stat &St) APT_OVERRIDE 
    {
       c1out << "Del " << Pkg << " " << Ver << " [" << SizeToStr(St.st_size) << "B]" << endl;
       
@@ -658,9 +629,6 @@ static bool DoDownload(CommandLine &CmdL)
       return true;
    }
 
-   // Disable drop-privs if "_apt" can not write to the target dir
-   CheckDropPrivsMustBeDisabled(Fetcher);
-
    if (_error->PendingError() == true || CheckAuth(Fetcher, false) == false)
       return false;
 
@@ -722,9 +690,6 @@ static bool DoSource(CommandLine &CmdL)
    pkgSourceList *List = Cache.GetSourceList();
    
    // Create the text record parsers
-#if APT_PKG_ABI < 413
-   pkgRecords Recs(Cache);
-#endif
    pkgSrcRecords SrcRecs(*List);
    if (_error->PendingError() == true)
       return false;
@@ -733,7 +698,7 @@ static bool DoSource(CommandLine &CmdL)
    AcqTextStatus Stat(std::cout, ScreenWidth,_config->FindI("quiet",0));
    pkgAcquire Fetcher(&Stat);
 
-   SPtrArray<DscFile> Dsc = new DscFile[CmdL.FileSize()];
+   std::unique_ptr<DscFile[]> Dsc(new DscFile[CmdL.FileSize()]);
    
    // insert all downloaded uris into this set to avoid downloading them
    // twice
@@ -748,22 +713,18 @@ static bool DoSource(CommandLine &CmdL)
 
    // Load the requestd sources into the fetcher
    unsigned J = 0;
-   std::string UntrustedList;
+   std::vector<std::string> UntrustedList;
    for (const char **I = CmdL.FileList + 1; *I != 0; I++, J++)
    {
       string Src;
-#if APT_PKG_ABI >= 413
       pkgSrcRecords::Parser *Last = FindSrc(*I,SrcRecs,Src,Cache);
-#else
-      pkgSrcRecords::Parser *Last = FindSrc(*I,Recs,SrcRecs,Src,Cache);
-#endif
       if (Last == 0) {
         return _error->Error(_("Unable to find a source package for %s"),Src.c_str());
       }
 
       if (Last->Index().IsTrusted() == false)
-         UntrustedList += Src + " ";
-      
+         UntrustedList.push_back(Src);
+
       string srec = Last->AsStr();
       string::size_type pos = srec.find("\nVcs-");
       while (pos != string::npos)
@@ -886,11 +847,8 @@ static bool DoSource(CommandLine &CmdL)
       return true;
    }
 
-   // Disable drop-privs if "_apt" can not write to the target dir
-   CheckDropPrivsMustBeDisabled(Fetcher);
-
    // check authentication status of the source as well
-   if (UntrustedList != "" && !AuthPrompt(UntrustedList, false))
+   if (UntrustedList.empty() == false && AuthPrompt(UntrustedList, false) == false)
       return false;
 
    // Run it
@@ -1002,8 +960,10 @@ static bool DoBuildDep(CommandLine &CmdL)
    CacheFile Cache;
 
    _config->Set("APT::Install-Recommends", false);
+
+   bool WantLock = _config->FindB("APT::Get::Print-URIs", false) == false;
    
-   if (Cache.Open(true) == false)
+   if (Cache.Open(WantLock) == false)
       return false;
 
    if (CmdL.FileSize() <= 1)
@@ -1036,7 +996,7 @@ static bool DoBuildDep(CommandLine &CmdL)
    {
       string Src;
       pkgSrcRecords::Parser *Last = 0;
-      SPtr<pkgSrcRecords::Parser> LastOwner;
+      std::unique_ptr<pkgSrcRecords::Parser> LastOwner;
 
       // an unpacked debian source tree
       using APT::String::Startswith;
@@ -1045,10 +1005,10 @@ static bool DoBuildDep(CommandLine &CmdL)
       {
          ioprintf(c1out, _("Note, using directory '%s' to get the build dependencies\n"), *I);
          // FIXME: how can we make this more elegant?
-         std::string TypeName = "debian/control File Source Index";
+         std::string TypeName = "Debian control file";
          pkgIndexFile::Type *Type = pkgIndexFile::Type::GetType(TypeName.c_str());
          if(Type != NULL)
-            LastOwner = Last = Type->CreateSrcPkgParser(*I);
+            LastOwner.reset(Last = Type->CreateSrcPkgParser(*I));
       }
       // if its a local file (e.g. .dsc) use this
       else if (FileExists(*I))
@@ -1056,17 +1016,13 @@ static bool DoBuildDep(CommandLine &CmdL)
          ioprintf(c1out, _("Note, using file '%s' to get the build dependencies\n"), *I);
 
          // see if we can get a parser for this pkgIndexFile type
-         string TypeName = flExtension(*I) + " File Source Index";
+         string TypeName = "Debian " + flExtension(*I) + " file";
          pkgIndexFile::Type *Type = pkgIndexFile::Type::GetType(TypeName.c_str());
          if(Type != NULL)
-            LastOwner = Last = Type->CreateSrcPkgParser(*I);
+            LastOwner.reset(Last = Type->CreateSrcPkgParser(*I));
       } else {
          // normal case, search the cache for the source file
-#if APT_PKG_ABI >= 413
         Last = FindSrc(*I,SrcRecs,Src,Cache);
-#else
-        Last = FindSrc(*I,Recs,SrcRecs,Src,Cache);
-#endif
       }
 
       if (Last == 0)
@@ -1211,12 +1167,12 @@ static bool DoBuildDep(CommandLine &CmdL)
               for (; Ver != verlist.end(); ++Ver)
               {
                  forbidden.clear();
-                 if (Ver->MultiArch == pkgCache::Version::None || Ver->MultiArch == pkgCache::Version::All)
+                 if (Ver->MultiArch == pkgCache::Version::No || Ver->MultiArch == pkgCache::Version::All)
                  {
                     if (colon == string::npos)
                        Pkg = Ver.ParentPkg().Group().FindPkg(hostArch);
                     else if (strcmp(D->Package.c_str() + colon, ":any") == 0)
-                       forbidden = "Multi-Arch: none";
+                       forbidden = "Multi-Arch: no";
                     else if (strcmp(D->Package.c_str() + colon, ":native") == 0)
                        Pkg = Ver.ParentPkg().Group().FindPkg("native");
                  }
@@ -1441,11 +1397,6 @@ static bool DoChangelog(CommandLine &CmdL)
 
    if (printOnly == false)
    {
-      // Disable drop-privs if "_apt" can not write to the target dir
-      CheckDropPrivsMustBeDisabled(Fetcher);
-      if (_error->PendingError() == true)
-        return false;
-
       bool Failed = false;
       if (AcquireRun(Fetcher, 0, &Failed, NULL) == false || Failed == true)
         return false;
@@ -1475,7 +1426,7 @@ static bool DoChangelog(CommandLine &CmdL)
    return true;
 }
                                                                        /*}}}*/
-// DoFiles - Lists all IndexTargets                                    /*{{{*/
+// DoIndexTargets - Lists all IndexTargets                             /*{{{*/
 static std::string format_key(std::string key)
 {
    // deb822 is case-insensitive, but the human eye prefers candy
@@ -1491,7 +1442,7 @@ static std::string format_key(std::string key)
    }
    return key;
 }
-static bool DoFiles(CommandLine &CmdL)
+static bool DoIndexTargets(CommandLine &CmdL)
 {
    pkgCacheFile CacheFile;
    pkgSourceList *SrcList = CacheFile.GetSourceList();
@@ -1499,8 +1450,8 @@ static bool DoFiles(CommandLine &CmdL)
    if (SrcList == NULL)
       return false;
 
-   std::string const Format = _config->Find("APT::Get::Files::Format");
-   bool const ReleaseInfo = _config->FindB("APT::Get::Files::ReleaseInfo", true);
+   std::string const Format = _config->Find("APT::Get::IndexTargets::Format");
+   bool const ReleaseInfo = _config->FindB("APT::Get::IndexTargets::ReleaseInfo", true);
    bool Filtered = CmdL.FileSize() > 1;
    for (pkgSourceList::const_iterator S = SrcList->begin(); S != SrcList->end(); ++S)
    {
@@ -1536,11 +1487,21 @@ static bool DoFiles(CommandLine &CmdL)
               << "Description: " << T->Description << "\n"
               << "URI: " << T->URI << "\n"
               << "Filename: " << filename << "\n"
-              << "Optional: " << (T->IsOptional ? "yes" : "no") << "\n";
+              << "Optional: " << (T->IsOptional ? "yes" : "no") << "\n"
+              << "KeepCompressed: " << (T->KeepCompressed ? "yes" : "no") << "\n";
            for (std::map<std::string,std::string>::const_iterator O = AddOptions.begin(); O != AddOptions.end(); ++O)
               stanza << format_key(O->first) << ": " << O->second << "\n";
            for (std::map<std::string,std::string>::const_iterator O = T->Options.begin(); O != T->Options.end(); ++O)
-              stanza << format_key(O->first) << ": " << O->second << "\n";
+           {
+              if (O->first == "PDIFFS")
+                 stanza << "PDiffs: " << O->second << "\n";
+              else if (O->first == "COMPRESSIONTYPES")
+                 stanza << "CompressionTypes: " << O->second << "\n";
+              else if (O->first == "DEFAULTENABLED")
+                 stanza << "DefaultEnabled: " << O->second << "\n";
+              else
+                 stanza << format_key(O->first) << ": " << O->second << "\n";
+           }
            stanza << "\n";
 
            if (Filtered)
@@ -1683,18 +1644,21 @@ int main(int argc,const char *argv[])                                   /*{{{*/
                                    {"remove",&DoInstall},
                                    {"purge",&DoInstall},
                                   {"autoremove",&DoInstall},
+                                  {"auto-remove",&DoInstall},
                                   {"markauto",&DoMarkAuto},
                                   {"unmarkauto",&DoMarkAuto},
                                    {"dist-upgrade",&DoDistUpgrade},
+                                   {"full-upgrade",&DoDistUpgrade},
                                    {"dselect-upgrade",&DoDSelectUpgrade},
                                   {"build-dep",&DoBuildDep},
                                    {"clean",&DoClean},
                                    {"autoclean",&DoAutoClean},
+                                   {"auto-clean",&DoAutoClean},
                                    {"check",&DoCheck},
                                   {"source",&DoSource},
                                    {"download",&DoDownload},
                                    {"changelog",&DoChangelog},
-                                  {"files",&DoFiles},
+                                  {"indextargets",&DoIndexTargets},
                                   {"moo",&DoMoo},
                                   {"help",&ShowHelp},
                                    {0,0}};