From 459b5f5dcc2fcdd754b8f273a6e40d6ac4e48659 Mon Sep 17 00:00:00 2001 From: Michael Vogt Date: Mon, 15 Nov 2010 15:49:30 +0100 Subject: cmdline/apt-get.cc: add download commandlien option --- cmdline/apt-get.cc | 46 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) (limited to 'cmdline') diff --git a/cmdline/apt-get.cc b/cmdline/apt-get.cc index 8efcd0e2e..3fab4b17e 100644 --- a/cmdline/apt-get.cc +++ b/cmdline/apt-get.cc @@ -2733,6 +2733,51 @@ bool DoBuildDep(CommandLine &CmdL) return true; } /*}}}*/ +// 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; + + 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()); + // down + new pkgAcqFile(&Fetcher, uri, "", 0, descr, Pkg.Name(), "."); + int res = Fetcher.Run(); + } + + return true; +} + /*}}}*/ // DoMoo - Never Ask, Never Tell /*{{{*/ // --------------------------------------------------------------------- /* */ @@ -2923,6 +2968,7 @@ int main(int argc,const char *argv[]) /*{{{*/ {"autoclean",&DoAutoClean}, {"check",&DoCheck}, {"source",&DoSource}, + {"download",&DoDownload}, {"moo",&DoMoo}, {"help",&ShowHelp}, {0,0}}; -- cgit v1.2.3 From c9f3e0cdacbe24abccb2bbc0eab6c6b1a15d3bd9 Mon Sep 17 00:00:00 2001 From: Michael Vogt Date: Mon, 15 Nov 2010 16:33:17 +0100 Subject: cmdline/apt-get.cc: add hash to the downloader --- cmdline/apt-get.cc | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) (limited to 'cmdline') diff --git a/cmdline/apt-get.cc b/cmdline/apt-get.cc index 3fab4b17e..4e96bc67d 100644 --- a/cmdline/apt-get.cc +++ b/cmdline/apt-get.cc @@ -2751,6 +2751,7 @@ bool DoDownload(CommandLine &CmdL) if (verset.empty() == true) return false; + bool result = true; pkgRecords Recs(Cache); pkgSourceList *SrcList = Cache.GetSourceList(); for (APT::VersionSet::const_iterator Ver = verset.begin(); @@ -2770,12 +2771,20 @@ bool DoDownload(CommandLine &CmdL) return _error->Error("FindIndex failed"); string uri = index->ArchiveURI(rec.FileName()); strprintf(descr, _("Downloading %s %s"), Pkg.Name(), Ver.VerStr()); - // down - new pkgAcqFile(&Fetcher, uri, "", 0, descr, Pkg.Name(), "."); - int res = Fetcher.Run(); - } - - return true; + // 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(), 0, descr, Pkg.Name(), "."); + result &= (Fetcher.Run() == pkgAcquire::Continue); + } + + return result; } /*}}}*/ // DoMoo - Never Ask, Never Tell /*{{{*/ -- cgit v1.2.3 From 7f7aa6eb3227e69b34b1b38e3c5d5b15746c395f Mon Sep 17 00:00:00 2001 From: Michael Vogt Date: Mon, 15 Nov 2010 16:38:07 +0100 Subject: cmdline/apt-get.cc: and add size as well --- cmdline/apt-get.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'cmdline') diff --git a/cmdline/apt-get.cc b/cmdline/apt-get.cc index 4e96bc67d..febcab18c 100644 --- a/cmdline/apt-get.cc +++ b/cmdline/apt-get.cc @@ -2780,7 +2780,7 @@ bool DoDownload(CommandLine &CmdL) else if (rec.MD5Hash() != "") hash = HashString("md5", rec.MD5Hash()); // get the file - new pkgAcqFile(&Fetcher, uri, hash.toStr(), 0, descr, Pkg.Name(), "."); + new pkgAcqFile(&Fetcher, uri, hash.toStr(), (*Ver)->Size, descr, Pkg.Name(), "."); result &= (Fetcher.Run() == pkgAcquire::Continue); } -- cgit v1.2.3