summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--apt-pkg/contrib/strutl.cc9
-rw-r--r--apt-pkg/contrib/strutl.h1
-rw-r--r--cmdline/apt-get.cc218
-rw-r--r--debian/apt.conf.changelog2
-rw-r--r--debian/changelog3
-rw-r--r--doc/examples/configure-index98
-rw-r--r--test/integration/framework1
-rwxr-xr-xtest/integration/test-changelog34
8 files changed, 320 insertions, 46 deletions
diff --git a/apt-pkg/contrib/strutl.cc b/apt-pkg/contrib/strutl.cc
index 987f4c3a4..c2b335ed7 100644
--- a/apt-pkg/contrib/strutl.cc
+++ b/apt-pkg/contrib/strutl.cc
@@ -1174,6 +1174,15 @@ char *safe_snprintf(char *Buffer,char *End,const char *Format,...)
return Buffer + Did;
}
/*}}}*/
+// StripEpoch - Remove the version "epoch" from a version string /*{{{*/
+// ---------------------------------------------------------------------
+string StripEpoch(const string &VerStr)
+{
+ size_t i = VerStr.find(":");
+ if (i == string::npos)
+ return VerStr;
+ return VerStr.substr(i+1);
+}
// tolower_ascii - tolower() function that ignores the locale /*{{{*/
// ---------------------------------------------------------------------
diff --git a/apt-pkg/contrib/strutl.h b/apt-pkg/contrib/strutl.h
index a457ff047..14cf5c943 100644
--- a/apt-pkg/contrib/strutl.h
+++ b/apt-pkg/contrib/strutl.h
@@ -61,6 +61,7 @@ void strprintf(string &out,const char *format,...) __like_printf(2);
char *safe_snprintf(char *Buffer,char *End,const char *Format,...) __like_printf(3);
bool CheckDomainList(const string &Host, const string &List);
int tolower_ascii(int const c) __attrib_const __hot;
+string StripEpoch(const string &VerStr);
#define APT_MKSTRCMP(name,func) \
inline int name(const char *A,const char *B) {return func(A,A+strlen(A),B,B+strlen(B));}; \
diff --git a/cmdline/apt-get.cc b/cmdline/apt-get.cc
index 8efcd0e2e..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
@@ -2733,6 +2787,168 @@ 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)
+{
+ // get the binary deb server path
+ 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 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
+ return true;
+}
+// DownloadChangelog - Download the changelog /*{{{*/
+// ---------------------------------------------------------------------
+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 path;
+ string descr;
+ string server;
+ string changelog_uri;
+
+ // data structures we need
+ pkgCache::PkgIterator Pkg = Ver.ParentPkg();
+
+ // make the server root configurable
+ server = _config->Find("Apt::Changelogs::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());
+ // queue it
+ 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?!?
+ int res = Fetcher.Run();
+ if (!FileExists(targetfile))
+ {
+ 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);
+ res = Fetcher.Run();
+ }
+ }
+
+ if (FileExists(targetfile))
+ return true;
+
+ // error
+ return _error->Error("changelog download failed");
+}
+ /*}}}*/
+// 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;
+ AcqTextStatus Stat(ScreenWidth, _config->FindI("quiet",0));
+ Fetcher.Setup(&Stat);
+
+ if (verset.empty() == true)
+ return false;
+ char *tmpdir = mkdtemp(strdup("/tmp/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 = string(tmpdir) + "changelog";
+ if (DownloadChangelog(Cache, Fetcher, Ver, changelogfile))
+ DisplayFileInPager(changelogfile);
+ // cleanup temp file
+ unlink(changelogfile.c_str());
+ }
+ // clenaup tmp dir
+ rmdir(tmpdir);
+ free(tmpdir);
+ return true;
+}
+ /*}}}*/
// DoMoo - Never Ask, Never Tell /*{{{*/
// ---------------------------------------------------------------------
/* */
@@ -2923,6 +3139,8 @@ int main(int argc,const char *argv[]) /*{{{*/
{"autoclean",&DoAutoClean},
{"check",&DoCheck},
{"source",&DoSource},
+ {"download",&DoDownload},
+ {"changelog",&DoChangelog},
{"moo",&DoMoo},
{"help",&ShowHelp},
{0,0}};
diff --git a/debian/apt.conf.changelog b/debian/apt.conf.changelog
index 3466bb6e0..7605c97d9 100644
--- a/debian/apt.conf.changelog
+++ b/debian/apt.conf.changelog
@@ -1,6 +1,6 @@
// Server information for apt-changelog
APT {
- Changelog {
+ Changelogs {
Server "http://changelogs.ubuntu.com/changelogs";
}
}
diff --git a/debian/changelog b/debian/changelog
index 0e9332f8d..3b2746e2d 100644
--- a/debian/changelog
+++ b/debian/changelog
@@ -1,6 +1,9 @@
apt (0.8.9ubuntu1) UNRELEASED; urgency=low
* re-merged from the debian-sid bzr branch
+ * merged lp:~mvo/apt/mvo, this brings two new commands:
+ - apt-get download binary-pkgname to download a deb
+ - apt-get changelog binary-pkgname to display the changelog
-- Michael Vogt <michael.vogt@ubuntu.com> Thu, 18 Nov 2010 09:58:08 +0100
diff --git a/doc/examples/configure-index b/doc/examples/configure-index
index c4c2acb64..b87251103 100644
--- a/doc/examples/configure-index
+++ b/doc/examples/configure-index
@@ -114,54 +114,62 @@ APT
// does a ExecFork)
Keep-Fds {};
+ Changelogs
+ {
+ // server the provides the changelogs, the code will assume
+ // the changlogs are in the pool/ under a srcpkg_ver directory
+ // with the name "changelog"
+ Server "http://packages.debian.org/changelogs";
+ }:
+
// control parameters for cron jobs by /etc/cron.daily/apt
Periodic
{
- BackupArchiveInterval "0";
- // - Backup after n-days if archive contents changed.(0=disable)
-
- BackupLevel "3";
- // - Backup level.(0=disable), 1 is invalid.
-
- // APT::Archives::MaxAge "0"; (old, deprecated)
- MaxAge "0"; // (new)
- // - Set maximum allowed age of a cache package file. If a cache
- // package file is older it is deleted (0=disable)
-
- // APT::Archives::MinAge "2"; (old, deprecated)
- MinAge "2"; // (new)
- // - Set minimum age of a package file. If a file is younger it
- // will not be deleted (0=disable). Usefull to prevent races
- // and to keep backups of the packages for emergency.
-
- // APT::Archives::MaxSize "0"; (old, deprecated)
- MaxSize "0"; // (new)
- // - Set maximum size of the cache in MB (0=disable). If the cache
- // is bigger, cached package files are deleted until the size
- // requirement is met (the biggest packages will be deleted
- // first).
-
- Update-Package-Lists "0";
- // - Do "apt-get update" automatically every n-days (0=disable)
- //
- Download-Upgradeable-Packages "0";
- // - Do "apt-get upgrade --download-only" every n-days (0=disable)
- //
- Unattended-Upgrade "0";
- // - Run the "unattended-upgrade" security upgrade script
- // every n-days (0=disabled)
- // Requires the package "unattended-upgrades" and will write
- // a log in /var/log/unattended-upgrades
- //
- AutocleanInterval "0";
- // - Do "apt-get autoclean" every n-days (0=disable)
-
- Verbose "0";
- // - Send report mail to root
- // 0: no report (or null string)
- // 1: progress report (actually any string)
- // 2: + command outputs (remove -qq, remove 2>/dev/null, add -d)
- // 3: + trace on
+ BackupArchiveInterval "0";
+ // - Backup after n-days if archive contents changed.(0=disable)
+
+ BackupLevel "3";
+ // - Backup level.(0=disable), 1 is invalid.
+
+ // APT::Archives::MaxAge "0"; (old, deprecated)
+ MaxAge "0"; // (new)
+ // - Set maximum allowed age of a cache package file. If a cache
+ // package file is older it is deleted (0=disable)
+
+ // APT::Archives::MinAge "2"; (old, deprecated)
+ MinAge "2"; // (new)
+ // - Set minimum age of a package file. If a file is younger it
+ // will not be deleted (0=disable). Usefull to prevent races
+ // and to keep backups of the packages for emergency.
+
+ // APT::Archives::MaxSize "0"; (old, deprecated)
+ MaxSize "0"; // (new)
+ // - Set maximum size of the cache in MB (0=disable). If the cache
+ // is bigger, cached package files are deleted until the size
+ // requirement is met (the biggest packages will be deleted
+ // first).
+
+ Update-Package-Lists "0";
+ // - Do "apt-get update" automatically every n-days (0=disable)
+ //
+ Download-Upgradeable-Packages "0";
+ // - Do "apt-get upgrade --download-only" every n-days (0=disable)
+ //
+ Unattended-Upgrade "0";
+ // - Run the "unattended-upgrade" security upgrade script
+ // every n-days (0=disabled)
+ // Requires the package "unattended-upgrades" and will write
+ // a log in /var/log/unattended-upgrades
+ //
+ AutocleanInterval "0";
+ // - Do "apt-get autoclean" every n-days (0=disable)
+
+ Verbose "0";
+ // - Send report mail to root
+ // 0: no report (or null string)
+ // 1: progress report (actually any string)
+ // 2: + command outputs (remove -qq, remove 2>/dev/null, add -d)
+ // 3: + trace on
};
};
diff --git a/test/integration/framework b/test/integration/framework
index 2422f0886..f78ae2ee1 100644
--- a/test/integration/framework
+++ b/test/integration/framework
@@ -117,6 +117,7 @@ setupenvironment() {
echo "Debug::NoLocking \"true\";" >> aptconfig.conf
echo "APT::Get::Show-User-Simulation-Note \"false\";" >> aptconfig.conf
echo "Dir::Bin::dpkg \"fakeroot\";" >> aptconfig.conf
+ echo "Dir::Bin::methods \"${BUILDDIRECTORY}/methods\";" >> aptconfig.conf
echo "DPKG::options:: \"dpkg\";" >> aptconfig.conf
echo "DPKG::options:: \"--root=${TMPWORKINGDIRECTORY}/rootdir\";" >> aptconfig.conf
echo "DPKG::options:: \"--force-not-root\";" >> aptconfig.conf
diff --git a/test/integration/test-changelog b/test/integration/test-changelog
new file mode 100755
index 000000000..292df6e32
--- /dev/null
+++ b/test/integration/test-changelog
@@ -0,0 +1,34 @@
+#!/bin/sh
+set -e
+
+TESTDIR=$(readlink -f $(dirname $0))
+. $TESTDIR/framework
+
+setupenvironment
+configarchitecture "i386"
+
+# this will be valid until ubuntu lucid is EOL (04/2015)
+pkgchangelogtest="Package: apt
+Architecture: i386
+Version: 0.7.25.3ubuntu7
+Filename: pool/main/a/apt/apt_0.7.25.3ubuntu7_i386.deb
+Section: admin
+"
+cat <<-EOF >aptarchive/Packages
+$pkgchangelogtest
+EOF
+
+setupaptarchive
+
+echo "Apt::Changelogs::Server \"http://changelogs.ubuntu.com/\";" >> ./aptconfig.conf
+msgnmsg "apt-get changelog: "
+aptget changelog apt -qq > downloaded-changelog
+expected="apt (0.7.25.3ubuntu7) lucid; urgency=low"
+got="$(head -n1 downloaded-changelog)"
+if [ -s downloaded-changelog ] && [ "$got" = "$expected" ]; then
+ msgpass
+else
+ msgfail
+ msgwarn "$got != $expected"
+fi
+