// -*- mode: cpp; mode: fold -*-
// Description /*{{{*/
-// $Id: apt-get.cc,v 1.39 1999/02/07 08:40:34 jgg Exp $
+// $Id: apt-get.cc,v 1.47 1999/03/27 03:02:39 jgg Exp $
/* ######################################################################
apt-get - Cover for dpkg
#include <termios.h>
#include <sys/ioctl.h>
#include <sys/stat.h>
+#include <sys/vfs.h>
#include <signal.h>
+#include <unistd.h>
#include <stdio.h>
/*}}}*/
return true;
}
/*}}}*/
+// AnalPrompt - Annoying Yes No Prompt. /*{{{*/
+// ---------------------------------------------------------------------
+/* Returns true on a Yes.*/
+bool AnalPrompt(const char *Text)
+{
+ char Buf[1024];
+ cin.getline(Buf,sizeof(Buf));
+ if (strcmp(Buf,Text) == 0)
+ return true;
+ return false;
+}
+ /*}}}*/
// ShowList - Show a list /*{{{*/
// ---------------------------------------------------------------------
/* This prints out a string of space seperated words with a title and
// ---------------------------------------------------------------------
/* This displays the informative messages describing what is going to
happen and then calls the download routines */
-bool InstallPackages(CacheFile &Cache,bool ShwKept,bool Ask = true)
+bool InstallPackages(CacheFile &Cache,bool ShwKept,bool Ask = true,bool Saftey = true)
{
bool Fail = false;
+ bool Essential = false;
// Show all the various warning indicators
ShowDel(c1out,Cache);
Fail |= !ShowHold(c1out,Cache);
if (_config->FindB("APT::Get::Show-Upgraded",false) == true)
ShowUpgraded(c1out,Cache);
- Fail |= !ShowEssential(c1out,Cache);
+ Essential = !ShowEssential(c1out,Cache);
+ Fail |= Essential;
Stats(c1out,Cache);
// Sanity check
// Create the package manager and prepare to download
pkgDPkgPM PM(Cache);
- if (PM.GetArchives(&Fetcher,&List,&Recs) == false)
+ if (PM.GetArchives(&Fetcher,&List,&Recs) == false ||
+ _error->PendingError() == true)
return false;
// Display statistics
unsigned long FetchBytes = Fetcher.FetchNeeded();
+ unsigned long FetchPBytes = Fetcher.PartialPresent();
unsigned long DebBytes = Fetcher.TotalNeeded();
if (DebBytes != Cache->DebSize())
{
c0out << DebBytes << ',' << Cache->DebSize() << endl;
c0out << "How odd.. The sizes didn't match, email apt@packages.debian.org" << endl;
}
-
+
+ // Check for enough free space
+ struct statfs Buf;
+ string OutputDir = _config->FindDir("Dir::Cache::Archives");
+ if (statfs(OutputDir.c_str(),&Buf) != 0)
+ return _error->Errno("statfs","Couldn't determine free space in %s",
+ OutputDir.c_str());
+ if (unsigned(Buf.f_bfree) < (FetchBytes - FetchPBytes)/Buf.f_bsize)
+ return _error->Error("Sorry, you don't have enough free space in %s",
+ OutputDir.c_str());
+
// Number of bytes
- c2out << "Need to get ";
+ c1out << "Need to get ";
if (DebBytes != FetchBytes)
- c2out << SizeToStr(FetchBytes) << "b/" << SizeToStr(DebBytes) << 'b';
+ c1out << SizeToStr(FetchBytes) << "b/" << SizeToStr(DebBytes) << 'b';
else
- c2out << SizeToStr(DebBytes) << 'b';
+ c1out << SizeToStr(DebBytes) << 'b';
c1out << " of archives. After unpacking ";
// Size delta
if (Cache->UsrSize() >= 0)
- c2out << SizeToStr(Cache->UsrSize()) << "b will be used." << endl;
+ c1out << SizeToStr(Cache->UsrSize()) << "b will be used." << endl;
else
- c2out << SizeToStr(-1*Cache->UsrSize()) << "b will be freed." << endl;
+ c1out << SizeToStr(-1*Cache->UsrSize()) << "b will be freed." << endl;
if (_error->PendingError() == true)
return false;
// Fail safe check
- if (_config->FindB("APT::Get::Assume-Yes",false) == true)
+ if (_config->FindI("quiet",0) >= 2 ||
+ _config->FindB("APT::Get::Assume-Yes",false) == true)
{
if (Fail == true && _config->FindB("APT::Get::Force-Yes",false) == false)
return _error->Error("There are problems and -y was used without --force-yes");
}
-
- // Prompt to continue
- if (Ask == true)
- {
- if (_config->FindI("quiet",0) < 2 ||
- _config->FindB("APT::Get::Assume-Yes",false) == false)
- c2out << "Do you want to continue? [Y/n] " << flush;
- if (YnPrompt() == false)
+ if (Essential == true && Saftey == true)
+ {
+ c2out << "You are about to do something potentially harmful" << endl;
+ c2out << "To continue type in the phrase 'Yes, I understand this is bad'" << endl;
+ c2out << " ?] " << flush;
+ if (AnalPrompt("Yes, I understand this is bad") == false)
+ {
+ c2out << "Abort." << endl;
exit(1);
- }
-
+ }
+ }
+ else
+ {
+ // Prompt to continue
+ if (Ask == true)
+ {
+ if (_config->FindI("quiet",0) < 2 &&
+ _config->FindB("APT::Get::Assume-Yes",false) == false)
+ {
+ c2out << "Do you want to continue? [Y/n] " << flush;
+
+ if (YnPrompt() == false)
+ {
+ c2out << "Abort." << endl;
+ exit(1);
+ }
+ }
+ }
+ }
+
if (_config->FindB("APT::Get::Print-URIs") == true)
{
pkgAcquire::UriIterator I = Fetcher.UriBegin();
// ---------------------------------------------------------------------
/* This is similar to clean but it only purges things that cannot be
downloaded, that is old versions of cached packages. */
+class LogCleaner : public pkgArchiveCleaner
+{
+ protected:
+ virtual void Erase(const char *File,string Pkg,string Ver,struct stat &St)
+ {
+ cout << "Del " << Pkg << " " << Ver << " [" << SizeToStr(St.st_size) << "b]" << endl;
+ };
+};
+
bool DoAutoClean(CommandLine &CmdL)
{
CacheFile Cache;
if (Cache.Open(true) == false)
return false;
- class LogCleaner : public pkgArchiveCleaner
- {
- protected:
- virtual void Erase(const char *File,string Pkg,string Ver,struct stat &St)
- {
- cout << "Del " << Pkg << " " << Ver << " [" << SizeToStr(St.st_size) << "b]" << endl;
- };
- } Cleaner;
+ LogCleaner Cleaner;
return Cleaner.Go(_config->FindDir("Dir::Cache::archives"),*Cache) &&
Cleaner.Go(_config->FindDir("Dir::Cache::archives") + "partial/",*Cache);
CmdL.FileSize() == 0)
return ShowHelp(CmdL);
+ // Deal with stdout not being a tty
+ if (ttyname(STDOUT_FILENO) == 0 && _config->FindI("quiet",0) < 1)
+ _config->Set("quiet","1");
+
// Setup the output streams
c0out.rdbuf(cout.rdbuf());
c1out.rdbuf(cout.rdbuf());