diff options
author | David Kalnischkies <kalnischkies@gmail.com> | 2011-02-07 17:30:06 +0100 |
---|---|---|
committer | David Kalnischkies <kalnischkies@gmail.com> | 2011-02-07 17:30:06 +0100 |
commit | 72dd5bec06d8d50ff9e8022e36a7d8a6f0cfd7a0 (patch) | |
tree | dffa7dd8e26a0c8241e9416ea52319da98e20c94 | |
parent | fcb144b91a91ef9b6016ede0be05e07dacc8aaf9 (diff) | |
download | apt-72dd5bec06d8d50ff9e8022e36a7d8a6f0cfd7a0.tar.gz |
implement download-only for changelog command which downloads the
changelog to the file $PKGNAME.changelog in the current directory
-rw-r--r-- | cmdline/apt-get.cc | 41 | ||||
-rwxr-xr-x | test/integration/test-changelog | 12 |
2 files changed, 39 insertions, 14 deletions
diff --git a/cmdline/apt-get.cc b/cmdline/apt-get.cc index 99c0e5d66..93f167f19 100644 --- a/cmdline/apt-get.cc +++ b/cmdline/apt-get.cc @@ -2961,6 +2961,8 @@ bool DoChangelog(CommandLine &CmdL) APT::CacheSetHelper helper(c0out); APT::VersionSet verset = APT::VersionSet::FromCommandLine(Cache, CmdL.FileList + 1, APT::VersionSet::CANDIDATE, helper); + if (verset.empty() == true) + return false; pkgAcquire Fetcher; if (_config->FindB("APT::Get::Print-URIs", false) == true) @@ -2971,26 +2973,41 @@ bool DoChangelog(CommandLine &CmdL) 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"); + bool const downOnly = _config->FindB("APT::Get::Download-Only", false); + + char tmpname[100]; + char* tmpdir = NULL; + if (downOnly == false) + { + const char* const tmpDir = getenv("TMPDIR"); + if (tmpDir != NULL && *tmpDir != '\0') + snprintf(tmpname, sizeof(tmpname), "%s/apt-changelog-XXXXXX", tmpDir); + else + strncpy(tmpname, "/tmp/apt-changelog-XXXXXX", sizeof(tmpname)); + tmpdir = mkdtemp(tmpname); + 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)) + string changelogfile; + if (downOnly == false) + changelogfile.append(tmpname).append("changelog"); + else + changelogfile.append(Ver.ParentPkg().Name()).append(".changelog"); + if (DownloadChangelog(Cache, Fetcher, Ver, changelogfile) && downOnly == false) + { DisplayFileInPager(changelogfile); - // cleanup temp file - unlink(changelogfile.c_str()); + // cleanup temp file + unlink(changelogfile.c_str()); + } } // clenaup tmp dir - rmdir(tmpdir); - free(tmpdir); + if (tmpdir != NULL) + rmdir(tmpdir); return true; } /*}}}*/ diff --git a/test/integration/test-changelog b/test/integration/test-changelog index b5c204a53..0a80cc08c 100755 --- a/test/integration/test-changelog +++ b/test/integration/test-changelog @@ -19,10 +19,18 @@ testequal "'http://localhost:8080//pool/apt_1.0/changelog'" aptget changelog apt aptget changelog apt -qq > apt.changelog testfileequal 'apt.changelog' "$(cat aptarchive/pool/apt_1.0/changelog)" -rm aptarchive/pool/apt_1.0/changelog +rm apt.changelog + +aptget changelog apt -d -qq +testfileequal 'apt.changelog' "$(cat aptarchive/pool/apt_1.0/changelog)" +rm apt.changelog aptarchive/pool/apt_1.0/changelog aptget changelog apt -qq -o APT::Changelogs::Server='http://not-on-the-main-server:8080/' > apt.changelog testfileequal 'apt.changelog' "$(cat aptarchive/pool/apt_1.0.changelog)" -rm aptarchive/pool/apt_1.0.changelog +rm apt.changelog + +aptget changelog apt -d -qq +testfileequal 'apt.changelog' "$(cat aptarchive/pool/apt_1.0.changelog)" +rm apt.changelog aptarchive/pool/apt_1.0.changelog testequal 'E: changelog download failed' aptget changelog apt -qq -o APT::Changelogs::Server='http://not-on-the-main-server:8080/' |