]> git.saurik.com Git - apt.git/blobdiff - cmdline/apt-get.cc
remove empty keyrings in trusted.gpg.d on upgrade
[apt.git] / cmdline / apt-get.cc
index 253b2f4a5b1a041a0b8339ec556e560bca8937f0..aed1beb4df6c6009fb51b2f02d182cc5c86ccce5 100644 (file)
 // Include Files                                                       /*{{{*/
 #include <config.h>
 
+#include <apt-pkg/acquire-item.h>
+#include <apt-pkg/algorithms.h>
 #include <apt-pkg/aptconfiguration.h>
-#include <apt-pkg/error.h>
+#include <apt-pkg/cachefile.h>
+#include <apt-pkg/cacheset.h>
+#include <apt-pkg/clean.h>
 #include <apt-pkg/cmndline.h>
-#include <apt-pkg/init.h>
+#include <apt-pkg/debmetaindex.h>
 #include <apt-pkg/depcache.h>
-#include <apt-pkg/sourcelist.h>
-#include <apt-pkg/algorithms.h>
-#include <apt-pkg/acquire-item.h>
-#include <apt-pkg/strutl.h>
+#include <apt-pkg/error.h>
 #include <apt-pkg/fileutl.h>
-#include <apt-pkg/clean.h>
-#include <apt-pkg/srcrecords.h>
-#include <apt-pkg/version.h>
-#include <apt-pkg/cachefile.h>
-#include <apt-pkg/cacheset.h>
-#include <apt-pkg/sptr.h>
+#include <apt-pkg/indexfile.h>
+#include <apt-pkg/indexrecords.h>
+#include <apt-pkg/init.h>
 #include <apt-pkg/md5.h>
-#include <apt-pkg/versionmatch.h>
-#include <apt-pkg/progress.h>
-#include <apt-pkg/pkgsystem.h>
+#include <apt-pkg/metaindex.h>
 #include <apt-pkg/pkgrecords.h>
-#include <apt-pkg/indexfile.h>
+#include <apt-pkg/pkgsystem.h>
+#include <apt-pkg/progress.h>
+#include <apt-pkg/sourcelist.h>
+#include <apt-pkg/srcrecords.h>
+#include <apt-pkg/strutl.h>
+#include <apt-pkg/version.h>
+#include <apt-pkg/acquire.h>
+#include <apt-pkg/configuration.h>
+#include <apt-pkg/macros.h>
+#include <apt-pkg/pkgcache.h>
+#include <apt-pkg/cacheiterators.h>
 #include <apt-pkg/upgrade.h>
-#include <apt-pkg/metaindex.h>
-#include <apt-pkg/indexrecords.h>
 
+#include <apt-private/acqprogress.h>
+#include <apt-private/private-cacheset.h>
+#include <apt-private/private-cachefile.h>
+#include <apt-private/private-cmndline.h>
 #include <apt-private/private-download.h>
 #include <apt-private/private-install.h>
-#include <apt-private/private-upgrade.h>
+#include <apt-private/private-main.h>
+#include <apt-private/private-moo.h>
 #include <apt-private/private-output.h>
-#include <apt-private/private-cacheset.h>
 #include <apt-private/private-update.h>
-#include <apt-private/private-cmndline.h>
-#include <apt-private/private-moo.h>
+#include <apt-private/private-upgrade.h>
 #include <apt-private/private-utils.h>
 
-#include <apt-pkg/debmetaindex.h>
-
-#include <apt-private/acqprogress.h>
-
-#include <set>
-#include <fstream>
-#include <sstream>
-
-#include <locale.h>
-#include <langinfo.h>
-#include <termios.h>
+#include <errno.h>
+#include <signal.h>
+#include <stddef.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
 #include <sys/ioctl.h>
 #include <sys/stat.h>
 #include <sys/statfs.h>
 #include <sys/statvfs.h>
-#include <signal.h>
-#include <unistd.h>
-#include <stdio.h>
-#include <errno.h>
-#include <regex.h>
 #include <sys/wait.h>
-
-#include <apt-private/private-output.h>
-#include <apt-private/private-main.h>
+#include <unistd.h>
+#include <algorithm>
+#include <fstream>
+#include <iostream>
+#include <set>
+#include <string>
+#include <vector>
 
 #include <apti18n.h>
                                                                        /*}}}*/
@@ -475,7 +476,7 @@ static bool DoMarkAuto(CommandLine &CmdL)
 // DoDSelectUpgrade - Do an upgrade by following dselects selections   /*{{{*/
 // ---------------------------------------------------------------------
 /* Follows dselect's selections */
-static bool DoDSelectUpgrade(CommandLine &CmdL)
+static bool DoDSelectUpgrade(CommandLine &)
 {
    CacheFile Cache;
    if (Cache.OpenForInstall() == false || Cache.CheckDeps() == false)
@@ -539,7 +540,7 @@ static bool DoDSelectUpgrade(CommandLine &CmdL)
    }
 
    // Now upgrade everything
-   if (pkgAllUpgrade(Cache) == false)
+   if (APT::Upgrade::Upgrade(Cache, APT::Upgrade::FORBID_REMOVE_PACKAGES | APT::Upgrade::FORBID_INSTALL_NEW_PACKAGES) == false)
    {
       ShowBroken(c1out,Cache,false);
       return _error->Error(_("Internal error, problem resolver broke stuff"));
@@ -551,7 +552,7 @@ static bool DoDSelectUpgrade(CommandLine &CmdL)
 // DoClean - Remove download archives                                  /*{{{*/
 // ---------------------------------------------------------------------
 /* */
-static bool DoClean(CommandLine &CmdL)
+static bool DoClean(CommandLine &)
 {
    std::string const archivedir = _config->FindDir("Dir::Cache::archives");
    std::string const pkgcache = _config->FindFile("Dir::cache::pkgcache");
@@ -599,7 +600,7 @@ class LogCleaner : public pkgArchiveCleaner
    };
 };
 
-static bool DoAutoClean(CommandLine &CmdL)
+static bool DoAutoClean(CommandLine &)
 {
    // Lock the archive directory
    FileFd Lock;
@@ -696,7 +697,7 @@ static bool DoDownload(CommandLine &CmdL)
 // ---------------------------------------------------------------------
 /* Opening automatically checks the system, this command is mostly used
    for debugging */
-static bool DoCheck(CommandLine &CmdL)
+static bool DoCheck(CommandLine &)
 {
    CacheFile Cache;
    Cache.Open();
@@ -740,7 +741,7 @@ static bool DoSource(CommandLine &CmdL)
    pkgAcquire Fetcher;
    Fetcher.SetLog(&Stat);
 
-   DscFile *Dsc = new DscFile[CmdL.FileSize()];
+   SPtrArray<DscFile> Dsc = new DscFile[CmdL.FileSize()];
    
    // insert all downloaded uris into this set to avoid downloading them
    // twice
@@ -755,15 +756,18 @@ static bool DoSource(CommandLine &CmdL)
 
    // Load the requestd sources into the fetcher
    unsigned J = 0;
+   std::string UntrustedList;
    for (const char **I = CmdL.FileList + 1; *I != 0; I++, J++)
    {
       string Src;
       pkgSrcRecords::Parser *Last = FindSrc(*I,Recs,SrcRecs,Src,Cache);
       
       if (Last == 0) {
-        delete[] Dsc;
         return _error->Error(_("Unable to find a source package for %s"),Src.c_str());
       }
+
+      if (Last->Index().IsTrusted() == false)
+         UntrustedList += Src + " ";
       
       string srec = Last->AsStr();
       string::size_type pos = srec.find("\nVcs-");
@@ -795,7 +799,6 @@ static bool DoSource(CommandLine &CmdL)
       // Back track
       vector<pkgSrcRecords::File> Lst;
       if (Last->Files(Lst) == false) {
-        delete[] Dsc;
         return false;
       }
 
@@ -829,25 +832,31 @@ static bool DoSource(CommandLine &CmdL)
         queued.insert(Last->Index().ArchiveURI(I->Path));
 
         // check if we have a file with that md5 sum already localy
-        if(!I->MD5Hash.empty() && FileExists(flNotDir(I->Path)))  
-        {
-           FileFd Fd(flNotDir(I->Path), FileFd::ReadOnly);
-           MD5Summation sum;
-           sum.AddFD(Fd.Fd(), Fd.Size());
-           Fd.Close();
-           if((string)sum.Result() == I->MD5Hash) 
+        std::string localFile = flNotDir(I->Path);
+        if (FileExists(localFile) == true)
+           if(I->Hashes.VerifyFile(localFile) == true)
            {
               ioprintf(c1out,_("Skipping already downloaded file '%s'\n"),
-                       flNotDir(I->Path).c_str());
+                       localFile.c_str());
               continue;
            }
+
+        // see if we have a hash (Acquire::ForceHash is the only way to have none)
+        if (I->Hashes.usable() == false && _config->FindB("APT::Get::AllowUnauthenticated",false) == false)
+        {
+           ioprintf(c1out, "Skipping download of file '%s' as requested hashsum is not available for authentication\n",
+                    localFile.c_str());
+           continue;
         }
 
         new pkgAcqFile(&Fetcher,Last->Index().ArchiveURI(I->Path),
-                       I->MD5Hash,I->Size,
-                       Last->Index().SourceInfo(*Last,*I),Src);
+                       I->Hashes, I->Size, Last->Index().SourceInfo(*Last,*I), Src);
       }
    }
+
+   // check authentication status of the source as well
+   if (UntrustedList != "" && !AuthPrompt(UntrustedList, false))
+      return false;
    
    // Display statistics
    unsigned long long FetchBytes = Fetcher.FetchNeeded();
@@ -858,7 +867,6 @@ static bool DoSource(CommandLine &CmdL)
    struct statvfs Buf;
    string OutputDir = ".";
    if (statvfs(OutputDir.c_str(),&Buf) != 0) {
-      delete[] Dsc;
       if (errno == EOVERFLOW)
         return _error->WarningE("statvfs",_("Couldn't determine free space in %s"),
                                OutputDir.c_str());
@@ -873,7 +881,6 @@ static bool DoSource(CommandLine &CmdL)
            || unsigned(Stat.f_type) != RAMFS_MAGIC
 #endif
            )  {
-        delete[] Dsc;
           return _error->Error(_("You don't have enough free space in %s"),
               OutputDir.c_str());
        }
@@ -895,7 +902,6 @@ static bool DoSource(CommandLine &CmdL)
    {
       for (unsigned I = 0; I != J; I++)
         ioprintf(cout,_("Fetch source %s\n"),Dsc[I].Package.c_str());
-      delete[] Dsc;
       return true;
    }
    
@@ -906,7 +912,6 @@ static bool DoSource(CommandLine &CmdL)
       for (; I != Fetcher.UriEnd(); ++I)
         cout << '\'' << I->URI << "' " << flNotDir(I->Owner->DestFile) << ' ' << 
               I->Owner->FileSize << ' ' << I->Owner->HashSum() << endl;
-      delete[] Dsc;
       return true;
    }
 
@@ -914,14 +919,12 @@ static bool DoSource(CommandLine &CmdL)
    bool Failed = false;
    if (AcquireRun(Fetcher, 0, &Failed, NULL) == false || Failed == true)
    {
-      delete[] Dsc;
       return _error->Error(_("Failed to fetch some archives."));
    }
 
    if (_config->FindB("APT::Get::Download-only",false) == true)
    {
       c1out << _("Download complete and in download only mode") << endl;
-      delete[] Dsc;
       return true;
    }
 
@@ -952,18 +955,19 @@ static bool DoSource(CommandLine &CmdL)
         else
         {
            // Call dpkg-source
-           char S[500];
-           snprintf(S,sizeof(S),"%s -x %s",
+           std::string const sourceopts = _config->Find("DPkg::Source-Options", "-x");
+           std::string S;
+           strprintf(S, "%s %s %s",
                     _config->Find("Dir::Bin::dpkg-source","dpkg-source").c_str(),
-                    Dsc[I].Dsc.c_str());
-           if (system(S) != 0)
+                    sourceopts.c_str(), Dsc[I].Dsc.c_str());
+           if (system(S.c_str()) != 0)
            {
-              fprintf(stderr,_("Unpack command '%s' failed.\n"),S);
-              fprintf(stderr,_("Check if the 'dpkg-dev' package is installed.\n"));
+              fprintf(stderr, _("Unpack command '%s' failed.\n"), S.c_str());
+              fprintf(stderr, _("Check if the 'dpkg-dev' package is installed.\n"));
               _exit(1);
-           }       
+           }
         }
-        
+
         // Try to compile it with dpkg-buildpackage
         if (_config->FindB("APT::Get::Compile",false) == true)
         {
@@ -979,23 +983,22 @@ static bool DoSource(CommandLine &CmdL)
            buildopts.append(_config->Find("DPkg::Build-Options","-b -uc"));
 
            // Call dpkg-buildpackage
-           char S[500];
-           snprintf(S,sizeof(S),"cd %s && %s %s",
+           std::string S;
+           strprintf(S, "cd %s && %s %s",
                     Dir.c_str(),
                     _config->Find("Dir::Bin::dpkg-buildpackage","dpkg-buildpackage").c_str(),
                     buildopts.c_str());
-           
-           if (system(S) != 0)
+
+           if (system(S.c_str()) != 0)
            {
-              fprintf(stderr,_("Build command '%s' failed.\n"),S);
+              fprintf(stderr, _("Build command '%s' failed.\n"), S.c_str());
               _exit(1);
-           }       
-        }      
+           }
+        }
       }
-      
+
       _exit(0);
    }
-   delete[] Dsc;
 
    // Wait for the subprocess
    int Status = 0;
@@ -1061,7 +1064,35 @@ static bool DoBuildDep(CommandLine &CmdL)
    for (const char **I = CmdL.FileList + 1; *I != 0; I++, J++)
    {
       string Src;
-      pkgSrcRecords::Parser *Last = FindSrc(*I,Recs,SrcRecs,Src,Cache);
+      pkgSrcRecords::Parser *Last = 0;
+
+      // an unpacked debian source tree
+      using APT::String::Startswith;
+      if ((Startswith(*I, "./") || Startswith(*I, "/")) &&
+          DirectoryExists(*I))
+      {
+         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";
+         pkgIndexFile::Type *Type = pkgIndexFile::Type::GetType(TypeName.c_str());
+         if(Type != NULL)
+            Last = Type->CreateSrcPkgParser(*I);
+      }
+      // if its a local file (e.g. .dsc) use this
+      else if (FileExists(*I))
+      {
+         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";
+         pkgIndexFile::Type *Type = pkgIndexFile::Type::GetType(TypeName.c_str());
+         if(Type != NULL)
+            Last = Type->CreateSrcPkgParser(*I);
+      } else {
+         // normal case, search the cache for the source file
+         Last = FindSrc(*I,Recs,SrcRecs,Src,Cache);
+      }
+
       if (Last == 0)
         return _error->Error(_("Unable to find a source package for %s"),Src.c_str());
             
@@ -1079,7 +1110,7 @@ static bool DoBuildDep(CommandLine &CmdL)
       }
       else if (Last->BuildDepends(BuildDeps, _config->FindB("APT::Get::Arch-Only", false), StripMultiArch) == false)
            return _error->Error(_("Unable to get build-dependency information for %s"),Src.c_str());
-   
+
       // Also ensure that build-essential packages are present
       Configuration::Item const *Opts = _config->Tree("APT::Build-Essential");
       if (Opts) 
@@ -1581,7 +1612,7 @@ static bool DoChangelog(CommandLine &CmdL)
 // ShowHelp - Show a help screen                                       /*{{{*/
 // ---------------------------------------------------------------------
 /* */
-static bool ShowHelp(CommandLine &CmdL)
+static bool ShowHelp(CommandLine &)
 {
    ioprintf(cout,_("%s %s for %s compiled on %s %s\n"),PACKAGE,PACKAGE_VERSION,
            COMMON_ARCH,__DATE__,__TIME__);
@@ -1672,20 +1703,6 @@ static bool ShowHelp(CommandLine &CmdL)
       "pages for more information and options.\n"
       "                       This APT has Super Cow Powers.\n");
    return true;
-}
-                                                                       /*}}}*/
-// SigWinch - Window size change signal handler                                /*{{{*/
-// ---------------------------------------------------------------------
-/* */
-static void SigWinch(int)
-{
-   // Riped from GNU ls
-#ifdef TIOCGWINSZ
-   struct winsize ws;
-  
-   if (ioctl(1, TIOCGWINSZ, &ws) != -1 && ws.ws_col >= 5)
-      ScreenWidth = ws.ws_col - 1;
-#endif
 }
                                                                        /*}}}*/
 int main(int argc,const char *argv[])                                  /*{{{*/
@@ -1742,14 +1759,12 @@ int main(int argc,const char *argv[])                                   /*{{{*/
    // see if we are in simulate mode
    CheckSimulateMode(CmdL);
 
+   // Init the signals
+   InitSignals();
+
    // Setup the output streams
    InitOutput();
 
-   // Setup the signals
-   signal(SIGPIPE,SIG_IGN);
-   signal(SIGWINCH,SigWinch);
-   SigWinch(0);
-
    // Match the operation
    CmdL.DispatchArg(Cmds);