summaryrefslogtreecommitdiff
path: root/cmdline
diff options
context:
space:
mode:
Diffstat (limited to 'cmdline')
-rw-r--r--cmdline/acqprogress.cc12
-rw-r--r--cmdline/apt-get.cc55
2 files changed, 67 insertions, 0 deletions
diff --git a/cmdline/acqprogress.cc b/cmdline/acqprogress.cc
index 32e8243bf..ba334ce05 100644
--- a/cmdline/acqprogress.cc
+++ b/cmdline/acqprogress.cc
@@ -11,6 +11,7 @@
#include "acqprogress.h"
#include <apt-pkg/acquire-item.h>
#include <apt-pkg/acquire-worker.h>
+#include <apt-pkg/configuration.h>
#include <apt-pkg/strutl.h>
#include <apt-pkg/error.h>
@@ -19,6 +20,7 @@
#include <stdio.h>
#include <signal.h>
#include <iostream>
+#include <unistd.h>
/*}}}*/
using namespace std;
@@ -266,6 +268,16 @@ bool AcqTextStatus::Pulse(pkgAcquire *Owner)
/* Prompt for a media swap */
bool AcqTextStatus::MediaChange(string Media,string Drive)
{
+ // If we do not output on a terminal and one of the options to avoid user
+ // interaction is given, we assume that no user is present who could react
+ // on your media change request
+ if (isatty(STDOUT_FILENO) != 1 && Quiet >= 2 &&
+ (_config->FindB("APT::Get::Assume-Yes",false) == true ||
+ _config->FindB("APT::Get::Force-Yes",false) == true ||
+ _config->FindB("APT::Get::Trivial-Only",false) == true))
+
+ return false;
+
if (Quiet <= 0)
cout << '\r' << BlankLine << '\r';
ioprintf(cout,_("Media change: please insert the disc labeled\n"
diff --git a/cmdline/apt-get.cc b/cmdline/apt-get.cc
index a1987b977..0c7100283 100644
--- a/cmdline/apt-get.cc
+++ b/cmdline/apt-get.cc
@@ -2165,6 +2165,60 @@ bool DoAutoClean(CommandLine &CmdL)
Cleaner.Go(_config->FindDir("Dir::Cache::archives") + "partial/",*Cache);
}
/*}}}*/
+// DoDownload - download a binary /*{{{*/
+// ---------------------------------------------------------------------
+bool DoDownload(CommandLine &CmdL)
+{
+ CacheFile Cache;
+ if (Cache.ReadOnlyOpen() == false)
+ return false;
+
+ APT::CacheSetHelper helper(c0out);
+ APT::VersionSet verset = APT::VersionSet::FromCommandLine(Cache,
+ CmdL.FileList + 1, APT::VersionSet::CANDIDATE, helper);
+ pkgAcquire Fetcher;
+ AcqTextStatus Stat(ScreenWidth, _config->FindI("quiet",0));
+ Fetcher.Setup(&Stat);
+
+ if (verset.empty() == true)
+ return false;
+
+ bool result = true;
+ pkgRecords Recs(Cache);
+ pkgSourceList *SrcList = Cache.GetSourceList();
+ for (APT::VersionSet::const_iterator Ver = verset.begin();
+ Ver != verset.end();
+ ++Ver)
+ {
+ string descr;
+ // get the right version
+ pkgCache::PkgIterator Pkg = Ver.ParentPkg();
+ pkgRecords::Parser &rec=Recs.Lookup(Ver.FileList());
+ pkgCache::VerFileIterator Vf = Ver.FileList();
+ if (Vf.end() == true)
+ return _error->Error("Can not find VerFile");
+ pkgCache::PkgFileIterator F = Vf.File();
+ pkgIndexFile *index;
+ if(SrcList->FindIndex(F, index) == false)
+ return _error->Error("FindIndex failed");
+ string uri = index->ArchiveURI(rec.FileName());
+ strprintf(descr, _("Downloading %s %s"), Pkg.Name(), Ver.VerStr());
+ // get the most appropriate hash
+ HashString hash;
+ if (rec.SHA256Hash() != "")
+ hash = HashString("sha256", rec.SHA256Hash());
+ else if (rec.SHA1Hash() != "")
+ hash = HashString("sha1", rec.SHA1Hash());
+ else if (rec.MD5Hash() != "")
+ hash = HashString("md5", rec.MD5Hash());
+ // get the file
+ new pkgAcqFile(&Fetcher, uri, hash.toStr(), (*Ver)->Size, descr, Pkg.Name(), ".");
+ result &= (Fetcher.Run() == pkgAcquire::Continue);
+ }
+
+ return result;
+}
+ /*}}}*/
// DoCheck - Perform the check operation /*{{{*/
// ---------------------------------------------------------------------
/* Opening automatically checks the system, this command is mostly used
@@ -3085,6 +3139,7 @@ int main(int argc,const char *argv[]) /*{{{*/
{"autoclean",&DoAutoClean},
{"check",&DoCheck},
{"source",&DoSource},
+ {"download",&DoDownload},
{"changelog",&DoChangelog},
{"moo",&DoMoo},
{"help",&ShowHelp},