]> git.saurik.com Git - apt.git/commitdiff
merged from apt-get-changelog
authorMichael Vogt <michael.vogt@ubuntu.com>
Thu, 18 Nov 2010 13:13:39 +0000 (14:13 +0100)
committerMichael Vogt <michael.vogt@ubuntu.com>
Thu, 18 Nov 2010 13:13:39 +0000 (14:13 +0100)
1  2 
cmdline/apt-get.cc

diff --combined cmdline/apt-get.cc
index 6d1ab03c2fa578bcaf51c32c00ce907aa22337b0,0879cf7c6c6b8185efc30491688a9afc2e4db3c8..eb3ac425b052d01120b30a8a6823fca64c1392c6
@@@ -2165,60 -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
@@@ -2805,10 -2751,12 +2805,12 @@@ string GetChangelogPath(CacheFile &Cach
     pkgRecords Recs(Cache);
     pkgRecords::Parser &rec=Recs.Lookup(Ver.FileList());
     string srcpkg = rec.SourcePkg().empty() ? Pkg.Name() : rec.SourcePkg();
-    // FIXME: deal with cases like gcc-defaults (srcver != binver)
-    string srcver = StripEpoch(Ver.VerStr());
+    string ver = Ver.VerStr();
+    // if there is a source version it always wins
+    if (rec.SourceVer() != "")
+       ver = rec.SourceVer();
     path = flNotFile(rec.FileName());
-    path += srcpkg + "_" + srcver;
+    path += srcpkg + "_" + StripEpoch(ver);
     return path;
  }
                                                                        /*}}}*/
@@@ -2854,7 -2802,6 +2856,6 @@@ bool DownloadChangelog(CacheFile &Cache
   * GuessThirdPartyChangelogUri for details how)
   */
  {
-    string srcpkg;
     string path;
     string descr;
     string server;
                            "http://packages.debian.org/changelogs");
     path = GetChangelogPath(CacheFile, Pkg, Ver);
     strprintf(changelog_uri, "%s/%s/changelog", server.c_str(), path.c_str());
-    strprintf(descr, _("Changelog for %s (%s)"), srcpkg.c_str(), changelog_uri.c_str());
+    strprintf(descr, _("Changelog for %s (%s)"), Pkg.Name(), changelog_uri.c_str());
     // queue it
-    new pkgAcqFile(&Fetcher, changelog_uri, "", 0, descr, srcpkg, "ignored", targetfile);
+    new pkgAcqFile(&Fetcher, changelog_uri, "", 0, descr, Pkg.Name(), "ignored", targetfile);
  
     // try downloading it, if that fails, they third-party-changelogs location
     // FIXME: res is "Continue" even if I get a 404?!?
        string third_party_uri;
        if (GuessThirdPartyChangelogUri(CacheFile, Pkg, Ver, third_party_uri))
        {
-          strprintf(descr, _("Changelog for %s (%s)"), srcpkg.c_str(), third_party_uri.c_str());
-          new pkgAcqFile(&Fetcher, third_party_uri, "", 0, descr, srcpkg, "ignored", targetfile);
+          strprintf(descr, _("Changelog for %s (%s)"), Pkg.Name(), third_party_uri.c_str());
+          new pkgAcqFile(&Fetcher, third_party_uri, "", 0, descr, Pkg.Name(), "ignored", targetfile);
           res = Fetcher.Run();
        }
     }
@@@ -3041,8 -2988,6 +3042,8 @@@ bool ShowHelp(CommandLine &CmdL
        "   check - Verify that there are no broken dependencies\n"
        "   markauto - Mark the given packages as automatically installed\n"
        "   unmarkauto - Mark the given packages as manually installed\n"
 +      "   changelog - Download and display the changelog for the given package\n"
 +      "   download - Download the binary package into the current directory\n"
        "\n"
        "Options:\n"
        "  -h  This help text.\n"
@@@ -3141,7 -3086,6 +3142,7 @@@ int main(int argc,const char *argv[]
                                     {"autoclean",&DoAutoClean},
                                     {"check",&DoCheck},
                                   {"source",&DoSource},
 +                                   {"download",&DoDownload},
                                     {"changelog",&DoChangelog},
                                   {"moo",&DoMoo},
                                   {"help",&ShowHelp},