~ubuntu-branches/ubuntu/maverick/apt/maverick-security

« back to all changes in this revision

Viewing changes to cmdline/apt-get.cc

  • Committer: Bazaar Package Importer
  • Author(s): Michael Vogt, Matt Zimmerman, Loïc Minier, Brian Murray, Michael Vogt, Merge
  • Date: 2009-09-23 18:15:10 UTC
  • mfrom: (1.1.11 squeeze)
  • Revision ID: james.westby@ubuntu.com-20090923181510-udhfn1lhbr67w5mi
Tags: 0.7.23.1ubuntu1
[ Matt Zimmerman ]
* apt-pkg/deb/dpkgpm.cc:
  - Suppress apport reports on dpkg short reads (these I/O errors are not 
    generally indicative of a bug in the packaging)

[ Loïc Minier ]
* cmdline/apt-key:
  - Emit a warning if removed keys keyring is missing and skip associated
    checks (LP: #218971)

[ Brian Murray ]
* cmdline/apt-get.cc:
  - typo fix (LP: #370094)

[ Michael Vogt ]
* apt-pkg/deb/dpkgpm.cc:
  - when tcgetattr() returns non-zero skip all pty magic 
    (thanks to Simon Richter, closes: #509866)
* apt-inst/contrib/arfile.cc:
  - show propper error message for Invalid archive members
* apt-pkg/acquire-worker.cc:
  - show error details of failed methods
* apt-pkg/contrib/fileutl.cc:
  - if a process aborts with signal, show signal number
* methods/http.cc:
  - ignore SIGPIPE, we deal with EPIPE from write in 
    HttpMethod::ServerDie() (LP: #385144)
* debian/apt.cron.daily:
  - if the timestamp is too far in the future, delete it 
    (LP: #135262)

[ Merge ]
* merged from debian, reverted the libdlopen-udev branch
  because its too late in the release process for this now
* not merged the proxy behaviour change from 0.7.23 (that will
  be part of lucid)

Show diffs side-by-side

added added

removed removed

Lines of Context:
111
111
         return Open(true);
112
112
   }
113
113
   CacheFile() : List(0) {};
 
114
   ~CacheFile() {
 
115
      delete[] List;
 
116
   }
114
117
};
115
118
                                                                        /*}}}*/
116
119
 
594
597
               Dep.BadCount());
595
598
}
596
599
                                                                        /*}}}*/
597
 
 
598
600
// CacheFile::NameComp - QSort compare by name                          /*{{{*/
599
601
// ---------------------------------------------------------------------
600
602
/* */
687
689
      
688
690
   return true;
689
691
}
690
 
 
 
692
                                                                        /*}}}*/
 
693
// CheckAuth - check if each download comes form a trusted source       /*{{{*/
 
694
// ---------------------------------------------------------------------
 
695
/* */
691
696
static bool CheckAuth(pkgAcquire& Fetcher)
692
697
{
693
698
   string UntrustedList;
728
733
 
729
734
   return _error->Error(_("There are problems and -y was used without --force-yes"));
730
735
}
731
 
 
732
 
 
733
736
                                                                        /*}}}*/
734
 
 
735
737
// InstallPackages - Actually download and install the packages         /*{{{*/
736
738
// ---------------------------------------------------------------------
737
739
/* This displays the informative messages describing what is going to 
866
868
      if (unsigned(Buf.f_bfree) < (FetchBytes - FetchPBytes)/Buf.f_bsize)
867
869
      {
868
870
         struct statfs Stat;
869
 
         if (statfs(OutputDir.c_str(),&Stat) != 0 ||
870
 
                         unsigned(Stat.f_type) != RAMFS_MAGIC)
 
871
         if (statfs(OutputDir.c_str(),&Stat) != 0
 
872
#if HAVE_STRUCT_STATFS_F_TYPE
 
873
             || unsigned(Stat.f_type) != RAMFS_MAGIC
 
874
#endif
 
875
             )
871
876
            return _error->Error(_("You don't have enough free space in %s."),
872
877
                OutputDir.c_str());
873
878
      }
1215
1220
{
1216
1221
   // We want to pull the version off the package specification..
1217
1222
   string VerTag;
 
1223
   string DefRel;
1218
1224
   string TmpSrc = Name;
1219
 
   string::size_type Slash = TmpSrc.rfind('=');
 
1225
   const size_t found = TmpSrc.find_last_of("/=");
1220
1226
 
1221
1227
   // honor default release
1222
 
   string DefRel = _config->Find("APT::Default-Release");
 
1228
   if (found != string::npos && TmpSrc[found] == '/')
 
1229
   {
 
1230
      DefRel = TmpSrc.substr(found+1);
 
1231
      TmpSrc = TmpSrc.substr(0,found);
 
1232
   }
 
1233
   else
 
1234
      DefRel = _config->Find("APT::Default-Release");
 
1235
 
1223
1236
   pkgCache::PkgIterator Pkg = Cache.FindPkg(TmpSrc);
1224
1237
 
1225
 
   if (Slash != string::npos)
 
1238
   if (found != string::npos && TmpSrc[found] == '=')
1226
1239
   {
1227
 
      VerTag = string(TmpSrc.begin() + Slash + 1,TmpSrc.end());
1228
 
      TmpSrc = string(TmpSrc.begin(),TmpSrc.begin() + Slash);
 
1240
      VerTag = TmpSrc.substr(found+1);
 
1241
      TmpSrc = TmpSrc.substr(0,found);
1229
1242
   } 
1230
1243
   else  if(!Pkg.end() && DefRel.empty() == false)
1231
1244
   {
1247
1260
                pkgCache::Flag::NotSource && Pkg.CurrentVer() != Ver)
1248
1261
            continue;
1249
1262
            
1250
 
            //std::cout << VF.File().Archive() << std::endl;
1251
 
            if(VF.File().Archive() && (VF.File().Archive() == DefRel)) 
 
1263
            if((VF.File().Archive() != 0 && VF.File().Archive() == DefRel) ||
 
1264
                (VF.File().Codename() != 0 && VF.File().Codename() == DefRel))
1252
1265
            {
1253
 
               VerTag = Ver.VerStr();
 
1266
               pkgRecords::Parser &Parse = Recs.Lookup(VF);
 
1267
               VerTag = Parse.SourceVer();
 
1268
               if (VerTag.empty())
 
1269
                  VerTag = Ver.VerStr();
1254
1270
               break;
1255
1271
            }
1256
1272
         }
1260
1276
   /* Lookup the version of the package we would install if we were to
1261
1277
      install a version and determine the source package name, then look
1262
1278
      in the archive for a source package of the same name. */
1263
 
   if (_config->FindB("APT::Get::Only-Source") == false)
 
1279
   bool MatchSrcOnly = _config->FindB("APT::Get::Only-Source");
 
1280
   if (MatchSrcOnly == false)
1264
1281
   {
1265
1282
      if (Pkg.end() == false)
1266
1283
      {
1278
1295
   unsigned long Offset = 0;
1279
1296
   string Version;
1280
1297
   bool IsMatch = false;
1281
 
   bool MatchSrcOnly = false;
1282
1298
 
1283
1299
   // No source package name..
1284
1300
   if (Src.empty() == true)
1301
1317
   while ((Parse = SrcRecs.Find(Src.c_str(), MatchSrcOnly)) != 0)
1302
1318
   {
1303
1319
      string Ver = Parse->Version();
 
1320
 
1304
1321
      // show name mismatches
1305
1322
      if (IsMatch == true && Parse->Package() != Src)       
1306
 
         ioprintf(c1out,  _("No source package '%s' picking '%s' instead\n"), Parse->Package().c_str(), Src.c_str());
 
1323
         ioprintf(c1out,  _("No source package '%s' picking '%s' instead\n"), Src.c_str(), Parse->Package().c_str());
1307
1324
      
1308
1325
      if (VerTag.empty() == false)
1309
1326
      {
1334
1351
   return Last;
1335
1352
}
1336
1353
                                                                        /*}}}*/
1337
 
 
1338
1354
// DoUpdate - Update the package lists                                  /*{{{*/
1339
1355
// ---------------------------------------------------------------------
1340
1356
/* */
1398
1414
   bool Debug = _config->FindI("Debug::pkgAutoRemove",false);
1399
1415
   bool doAutoRemove = _config->FindB("APT::Get::AutomaticRemove", false);
1400
1416
   bool hideAutoRemove = _config->FindB("APT::Get::HideAutoRemove");
 
1417
 
1401
1418
   pkgDepCache::ActionGroup group(*Cache);
1402
 
 
1403
1419
   if(Debug)
1404
1420
      std::cout << "DoAutomaticRemove()" << std::endl;
1405
1421
 
1406
 
   if (_config->FindB("APT::Get::Remove",true) == false &&
1407
 
       doAutoRemove == true)
 
1422
   // we don't want to autoremove and we don't want to see it, so why calculating?
 
1423
   if (doAutoRemove == false && hideAutoRemove == true)
 
1424
      return true;
 
1425
 
 
1426
   if (doAutoRemove == true &&
 
1427
        _config->FindB("APT::Get::Remove",true) == false)
1408
1428
   {
1409
1429
      c1out << _("We are not supposed to delete stuff, can't start "
1410
1430
                 "AutoRemover") << std::endl;
1411
 
      doAutoRemove = false;
 
1431
      return false;
1412
1432
   }
1413
1433
 
 
1434
   bool purgePkgs = _config->FindB("APT::Get::Purge", false);
 
1435
   bool smallList = (hideAutoRemove == false &&
 
1436
        strcasecmp(_config->Find("APT::Get::HideAutoRemove","").c_str(),"small") == 0);
 
1437
 
1414
1438
   string autoremovelist, autoremoveversions;
 
1439
   unsigned long autoRemoveCount = 0;
1415
1440
   // look over the cache to see what can be removed
1416
1441
   for (pkgCache::PkgIterator Pkg = Cache->PkgBegin(); ! Pkg.end(); ++Pkg)
1417
1442
   {
1420
1445
         if(Pkg.CurrentVer() != 0 || Cache[Pkg].Install())
1421
1446
            if(Debug)
1422
1447
               std::cout << "We could delete %s" <<  Pkg.Name() << std::endl;
1423
 
          
1424
 
         // only show stuff in the list that is not yet marked for removal
1425
 
         if(Cache[Pkg].Delete() == false) 
1426
 
         {
1427
 
            autoremovelist += string(Pkg.Name()) + " ";
1428
 
            autoremoveversions += string(Cache[Pkg].CandVersion) + "\n";
1429
 
         }
 
1448
 
1430
1449
         if (doAutoRemove)
1431
1450
         {
1432
1451
            if(Pkg.CurrentVer() != 0 && 
1433
1452
               Pkg->CurrentState != pkgCache::State::ConfigFiles)
1434
 
               Cache->MarkDelete(Pkg, _config->FindB("APT::Get::Purge", false));
 
1453
               Cache->MarkDelete(Pkg, purgePkgs);
1435
1454
            else
1436
1455
               Cache->MarkKeep(Pkg, false, false);
1437
1456
         }
 
1457
         else
 
1458
         {
 
1459
            // only show stuff in the list that is not yet marked for removal
 
1460
            if(Cache[Pkg].Delete() == false) 
 
1461
            {
 
1462
               // we don't need to fill the strings if we don't need them
 
1463
               if (smallList == true)
 
1464
                  ++autoRemoveCount;
 
1465
               else
 
1466
               {
 
1467
                 autoremovelist += string(Pkg.Name()) + " ";
 
1468
                 autoremoveversions += string(Cache[Pkg].CandVersion) + "\n";
 
1469
               }
 
1470
            }
 
1471
         }
1438
1472
      }
1439
1473
   }
1440
 
   if (!hideAutoRemove) 
1441
 
      ShowList(c1out, _("The following packages were automatically installed and are no longer required:"), autoremovelist, autoremoveversions);
1442
 
   if (!doAutoRemove && !hideAutoRemove && autoremovelist.size() > 0)
 
1474
   // if we don't remove them, we should show them!
 
1475
   if (doAutoRemove == false && (autoremovelist.empty() == false || autoRemoveCount != 0))
 
1476
   {
 
1477
      if (smallList == false)
 
1478
         ShowList(c1out, _("The following packages were automatically installed and are no longer required:"), autoremovelist, autoremoveversions);
 
1479
      else
 
1480
         ioprintf(c1out, _("%lu packages were automatically installed and are no longer required.\n"), autoRemoveCount);
1443
1481
      c1out << _("Use 'apt-get autoremove' to remove them.") << std::endl;
1444
 
 
1445
 
   // Now see if we destroyed anything
1446
 
   if (Cache->BrokenCount() != 0)
 
1482
   }
 
1483
   // Now see if we had destroyed anything (if we had done anything)
 
1484
   else if (Cache->BrokenCount() != 0)
1447
1485
   {
1448
1486
      c1out << _("Hmm, seems like the AutoRemover destroyed something which really\n"
1449
1487
                 "shouldn't happen. Please file a bug report against apt.") << endl;
1456
1494
   }
1457
1495
   return true;
1458
1496
}
1459
 
 
 
1497
                                                                        /*}}}*/
1460
1498
// DoUpgrade - Upgrade all packages                                     /*{{{*/
1461
1499
// ---------------------------------------------------------------------
1462
1500
/* Upgrade all packages without installing new packages or erasing old
1531
1569
   regfree(&Pattern);
1532
1570
   return res;
1533
1571
}
1534
 
 
 
1572
                                                                        /*}}}*/
1535
1573
// DoInstall - Install packages from the command line                   /*{{{*/
1536
1574
// ---------------------------------------------------------------------
1537
1575
/* Install named packages */
1869
1907
   // cache.commit()
1870
1908
   if (AutoMarkChanged > 0 &&
1871
1909
       Cache->DelCount() == 0 && Cache->InstCount() == 0 &&
1872
 
       Cache->BadCount() == 0)
 
1910
       Cache->BadCount() == 0 &&
 
1911
       _config->FindB("APT::Get::Simulate",false) == false)
1873
1912
      Cache->writeStateFile(NULL);
1874
1913
 
1875
1914
   // See if we need to prompt
2124
2163
         if(vcs == "Bzr") 
2125
2164
            ioprintf(c1out,_("Please use:\n"
2126
2165
                             "bzr get %s\n"
2127
 
                             "to retrieve the latest (possible unreleased) "
 
2166
                             "to retrieve the latest (possibly unreleased) "
2128
2167
                             "updates to the package.\n"),
2129
2168
                     uri.c_str());
2130
2169
         break;
2203
2242
   if (unsigned(Buf.f_bfree) < (FetchBytes - FetchPBytes)/Buf.f_bsize)
2204
2243
     {
2205
2244
       struct statfs Stat;
2206
 
       if (statfs(OutputDir.c_str(),&Stat) != 0 || 
2207
 
           unsigned(Stat.f_type) != RAMFS_MAGIC) 
 
2245
       if (statfs(OutputDir.c_str(),&Stat) != 0
 
2246
#if HAVE_STRUCT_STATFS_F_TYPE
 
2247
           || unsigned(Stat.f_type) != RAMFS_MAGIC
 
2248
#endif
 
2249
           ) 
2208
2250
          return _error->Error(_("You don't have enough free space in %s"),
2209
2251
              OutputDir.c_str());
2210
2252
      }
2574
2616
      
2575
2617
      // Now we check the state of the packages,
2576
2618
      if (Cache->BrokenCount() != 0)
2577
 
         return _error->Error(_("Build-dependencies for %s could not be satisfied."),*I);
 
2619
      {
 
2620
         ShowBroken(cout, Cache, false);
 
2621
         return _error->Error(_("Build-dependencies for %s could not be satisfied."),*I);
 
2622
      }
2578
2623
   }
2579
2624
  
2580
2625
   if (InstallPackages(Cache, false, true) == false)
2724
2769
#endif
2725
2770
}
2726
2771
                                                                        /*}}}*/
2727
 
 
2728
 
int main(int argc,const char *argv[])
 
2772
int main(int argc,const char *argv[])                                   /*{{{*/
2729
2773
{
2730
2774
   CommandLine::Args Args[] = {
2731
2775
      {'h',"help","help",0},
2813
2857
      ShowHelp(CmdL);
2814
2858
      return 0;
2815
2859
   }
2816
 
   
 
2860
 
 
2861
   // simulate user-friendly if apt-get has no root privileges
 
2862
   if (getuid() != 0 && _config->FindB("APT::Get::Simulate") == true)
 
2863
   {
 
2864
      if (_config->FindB("APT::Get::Show-User-Simulation-Note",true) == true)
 
2865
         cout << _("NOTE: This is only a simulation!\n"
 
2866
            "      apt-get needs root privileges for real execution.\n"
 
2867
            "      Keep also in mind that locking is deactivated,\n"
 
2868
            "      so don't depend on the relevance to the real current situation!"
 
2869
         ) << std::endl;
 
2870
      _config->Set("Debug::NoLocking",true);
 
2871
   }
 
2872
 
2817
2873
   // Deal with stdout not being a tty
2818
2874
   if (!isatty(STDOUT_FILENO) && _config->FindI("quiet",0) < 1)
2819
2875
      _config->Set("quiet","1");
2845
2901
   
2846
2902
   return 0;   
2847
2903
}
 
2904
                                                                        /*}}}*/