~ubuntu-branches/ubuntu/trusty/apt/trusty

« back to all changes in this revision

Viewing changes to cmdline/apt-get.cc

  • Committer: Package Import Robot
  • Author(s): Michael Vogt
  • Date: 2014-04-01 17:48:58 UTC
  • mfrom: (1.4.87 sid)
  • Revision ID: package-import@ubuntu.com-20140401174858-4mv29mm29zu22fn1
Tags: 1.0.1ubuntu1
merge with the debian/sid 1.0.1 version
(LP: #1302033)

Show diffs side-by-side

added added

removed removed

Lines of Context:
27
27
// Include Files                                                        /*{{{*/
28
28
#include <config.h>
29
29
 
 
30
#include <apt-pkg/acquire-item.h>
 
31
#include <apt-pkg/algorithms.h>
30
32
#include <apt-pkg/aptconfiguration.h>
 
33
#include <apt-pkg/cachefile.h>
 
34
#include <apt-pkg/cacheset.h>
 
35
#include <apt-pkg/clean.h>
 
36
#include <apt-pkg/cmndline.h>
 
37
#include <apt-pkg/debmetaindex.h>
 
38
#include <apt-pkg/depcache.h>
31
39
#include <apt-pkg/error.h>
32
 
#include <apt-pkg/cmndline.h>
 
40
#include <apt-pkg/fileutl.h>
 
41
#include <apt-pkg/indexfile.h>
 
42
#include <apt-pkg/indexrecords.h>
33
43
#include <apt-pkg/init.h>
34
 
#include <apt-pkg/depcache.h>
 
44
#include <apt-pkg/md5.h>
 
45
#include <apt-pkg/metaindex.h>
 
46
#include <apt-pkg/pkgrecords.h>
 
47
#include <apt-pkg/pkgsystem.h>
 
48
#include <apt-pkg/progress.h>
35
49
#include <apt-pkg/sourcelist.h>
36
 
#include <apt-pkg/algorithms.h>
37
 
#include <apt-pkg/acquire-item.h>
 
50
#include <apt-pkg/srcrecords.h>
38
51
#include <apt-pkg/strutl.h>
39
 
#include <apt-pkg/fileutl.h>
40
 
#include <apt-pkg/clean.h>
41
 
#include <apt-pkg/srcrecords.h>
42
52
#include <apt-pkg/version.h>
43
 
#include <apt-pkg/cachefile.h>
44
 
#include <apt-pkg/cacheset.h>
45
 
#include <apt-pkg/sptr.h>
46
 
#include <apt-pkg/md5.h>
47
 
#include <apt-pkg/versionmatch.h>
48
 
#include <apt-pkg/progress.h>
49
 
#include <apt-pkg/pkgsystem.h>
50
 
#include <apt-pkg/pkgrecords.h>
51
 
#include <apt-pkg/indexfile.h>
 
53
#include <apt-pkg/acquire.h>
 
54
#include <apt-pkg/configuration.h>
 
55
#include <apt-pkg/macros.h>
 
56
#include <apt-pkg/pkgcache.h>
 
57
#include <apt-pkg/cacheiterators.h>
52
58
#include <apt-pkg/upgrade.h>
53
 
#include <apt-pkg/metaindex.h>
54
 
#include <apt-pkg/indexrecords.h>
55
59
 
 
60
#include <apt-private/acqprogress.h>
 
61
#include <apt-private/private-cacheset.h>
 
62
#include <apt-private/private-cachefile.h>
 
63
#include <apt-private/private-cmndline.h>
56
64
#include <apt-private/private-download.h>
57
65
#include <apt-private/private-install.h>
 
66
#include <apt-private/private-main.h>
 
67
#include <apt-private/private-moo.h>
 
68
#include <apt-private/private-output.h>
 
69
#include <apt-private/private-update.h>
58
70
#include <apt-private/private-upgrade.h>
59
 
#include <apt-private/private-output.h>
60
 
#include <apt-private/private-cacheset.h>
61
 
#include <apt-private/private-update.h>
62
 
#include <apt-private/private-cmndline.h>
63
 
#include <apt-private/private-moo.h>
64
71
#include <apt-private/private-utils.h>
65
72
 
66
 
#include <apt-pkg/debmetaindex.h>
67
 
 
68
 
#include <apt-private/acqprogress.h>
69
 
 
70
 
#include <set>
71
 
#include <fstream>
72
 
#include <sstream>
73
 
 
74
 
#include <locale.h>
75
 
#include <langinfo.h>
76
 
#include <termios.h>
 
73
#include <errno.h>
 
74
#include <signal.h>
 
75
#include <stddef.h>
 
76
#include <stdio.h>
 
77
#include <stdlib.h>
 
78
#include <string.h>
77
79
#include <sys/ioctl.h>
78
80
#include <sys/stat.h>
79
81
#include <sys/statfs.h>
80
82
#include <sys/statvfs.h>
81
 
#include <signal.h>
 
83
#include <sys/wait.h>
82
84
#include <unistd.h>
83
 
#include <stdio.h>
84
 
#include <errno.h>
85
 
#include <regex.h>
86
 
#include <sys/wait.h>
87
 
 
88
 
#include <apt-private/private-output.h>
89
 
#include <apt-private/private-main.h>
 
85
#include <algorithm>
 
86
#include <fstream>
 
87
#include <iostream>
 
88
#include <set>
 
89
#include <string>
 
90
#include <vector>
90
91
 
91
92
#include <apti18n.h>
92
93
                                                                        /*}}}*/
97
98
// ---------------------------------------------------------------------
98
99
/* This used to be inlined in DoInstall, but with the advent of regex package
99
100
   name matching it was split out.. */
100
 
bool TryToInstallBuildDep(pkgCache::PkgIterator Pkg,pkgCacheFile &Cache,
 
101
static bool TryToInstallBuildDep(pkgCache::PkgIterator Pkg,pkgCacheFile &Cache,
101
102
                  pkgProblemResolver &Fix,bool Remove,bool BrokenFix,
102
103
                  bool AllowFail = true)
103
104
{
138
139
 
139
140
// helper that can go wit hthe next ABI break
140
141
#if (APT_PKG_MAJOR >= 4 && APT_PKG_MINOR < 13)
141
 
std::string MetaIndexFileNameOnDisk(metaIndex *metaindex)
 
142
static std::string MetaIndexFileNameOnDisk(metaIndex *metaindex)
142
143
{
143
144
   // FIXME: this cast is the horror, the horror
144
145
   debReleaseIndex *r = (debReleaseIndex*)metaindex;
159
160
// GetReleaseForSourceRecord - Return Suite for the given srcrecord     /*{{{*/
160
161
// ---------------------------------------------------------------------
161
162
/* */
162
 
std::string GetReleaseForSourceRecord(pkgSourceList *SrcList,
 
163
static std::string GetReleaseForSourceRecord(pkgSourceList *SrcList,
163
164
                                      pkgSrcRecords::Parser *Parse)
164
165
{
165
166
   // try to find release
194
195
// FindSrc - Find a source record                                       /*{{{*/
195
196
// ---------------------------------------------------------------------
196
197
/* */
197
 
pkgSrcRecords::Parser *FindSrc(const char *Name,pkgRecords &Recs,
 
198
static pkgSrcRecords::Parser *FindSrc(const char *Name,pkgRecords &Recs,
198
199
                               pkgSrcRecords &SrcRecs,string &Src,
199
200
                               CacheFile &CacheFile)
200
201
{
430
431
}
431
432
                                                                        /*}}}*/
432
433
/* mark packages as automatically/manually installed.                   {{{*/
433
 
bool DoMarkAuto(CommandLine &CmdL)
 
434
static bool DoMarkAuto(CommandLine &CmdL)
434
435
{
435
436
   bool Action = true;
436
437
   int AutoMarkChanged = 0;
475
476
// DoDSelectUpgrade - Do an upgrade by following dselects selections    /*{{{*/
476
477
// ---------------------------------------------------------------------
477
478
/* Follows dselect's selections */
478
 
bool DoDSelectUpgrade(CommandLine &CmdL)
 
479
static bool DoDSelectUpgrade(CommandLine &)
479
480
{
480
481
   CacheFile Cache;
481
482
   if (Cache.OpenForInstall() == false || Cache.CheckDeps() == false)
551
552
// DoClean - Remove download archives                                   /*{{{*/
552
553
// ---------------------------------------------------------------------
553
554
/* */
554
 
bool DoClean(CommandLine &CmdL)
 
555
static bool DoClean(CommandLine &)
555
556
{
556
557
   std::string const archivedir = _config->FindDir("Dir::Cache::archives");
557
558
   std::string const pkgcache = _config->FindFile("Dir::cache::pkgcache");
599
600
   };
600
601
};
601
602
 
602
 
bool DoAutoClean(CommandLine &CmdL)
 
603
static bool DoAutoClean(CommandLine &)
603
604
{
604
605
   // Lock the archive directory
605
606
   FileFd Lock;
623
624
                                                                        /*}}}*/
624
625
// DoDownload - download a binary                                       /*{{{*/
625
626
// ---------------------------------------------------------------------
626
 
bool DoDownload(CommandLine &CmdL)
 
627
static bool DoDownload(CommandLine &CmdL)
627
628
{
628
629
   CacheFile Cache;
629
630
   if (Cache.ReadOnlyOpen() == false)
696
697
// ---------------------------------------------------------------------
697
698
/* Opening automatically checks the system, this command is mostly used
698
699
   for debugging */
699
 
bool DoCheck(CommandLine &CmdL)
 
700
static bool DoCheck(CommandLine &)
700
701
{
701
702
   CacheFile Cache;
702
703
   Cache.Open();
715
716
   string Dsc;
716
717
};
717
718
 
718
 
bool DoSource(CommandLine &CmdL)
 
719
static bool DoSource(CommandLine &CmdL)
719
720
{
720
721
   CacheFile Cache;
721
722
   if (Cache.Open(false) == false)
740
741
   pkgAcquire Fetcher;
741
742
   Fetcher.SetLog(&Stat);
742
743
 
743
 
   DscFile *Dsc = new DscFile[CmdL.FileSize()];
 
744
   SPtrArray<DscFile> Dsc = new DscFile[CmdL.FileSize()];
744
745
   
745
746
   // insert all downloaded uris into this set to avoid downloading them
746
747
   // twice
761
762
      pkgSrcRecords::Parser *Last = FindSrc(*I,Recs,SrcRecs,Src,Cache);
762
763
      
763
764
      if (Last == 0) {
764
 
         delete[] Dsc;
765
765
         return _error->Error(_("Unable to find a source package for %s"),Src.c_str());
766
766
      }
767
767
      
795
795
      // Back track
796
796
      vector<pkgSrcRecords::File> Lst;
797
797
      if (Last->Files(Lst) == false) {
798
 
         delete[] Dsc;
799
798
         return false;
800
799
      }
801
800
 
858
857
   struct statvfs Buf;
859
858
   string OutputDir = ".";
860
859
   if (statvfs(OutputDir.c_str(),&Buf) != 0) {
861
 
      delete[] Dsc;
862
860
      if (errno == EOVERFLOW)
863
861
         return _error->WarningE("statvfs",_("Couldn't determine free space in %s"),
864
862
                                OutputDir.c_str());
873
871
           || unsigned(Stat.f_type) != RAMFS_MAGIC
874
872
#endif
875
873
           )  {
876
 
         delete[] Dsc;
877
874
          return _error->Error(_("You don't have enough free space in %s"),
878
875
              OutputDir.c_str());
879
876
       }
895
892
   {
896
893
      for (unsigned I = 0; I != J; I++)
897
894
         ioprintf(cout,_("Fetch source %s\n"),Dsc[I].Package.c_str());
898
 
      delete[] Dsc;
899
895
      return true;
900
896
   }
901
897
   
906
902
      for (; I != Fetcher.UriEnd(); ++I)
907
903
         cout << '\'' << I->URI << "' " << flNotDir(I->Owner->DestFile) << ' ' << 
908
904
               I->Owner->FileSize << ' ' << I->Owner->HashSum() << endl;
909
 
      delete[] Dsc;
910
905
      return true;
911
906
   }
912
907
 
914
909
   bool Failed = false;
915
910
   if (AcquireRun(Fetcher, 0, &Failed, NULL) == false || Failed == true)
916
911
   {
917
 
      delete[] Dsc;
918
912
      return _error->Error(_("Failed to fetch some archives."));
919
913
   }
920
914
 
921
915
   if (_config->FindB("APT::Get::Download-only",false) == true)
922
916
   {
923
917
      c1out << _("Download complete and in download only mode") << endl;
924
 
      delete[] Dsc;
925
918
      return true;
926
919
   }
927
920
 
970
963
            string buildopts = _config->Find("APT::Get::Host-Architecture");
971
964
            if (buildopts.empty() == false)
972
965
               buildopts = "-a" + buildopts + " ";
 
966
 
 
967
            // get all active build profiles
 
968
            std::string const profiles = APT::Configuration::getBuildProfilesString();
 
969
            if (profiles.empty() == false)
 
970
               buildopts.append(" -P").append(profiles).append(" ");
 
971
 
973
972
            buildopts.append(_config->Find("DPkg::Build-Options","-b -uc"));
974
973
 
975
974
            // Call dpkg-buildpackage
989
988
      
990
989
      _exit(0);
991
990
   }
992
 
   delete[] Dsc;
993
991
 
994
992
   // Wait for the subprocess
995
993
   int Status = 0;
1010
1008
// ---------------------------------------------------------------------
1011
1009
/* This function will look at the build depends list of the given source 
1012
1010
   package and install the necessary packages to make it true, or fail. */
1013
 
bool DoBuildDep(CommandLine &CmdL)
 
1011
static bool DoBuildDep(CommandLine &CmdL)
1014
1012
{
1015
1013
   CacheFile Cache;
1016
1014
 
1404
1402
 * pool/ next to the deb itself)
1405
1403
 * Example return: "pool/main/a/apt/apt_0.8.8ubuntu3" 
1406
1404
 */
1407
 
string GetChangelogPath(CacheFile &Cache, 
 
1405
static string GetChangelogPath(CacheFile &Cache, 
1408
1406
                        pkgCache::PkgIterator Pkg,
1409
1407
                        pkgCache::VerIterator Ver)
1410
1408
{
1431
1429
 * apt-get changelog mplayer-doc:
1432
1430
 *  http://packages.medibuntu.org/pool/non-free/m/mplayer/mplayer_1.0~rc4~try1.dsfg1-1ubuntu1+medibuntu1.changelog
1433
1431
 */
1434
 
bool GuessThirdPartyChangelogUri(CacheFile &Cache, 
 
1432
static bool GuessThirdPartyChangelogUri(CacheFile &Cache, 
1435
1433
                                 pkgCache::PkgIterator Pkg,
1436
1434
                                 pkgCache::VerIterator Ver,
1437
1435
                                 string &out_uri)
1456
1454
                                                                        /*}}}*/
1457
1455
// DownloadChangelog - Download the changelog                           /*{{{*/
1458
1456
// ---------------------------------------------------------------------
1459
 
bool DownloadChangelog(CacheFile &CacheFile, pkgAcquire &Fetcher, 
 
1457
static bool DownloadChangelog(CacheFile &CacheFile, pkgAcquire &Fetcher, 
1460
1458
                       pkgCache::VerIterator Ver, string targetfile)
1461
1459
/* Download a changelog file for the given package version to
1462
1460
 * targetfile. This will first try the server from Apt::Changelogs::Server
1514
1512
                                                                        /*}}}*/
1515
1513
// DoChangelog - Get changelog from the command line                    /*{{{*/
1516
1514
// ---------------------------------------------------------------------
1517
 
bool DoChangelog(CommandLine &CmdL)
 
1515
static bool DoChangelog(CommandLine &CmdL)
1518
1516
{
1519
1517
   CacheFile Cache;
1520
1518
   if (Cache.ReadOnlyOpen() == false)
1578
1576
// ShowHelp - Show a help screen                                        /*{{{*/
1579
1577
// ---------------------------------------------------------------------
1580
1578
/* */
1581
 
bool ShowHelp(CommandLine &CmdL)
 
1579
static bool ShowHelp(CommandLine &)
1582
1580
{
1583
1581
   ioprintf(cout,_("%s %s for %s compiled on %s %s\n"),PACKAGE,PACKAGE_VERSION,
1584
1582
            COMMON_ARCH,__DATE__,__TIME__);
1674
1672
// SigWinch - Window size change signal handler                         /*{{{*/
1675
1673
// ---------------------------------------------------------------------
1676
1674
/* */
1677
 
void SigWinch(int)
 
1675
static void SigWinch(int)
1678
1676
{
1679
1677
   // Riped from GNU ls
1680
1678
#ifdef TIOCGWINSZ