From a4c404301df135bea81f23b944dc6e1967f9ca85 Mon Sep 17 00:00:00 2001 From: Michael Vogt Date: Mon, 15 Nov 2010 12:12:56 +0100 Subject: initial apt-get changelog implementation, not quite ready yet (need to get rid of tmpnam --- cmdline/apt-get.cc | 99 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 99 insertions(+) (limited to 'cmdline') diff --git a/cmdline/apt-get.cc b/cmdline/apt-get.cc index 8efcd0e2e..72c1ef0b0 100644 --- a/cmdline/apt-get.cc +++ b/cmdline/apt-get.cc @@ -2733,6 +2733,104 @@ bool DoBuildDep(CommandLine &CmdL) return true; } /*}}}*/ +// DownloadChangelog - Download the changelog /*{{{*/ +// --------------------------------------------------------------------- +string DownloadChangelog(CacheFile &CacheFile, pkgAcquire &Fetcher, pkgCache::VerIterator V) +{ + string uri; + string srcpkg; + string prefix; + string descr; + string src_section; + string verstr; + + // data structures we need + pkgRecords Recs(CacheFile); + pkgCache::PkgIterator Pkg = V.ParentPkg(); + pkgRecords::Parser &rec=Recs.Lookup(V.FileList()); + + // build uri + srcpkg = rec.SourcePkg().empty() ? Pkg.Name() : rec.SourcePkg(); + strprintf(descr, _("Changelog for %s"), srcpkg.c_str()); + // FIXME: we actually need the source section here + src_section= Pkg.Section(); + if(src_section.find('/')!=src_section.npos) + src_section=string(src_section, 0, src_section.find('/')); + else + src_section="main"; + + prefix+=srcpkg[0]; + if(srcpkg.size()>3 && srcpkg[0]=='l' && srcpkg[1]=='i' && srcpkg[2]=='b') + prefix=std::string("lib")+srcpkg[3]; + + verstr = V.VerStr(); + if(verstr.find(':')!=verstr.npos) + verstr=string(verstr, verstr.find(':')+1); + + strprintf(uri, "http://packages.debian.org/changelogs/pool/%s/%s/%s/%s_%s/changelog", src_section.c_str(), prefix.c_str(), srcpkg.c_str(), srcpkg.c_str(), verstr.c_str()); + + AcqTextStatus Stat(ScreenWidth, _config->FindI("quiet",0)); + Fetcher.Setup(&Stat); + + // temp file + string targetfile = tmpnam(strdup("apt-changelog-XXXXXX")); + new pkgAcqFile(&Fetcher, uri, "", 0, descr, srcpkg, "ignore", targetfile); + + // get it + int res = Fetcher.Run(); + if (FileExists(targetfile)) + return targetfile; + + // error + return ""; +} + /*}}}*/ +// DisplayFileInPager - Display File with pager /*{{{*/ +void DisplayFileInPager(string filename) +{ + pid_t Process = ExecFork(); + if (Process == 0) + { + const char *Args[3]; + Args[0] = "/usr/bin/sensible-pager"; + Args[1] = filename.c_str(); + Args[2] = 0; + execvp(Args[0],(char **)Args); + exit(100); + } + + // Wait for the subprocess + ExecWait(Process, "sensible-pager", false); +} + /*}}}*/ +// DoChangelog - Get changelog from the command line /*{{{*/ +// --------------------------------------------------------------------- +bool DoChangelog(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; + + if (verset.empty() == true) + return false; + for (APT::VersionSet::const_iterator Ver = verset.begin(); + Ver != verset.end(); + ++Ver) + { + string changelogfile = DownloadChangelog(Cache, Fetcher, Ver); + if (changelogfile.size() > 0) + { + DisplayFileInPager(changelogfile); + unlink(changelogfile.c_str()); + } + } +} + /*}}}*/ // DoMoo - Never Ask, Never Tell /*{{{*/ // --------------------------------------------------------------------- /* */ @@ -2923,6 +3021,7 @@ int main(int argc,const char *argv[]) /*{{{*/ {"autoclean",&DoAutoClean}, {"check",&DoCheck}, {"source",&DoSource}, + {"changelog",&DoChangelog}, {"moo",&DoMoo}, {"help",&ShowHelp}, {0,0}}; -- cgit v1.2.3 From 4a6fe09cf2a7f18de2f80a1b79ea43e211302dbc Mon Sep 17 00:00:00 2001 From: Michael Vogt Date: Mon, 15 Nov 2010 12:26:39 +0100 Subject: use mkdtemp() instead of tempnam, free mkdtemp() data afterwards, return true in DoChangelog handler --- cmdline/apt-get.cc | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) (limited to 'cmdline') diff --git a/cmdline/apt-get.cc b/cmdline/apt-get.cc index 72c1ef0b0..0d67585a7 100644 --- a/cmdline/apt-get.cc +++ b/cmdline/apt-get.cc @@ -2773,11 +2773,18 @@ string DownloadChangelog(CacheFile &CacheFile, pkgAcquire &Fetcher, pkgCache::Ve Fetcher.Setup(&Stat); // temp file - string targetfile = tmpnam(strdup("apt-changelog-XXXXXX")); - new pkgAcqFile(&Fetcher, uri, "", 0, descr, srcpkg, "ignore", targetfile); + char *tmpdir = mkdtemp(strdup("apt-changelog-XXXXXX")); + if (tmpdir == NULL) { + _error->Errno("mkdtemp", "mkdtemp failed"); + return ""; + } + string targetfile = string(tmpdir) + "changelog"; // get it + new pkgAcqFile(&Fetcher, uri, "", 0, descr, srcpkg, tmpdir); int res = Fetcher.Run(); + free(tmpdir); + if (FileExists(targetfile)) return targetfile; @@ -2826,9 +2833,12 @@ bool DoChangelog(CommandLine &CmdL) if (changelogfile.size() > 0) { DisplayFileInPager(changelogfile); + // cleanup unlink(changelogfile.c_str()); + rmdir(flNotFile(changelogfile).c_str()); } } + return true; } /*}}}*/ // DoMoo - Never Ask, Never Tell /*{{{*/ -- cgit v1.2.3 From 18ae8b296bf08b853c44fdd5c20689e45ae71bfc Mon Sep 17 00:00:00 2001 From: Michael Vogt Date: Mon, 15 Nov 2010 12:53:52 +0100 Subject: support Apt::Changelog::Server, code cleanup --- cmdline/apt-get.cc | 40 +++++++++++++++++++--------------------- 1 file changed, 19 insertions(+), 21 deletions(-) (limited to 'cmdline') diff --git a/cmdline/apt-get.cc b/cmdline/apt-get.cc index 0d67585a7..a61bcc62b 100644 --- a/cmdline/apt-get.cc +++ b/cmdline/apt-get.cc @@ -2735,7 +2735,7 @@ bool DoBuildDep(CommandLine &CmdL) /*}}}*/ // DownloadChangelog - Download the changelog /*{{{*/ // --------------------------------------------------------------------- -string DownloadChangelog(CacheFile &CacheFile, pkgAcquire &Fetcher, pkgCache::VerIterator V) +bool DownloadChangelog(CacheFile &CacheFile, pkgAcquire &Fetcher, pkgCache::VerIterator V, string targetfile) { string uri; string srcpkg; @@ -2767,29 +2767,22 @@ string DownloadChangelog(CacheFile &CacheFile, pkgAcquire &Fetcher, pkgCache::Ve if(verstr.find(':')!=verstr.npos) verstr=string(verstr, verstr.find(':')+1); - strprintf(uri, "http://packages.debian.org/changelogs/pool/%s/%s/%s/%s_%s/changelog", src_section.c_str(), prefix.c_str(), srcpkg.c_str(), srcpkg.c_str(), verstr.c_str()); + string fmt = _config->Find("Apt::Changelogs::Server", + "http://packages.debian.org/changelogs/pool/%s/%s/%s/%s_%s/changelog"); + strprintf(uri, fmt.c_str(), src_section.c_str(), prefix.c_str(), srcpkg.c_str(), srcpkg.c_str(), verstr.c_str()); AcqTextStatus Stat(ScreenWidth, _config->FindI("quiet",0)); Fetcher.Setup(&Stat); - // temp file - char *tmpdir = mkdtemp(strdup("apt-changelog-XXXXXX")); - if (tmpdir == NULL) { - _error->Errno("mkdtemp", "mkdtemp failed"); - return ""; - } - string targetfile = string(tmpdir) + "changelog"; - // get it - new pkgAcqFile(&Fetcher, uri, "", 0, descr, srcpkg, tmpdir); + new pkgAcqFile(&Fetcher, uri, "", 0, descr, srcpkg, "ignored", targetfile); int res = Fetcher.Run(); - free(tmpdir); if (FileExists(targetfile)) - return targetfile; + return true; // error - return ""; + return _error->Error("changelog download failed"); } /*}}}*/ // DisplayFileInPager - Display File with pager /*{{{*/ @@ -2825,19 +2818,24 @@ bool DoChangelog(CommandLine &CmdL) if (verset.empty() == true) return false; + char *tmpdir = mkdtemp(strdup("apt-changelog-XXXXXX")); + if (tmpdir == NULL) { + return _error->Errno("mkdtemp", "mkdtemp failed"); + } + for (APT::VersionSet::const_iterator Ver = verset.begin(); Ver != verset.end(); ++Ver) { - string changelogfile = DownloadChangelog(Cache, Fetcher, Ver); - if (changelogfile.size() > 0) - { + string changelogfile = string(tmpdir) + "changelog"; + if (DownloadChangelog(Cache, Fetcher, Ver, changelogfile)) DisplayFileInPager(changelogfile); - // cleanup - unlink(changelogfile.c_str()); - rmdir(flNotFile(changelogfile).c_str()); - } + // cleanup temp file + unlink(changelogfile.c_str()); } + // clenaup tmp dir + rmdir(tmpdir); + free(tmpdir); return true; } /*}}}*/ -- cgit v1.2.3 From c2991635eb1d2a6bc8a0910b4f84748415a3ac14 Mon Sep 17 00:00:00 2001 From: Michael Vogt Date: Mon, 15 Nov 2010 13:28:22 +0100 Subject: cmdline/apt-get.cc make only the server configurable, but not the format string (attack vector?) --- cmdline/apt-get.cc | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) (limited to 'cmdline') diff --git a/cmdline/apt-get.cc b/cmdline/apt-get.cc index a61bcc62b..a5e3ad454 100644 --- a/cmdline/apt-get.cc +++ b/cmdline/apt-get.cc @@ -2737,12 +2737,13 @@ bool DoBuildDep(CommandLine &CmdL) // --------------------------------------------------------------------- bool DownloadChangelog(CacheFile &CacheFile, pkgAcquire &Fetcher, pkgCache::VerIterator V, string targetfile) { - string uri; string srcpkg; string prefix; string descr; string src_section; string verstr; + string server; + string path; // data structures we need pkgRecords Recs(CacheFile); @@ -2767,15 +2768,16 @@ bool DownloadChangelog(CacheFile &CacheFile, pkgAcquire &Fetcher, pkgCache::VerI if(verstr.find(':')!=verstr.npos) verstr=string(verstr, verstr.find(':')+1); - string fmt = _config->Find("Apt::Changelogs::Server", - "http://packages.debian.org/changelogs/pool/%s/%s/%s/%s_%s/changelog"); - strprintf(uri, fmt.c_str(), src_section.c_str(), prefix.c_str(), srcpkg.c_str(), srcpkg.c_str(), verstr.c_str()); - + // make the server configurable + server = _config->Find("Apt::Changelogs::Server", + "http://packages.debian.org/"); + // ... but not the format string to avoid all possible attacks + strprintf(path, "/changelogs/pool/%s/%s/%s/%s_%s/changelog", src_section.c_str(), prefix.c_str(), srcpkg.c_str(), srcpkg.c_str(), verstr.c_str()); AcqTextStatus Stat(ScreenWidth, _config->FindI("quiet",0)); Fetcher.Setup(&Stat); // get it - new pkgAcqFile(&Fetcher, uri, "", 0, descr, srcpkg, "ignored", targetfile); + new pkgAcqFile(&Fetcher, server+path, "", 0, descr, srcpkg, "ignored", targetfile); int res = Fetcher.Run(); if (FileExists(targetfile)) -- cgit v1.2.3 From 8cc74fb1f791935bea9afd767fddf78ecebd4740 Mon Sep 17 00:00:00 2001 From: Michael Vogt Date: Mon, 15 Nov 2010 13:34:36 +0100 Subject: cmdline/apt-get.cc: move Setup a level higher --- cmdline/apt-get.cc | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) (limited to 'cmdline') diff --git a/cmdline/apt-get.cc b/cmdline/apt-get.cc index a5e3ad454..cf4f1ab36 100644 --- a/cmdline/apt-get.cc +++ b/cmdline/apt-get.cc @@ -2773,9 +2773,6 @@ bool DownloadChangelog(CacheFile &CacheFile, pkgAcquire &Fetcher, pkgCache::VerI "http://packages.debian.org/"); // ... but not the format string to avoid all possible attacks strprintf(path, "/changelogs/pool/%s/%s/%s/%s_%s/changelog", src_section.c_str(), prefix.c_str(), srcpkg.c_str(), srcpkg.c_str(), verstr.c_str()); - AcqTextStatus Stat(ScreenWidth, _config->FindI("quiet",0)); - Fetcher.Setup(&Stat); - // get it new pkgAcqFile(&Fetcher, server+path, "", 0, descr, srcpkg, "ignored", targetfile); int res = Fetcher.Run(); @@ -2817,6 +2814,8 @@ bool DoChangelog(CommandLine &CmdL) 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; -- cgit v1.2.3 From 64b4c03ee79d5df053df7dabd33e88e0ebef1f20 Mon Sep 17 00:00:00 2001 From: Michael Vogt Date: Mon, 15 Nov 2010 13:54:47 +0100 Subject: cmdline/apt-get.cc: create the mkdtemp dir in /tmp --- 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 cf4f1ab36..53def383d 100644 --- a/cmdline/apt-get.cc +++ b/cmdline/apt-get.cc @@ -2819,7 +2819,7 @@ bool DoChangelog(CommandLine &CmdL) if (verset.empty() == true) return false; - char *tmpdir = mkdtemp(strdup("apt-changelog-XXXXXX")); + char *tmpdir = mkdtemp(strdup("/tmp/apt-changelog-XXXXXX")); if (tmpdir == NULL) { return _error->Errno("mkdtemp", "mkdtemp failed"); } -- cgit v1.2.3 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 From cdb9307c701fd016325c83dc879351912fb35c9d Mon Sep 17 00:00:00 2001 From: Michael Vogt Date: Tue, 16 Nov 2010 10:35:10 +0100 Subject: add support for third party changelogs --- cmdline/apt-get.cc | 42 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) (limited to 'cmdline') diff --git a/cmdline/apt-get.cc b/cmdline/apt-get.cc index 53def383d..35f37cc49 100644 --- a/cmdline/apt-get.cc +++ b/cmdline/apt-get.cc @@ -2733,6 +2733,37 @@ bool DoBuildDep(CommandLine &CmdL) return true; } /*}}}*/ +// GuessThirdPartyChangelogUri - return url /*{{{*/ +// --------------------------------------------------------------------- +bool GuessThirdPartyChangelogUri(CacheFile &Cache, + pkgCache::PkgIterator Pkg, + pkgCache::VerIterator Ver, + string &out_uri) +{ + pkgRecords Recs(Cache); + pkgSourceList *SrcList = Cache.GetSourceList(); + + // get the binary deb server path + 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()); + + pkgCache::VerFileIterator Vf = Ver.FileList(); + if (Vf.end() == true) + return false; + pkgCache::PkgFileIterator F = Vf.File(); + pkgIndexFile *index; + if(SrcList->FindIndex(F, index) == false) + return false; + // get archive uri for the binary deb + string deb_uri = index->ArchiveURI(rec.FileName()); + + // now strip away the filename and add srcpkg_srcver.changelog + out_uri = flNotFile(deb_uri); + out_uri += srcpkg + "_" + srcver + ".changelog"; + return true; +} // DownloadChangelog - Download the changelog /*{{{*/ // --------------------------------------------------------------------- bool DownloadChangelog(CacheFile &CacheFile, pkgAcquire &Fetcher, pkgCache::VerIterator V, string targetfile) @@ -2775,7 +2806,18 @@ bool DownloadChangelog(CacheFile &CacheFile, pkgAcquire &Fetcher, pkgCache::VerI strprintf(path, "/changelogs/pool/%s/%s/%s/%s_%s/changelog", src_section.c_str(), prefix.c_str(), srcpkg.c_str(), srcpkg.c_str(), verstr.c_str()); // get it new pkgAcqFile(&Fetcher, server+path, "", 0, descr, srcpkg, "ignored", targetfile); + // try downloading it, if that fails, they third-party-changelogs location + // FIXME: res is "Continue" even if I get a 404?!? int res = Fetcher.Run(); + if (!FileExists(targetfile)) + { + string third_party_uri; + if (GuessThirdPartyChangelogUri(CacheFile, Pkg, V, third_party_uri)) + { + new pkgAcqFile(&Fetcher, third_party_uri, "", 0, descr, srcpkg, "ignored", targetfile); + res = Fetcher.Run(); + } + } if (FileExists(targetfile)) return true; -- cgit v1.2.3 From d786352da27c6f05bc372a061f3a78237b69e6f4 Mon Sep 17 00:00:00 2001 From: Michael Vogt Date: Tue, 16 Nov 2010 10:40:36 +0100 Subject: cmdline/apt-get.cc: improve changelog description --- cmdline/apt-get.cc | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) (limited to 'cmdline') diff --git a/cmdline/apt-get.cc b/cmdline/apt-get.cc index 35f37cc49..8cb43be67 100644 --- a/cmdline/apt-get.cc +++ b/cmdline/apt-get.cc @@ -2783,7 +2783,6 @@ bool DownloadChangelog(CacheFile &CacheFile, pkgAcquire &Fetcher, pkgCache::VerI // build uri srcpkg = rec.SourcePkg().empty() ? Pkg.Name() : rec.SourcePkg(); - strprintf(descr, _("Changelog for %s"), srcpkg.c_str()); // FIXME: we actually need the source section here src_section= Pkg.Section(); if(src_section.find('/')!=src_section.npos) @@ -2804,8 +2803,11 @@ bool DownloadChangelog(CacheFile &CacheFile, pkgAcquire &Fetcher, pkgCache::VerI "http://packages.debian.org/"); // ... but not the format string to avoid all possible attacks strprintf(path, "/changelogs/pool/%s/%s/%s/%s_%s/changelog", src_section.c_str(), prefix.c_str(), srcpkg.c_str(), srcpkg.c_str(), verstr.c_str()); - // get it - new pkgAcqFile(&Fetcher, server+path, "", 0, descr, srcpkg, "ignored", targetfile); + // queue it + string changelog_uri = server+path; + strprintf(descr, _("Changelog for %s (%s)"), srcpkg.c_str(), changelog_uri.c_str()); + new pkgAcqFile(&Fetcher, uri, "", 0, descr, srcpkg, "ignored", targetfile); + // try downloading it, if that fails, they third-party-changelogs location // FIXME: res is "Continue" even if I get a 404?!? int res = Fetcher.Run(); @@ -2814,6 +2816,7 @@ bool DownloadChangelog(CacheFile &CacheFile, pkgAcquire &Fetcher, pkgCache::VerI string third_party_uri; if (GuessThirdPartyChangelogUri(CacheFile, Pkg, V, 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); res = Fetcher.Run(); } -- cgit v1.2.3 From 0e3e112e3d60647e335aee7e6ce308b29fd11988 Mon Sep 17 00:00:00 2001 From: Michael Vogt Date: Thu, 18 Nov 2010 10:31:49 +0100 Subject: move DoDownload up to workaround merge conflict with the changelog branch --- cmdline/apt-get.cc | 108 ++++++++++++++++++++++++++--------------------------- 1 file changed, 54 insertions(+), 54 deletions(-) (limited to 'cmdline') diff --git a/cmdline/apt-get.cc b/cmdline/apt-get.cc index febcab18c..116f4a07e 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 @@ -2733,60 +2787,6 @@ 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; - - 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; -} - /*}}}*/ // DoMoo - Never Ask, Never Tell /*{{{*/ // --------------------------------------------------------------------- /* */ -- cgit v1.2.3 From 413ba44c86dcc7421494ff6bba2e2289941b5ad7 Mon Sep 17 00:00:00 2001 From: Michael Vogt Date: Thu, 18 Nov 2010 10:47:34 +0100 Subject: cmdline/apt-get.cc: fix typo --- 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 8cb43be67..406adf644 100644 --- a/cmdline/apt-get.cc +++ b/cmdline/apt-get.cc @@ -2806,7 +2806,7 @@ bool DownloadChangelog(CacheFile &CacheFile, pkgAcquire &Fetcher, pkgCache::VerI // queue it string changelog_uri = server+path; strprintf(descr, _("Changelog for %s (%s)"), srcpkg.c_str(), changelog_uri.c_str()); - new pkgAcqFile(&Fetcher, uri, "", 0, descr, srcpkg, "ignored", targetfile); + new pkgAcqFile(&Fetcher, changelog_uri, "", 0, descr, srcpkg, "ignored", targetfile); // try downloading it, if that fails, they third-party-changelogs location // FIXME: res is "Continue" even if I get a 404?!? -- cgit v1.2.3 From 9b66180fe75c8414b84f422d1f278f4cec1c32b7 Mon Sep 17 00:00:00 2001 From: Michael Vogt Date: Thu, 18 Nov 2010 11:14:49 +0100 Subject: cmdline/apt-get.cc: simplify changelog uri generation --- cmdline/apt-get.cc | 21 ++++----------------- 1 file changed, 4 insertions(+), 17 deletions(-) (limited to 'cmdline') diff --git a/cmdline/apt-get.cc b/cmdline/apt-get.cc index 406adf644..01f850aa6 100644 --- a/cmdline/apt-get.cc +++ b/cmdline/apt-get.cc @@ -2771,7 +2771,6 @@ bool DownloadChangelog(CacheFile &CacheFile, pkgAcquire &Fetcher, pkgCache::VerI string srcpkg; string prefix; string descr; - string src_section; string verstr; string server; string path; @@ -2781,28 +2780,16 @@ bool DownloadChangelog(CacheFile &CacheFile, pkgAcquire &Fetcher, pkgCache::VerI pkgCache::PkgIterator Pkg = V.ParentPkg(); pkgRecords::Parser &rec=Recs.Lookup(V.FileList()); - // build uri + // we need the the source pkg, the source version and the pool prefix srcpkg = rec.SourcePkg().empty() ? Pkg.Name() : rec.SourcePkg(); - // FIXME: we actually need the source section here - src_section= Pkg.Section(); - if(src_section.find('/')!=src_section.npos) - src_section=string(src_section, 0, src_section.find('/')); - else - src_section="main"; - - prefix+=srcpkg[0]; - if(srcpkg.size()>3 && srcpkg[0]=='l' && srcpkg[1]=='i' && srcpkg[2]=='b') - prefix=std::string("lib")+srcpkg[3]; - - verstr = V.VerStr(); - if(verstr.find(':')!=verstr.npos) - verstr=string(verstr, verstr.find(':')+1); + verstr = StripEpoch(V.VerStr()); + prefix = flNotFile(rec.FileName()); // make the server configurable server = _config->Find("Apt::Changelogs::Server", "http://packages.debian.org/"); // ... but not the format string to avoid all possible attacks - strprintf(path, "/changelogs/pool/%s/%s/%s/%s_%s/changelog", src_section.c_str(), prefix.c_str(), srcpkg.c_str(), srcpkg.c_str(), verstr.c_str()); + strprintf(path, "/changelogs/%s/%s_%s/changelog", prefix.c_str(), srcpkg.c_str(), verstr.c_str()); // queue it string changelog_uri = server+path; strprintf(descr, _("Changelog for %s (%s)"), srcpkg.c_str(), changelog_uri.c_str()); -- cgit v1.2.3 From a53b07bbef4917884a8e4d7740b4d0786f029f5c Mon Sep 17 00:00:00 2001 From: Michael Vogt Date: Thu, 18 Nov 2010 11:47:49 +0100 Subject: refactor/simplify changelog fetching code --- cmdline/apt-get.cc | 83 ++++++++++++++++++++++++++++++++++-------------------- 1 file changed, 53 insertions(+), 30 deletions(-) (limited to 'cmdline') diff --git a/cmdline/apt-get.cc b/cmdline/apt-get.cc index 01f850aa6..a1987b977 100644 --- a/cmdline/apt-get.cc +++ b/cmdline/apt-get.cc @@ -2733,66 +2733,89 @@ bool DoBuildDep(CommandLine &CmdL) return true; } /*}}}*/ +// GetChangelogPath - return a path pointing to a changelog file or dir /*{{{*/ +// --------------------------------------------------------------------- +/* This returns a "path" string for the changelog url construction. + * Please note that its not complete, it either needs a "/changelog" + * appended (for the packages.debian.org/changelogs site) or a + * ".changelog" (for third party sites that store the changelog in the + * pool/ next to the deb itself) + * Example return: "pool/main/a/apt/apt_0.8.8ubuntu3" + */ +string GetChangelogPath(CacheFile &Cache, + pkgCache::PkgIterator Pkg, + pkgCache::VerIterator Ver) +{ + string path; + + 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()); + path = flNotFile(rec.FileName()); + path += srcpkg + "_" + srcver; + return path; +} + /*}}}*/ // GuessThirdPartyChangelogUri - return url /*{{{*/ // --------------------------------------------------------------------- +/* Contruct a changelog file path for third party sites that do not use + * packages.debian.org/changelogs + * This simply uses the ArchiveURI() of the source pkg and looks for + * a .changelog file there, Example for "mediabuntu": + * apt-get changelog mplayer-doc: + * http://packages.medibuntu.org/pool/non-free/m/mplayer/mplayer_1.0~rc4~try1.dsfg1-1ubuntu1+medibuntu1.changelog + */ bool GuessThirdPartyChangelogUri(CacheFile &Cache, pkgCache::PkgIterator Pkg, pkgCache::VerIterator Ver, string &out_uri) { - pkgRecords Recs(Cache); - pkgSourceList *SrcList = Cache.GetSourceList(); - // get the binary deb server path - 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()); - pkgCache::VerFileIterator Vf = Ver.FileList(); if (Vf.end() == true) return false; pkgCache::PkgFileIterator F = Vf.File(); pkgIndexFile *index; + pkgSourceList *SrcList = Cache.GetSourceList(); if(SrcList->FindIndex(F, index) == false) return false; + // get archive uri for the binary deb - string deb_uri = index->ArchiveURI(rec.FileName()); + string path_without_dot_changelog = GetChangelogPath(Cache, Pkg, Ver); + out_uri = index->ArchiveURI(path_without_dot_changelog + ".changelog"); // now strip away the filename and add srcpkg_srcver.changelog - out_uri = flNotFile(deb_uri); - out_uri += srcpkg + "_" + srcver + ".changelog"; return true; } // DownloadChangelog - Download the changelog /*{{{*/ // --------------------------------------------------------------------- -bool DownloadChangelog(CacheFile &CacheFile, pkgAcquire &Fetcher, pkgCache::VerIterator V, string targetfile) +bool DownloadChangelog(CacheFile &CacheFile, pkgAcquire &Fetcher, + pkgCache::VerIterator Ver, string targetfile) +/* Download a changelog file for the given package version to + * targetfile. This will first try the server from Apt::Changelogs::Server + * (http://packages.debian.org/changelogs by default) and if that gives + * a 404 tries to get it from the archive directly (see + * GuessThirdPartyChangelogUri for details how) + */ { string srcpkg; - string prefix; + string path; string descr; - string verstr; string server; - string path; + string changelog_uri; // data structures we need - pkgRecords Recs(CacheFile); - pkgCache::PkgIterator Pkg = V.ParentPkg(); - pkgRecords::Parser &rec=Recs.Lookup(V.FileList()); + pkgCache::PkgIterator Pkg = Ver.ParentPkg(); - // we need the the source pkg, the source version and the pool prefix - srcpkg = rec.SourcePkg().empty() ? Pkg.Name() : rec.SourcePkg(); - verstr = StripEpoch(V.VerStr()); - prefix = flNotFile(rec.FileName()); - - // make the server configurable + // make the server root configurable server = _config->Find("Apt::Changelogs::Server", - "http://packages.debian.org/"); - // ... but not the format string to avoid all possible attacks - strprintf(path, "/changelogs/%s/%s_%s/changelog", prefix.c_str(), srcpkg.c_str(), verstr.c_str()); - // queue it - string changelog_uri = server+path; + "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()); + // queue it new pkgAcqFile(&Fetcher, changelog_uri, "", 0, descr, srcpkg, "ignored", targetfile); // try downloading it, if that fails, they third-party-changelogs location @@ -2801,7 +2824,7 @@ bool DownloadChangelog(CacheFile &CacheFile, pkgAcquire &Fetcher, pkgCache::VerI if (!FileExists(targetfile)) { string third_party_uri; - if (GuessThirdPartyChangelogUri(CacheFile, Pkg, V, 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); -- cgit v1.2.3 From 5f967f2d48581436b8d0a49f6e8fa306088279d4 Mon Sep 17 00:00:00 2001 From: Michael Vogt Date: Thu, 18 Nov 2010 12:58:29 +0100 Subject: cmdline/apt-get.cc: add download/changelog to usage --- cmdline/apt-get.cc | 2 ++ 1 file changed, 2 insertions(+) (limited to 'cmdline') diff --git a/cmdline/apt-get.cc b/cmdline/apt-get.cc index 0c7100283..6d1ab03c2 100644 --- a/cmdline/apt-get.cc +++ b/cmdline/apt-get.cc @@ -3041,6 +3041,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" -- cgit v1.2.3 From c5d6a22cc65d4f5d0405c0a2a392c659e2959e3f Mon Sep 17 00:00:00 2001 From: Michael Vogt Date: Thu, 18 Nov 2010 14:10:50 +0100 Subject: cmdline/apt-get.cc: use source version instead of binary version --- cmdline/apt-get.cc | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) (limited to 'cmdline') diff --git a/cmdline/apt-get.cc b/cmdline/apt-get.cc index a1987b977..db9424985 100644 --- a/cmdline/apt-get.cc +++ b/cmdline/apt-get.cc @@ -2751,10 +2751,12 @@ string GetChangelogPath(CacheFile &Cache, 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; } /*}}}*/ -- cgit v1.2.3 From 88573174ba96c9b3948ee7cba8c6073b13a27c32 Mon Sep 17 00:00:00 2001 From: Michael Vogt Date: Thu, 18 Nov 2010 14:12:57 +0100 Subject: cmdline/apt-get.cc: remove srcpkg --- cmdline/apt-get.cc | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) (limited to 'cmdline') diff --git a/cmdline/apt-get.cc b/cmdline/apt-get.cc index db9424985..0879cf7c6 100644 --- a/cmdline/apt-get.cc +++ b/cmdline/apt-get.cc @@ -2802,7 +2802,6 @@ bool DownloadChangelog(CacheFile &CacheFile, pkgAcquire &Fetcher, * GuessThirdPartyChangelogUri for details how) */ { - string srcpkg; string path; string descr; string server; @@ -2816,9 +2815,9 @@ bool DownloadChangelog(CacheFile &CacheFile, pkgAcquire &Fetcher, "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?!? @@ -2828,8 +2827,8 @@ bool DownloadChangelog(CacheFile &CacheFile, pkgAcquire &Fetcher, 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(); } } -- cgit v1.2.3 From 6c6b2a3221f0a9432efd0080074b17c4e9d6a6ec Mon Sep 17 00:00:00 2001 From: Michael Vogt Date: Thu, 18 Nov 2010 14:32:44 +0100 Subject: cmdline/apt-get.cc: download it all in one go --- cmdline/apt-get.cc | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'cmdline') diff --git a/cmdline/apt-get.cc b/cmdline/apt-get.cc index febcab18c..a1a1b586d 100644 --- a/cmdline/apt-get.cc +++ b/cmdline/apt-get.cc @@ -2751,7 +2751,6 @@ 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(); @@ -2781,8 +2780,8 @@ bool DoDownload(CommandLine &CmdL) hash = HashString("md5", rec.MD5Hash()); // get the file new pkgAcqFile(&Fetcher, uri, hash.toStr(), (*Ver)->Size, descr, Pkg.Name(), "."); - result &= (Fetcher.Run() == pkgAcquire::Continue); } + bool result = (Fetcher.Run() == pkgAcquire::Continue); return result; } -- cgit v1.2.3