]> git.saurik.com Git - apt.git/blobdiff - cmdline/apt-get.cc
add cacheset push_back wrapping for std::back_inserter
[apt.git] / cmdline / apt-get.cc
index a69f5418a096cdb9f20b09ed63a8e0fc362872a3..cef7d8c1477c08d57514e88a28fafcfe66d88484 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>
@@ -78,7 +78,6 @@
 #include <string.h>
 #include <sys/ioctl.h>
 #include <sys/stat.h>
-#include <sys/wait.h>
 #include <unistd.h>
 #include <pwd.h>
 #include <grp.h>
@@ -161,11 +160,7 @@ static pkgCache::RlsFileIterator GetReleaseFileForSourceRecord(CacheFile &CacheF
 // 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)
 {
@@ -275,19 +270,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;
               }
            }
@@ -318,17 +302,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
         }
       }
    }
@@ -651,9 +628,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;
 
@@ -715,9 +689,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;
@@ -726,7 +697,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
@@ -741,22 +712,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)
@@ -770,17 +737,22 @@ static bool DoSource(CommandLine &CmdL)
         }
         pos += vcs.length()+2;
         string::size_type epos = srec.find("\n", pos);
-        string uri = srec.substr(pos,epos-pos).c_str();
+        string const uri = srec.substr(pos,epos-pos);
         ioprintf(c1out, _("NOTICE: '%s' packaging is maintained in "
                           "the '%s' version control system at:\n"
                           "%s\n"),
                  Src.c_str(), vcs.c_str(), uri.c_str());
-        if(vcs == "Bzr") 
-           ioprintf(c1out,_("Please use:\n"
-                            "bzr branch %s\n"
-                            "to retrieve the latest (possibly unreleased) "
-                            "updates to the package.\n"),
-                    uri.c_str());
+        std::string vcscmd;
+        if (vcs == "Bzr")
+           vcscmd = "bzr branch " + uri;
+        else if (vcs == "Git")
+           vcscmd = "git clone " + uri;
+
+        if (vcscmd.empty() == false)
+           ioprintf(c1out,_("Please use:\n%s\n"
+                    "to retrieve the latest (possibly unreleased) "
+                    "updates to the package.\n"),
+                 vcscmd.c_str());
         break;
       }
 
@@ -879,11 +851,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
@@ -971,19 +940,7 @@ static bool DoSource(CommandLine &CmdL)
       _exit(0);
    }
 
-   // Wait for the subprocess
-   int Status = 0;
-   while (waitpid(Process,&Status,0) != Process)
-   {
-      if (errno == EINTR)
-        continue;
-      return _error->Errno("waitpid","Couldn't wait for subprocess");
-   }
-
-   if (WIFEXITED(Status) == 0 || WEXITSTATUS(Status) != 0)
-      return _error->Error(_("Child process failed"));
-   
-   return true;
+   return ExecWait(Process, "dpkg-source");
 }
                                                                        /*}}}*/
 // DoBuildDep - Install/removes packages to satisfy build dependencies  /*{{{*/
@@ -995,8 +952,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)
@@ -1029,7 +988,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;
@@ -1041,7 +1000,7 @@ static bool DoBuildDep(CommandLine &CmdL)
          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))
@@ -1052,14 +1011,10 @@ static bool DoBuildDep(CommandLine &CmdL)
          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)
@@ -1204,12 +1159,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");
                  }
@@ -1434,11 +1389,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;
@@ -1529,11 +1479,21 @@ static bool DoIndexTargets(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)
@@ -1676,13 +1636,16 @@ 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},