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 /cmdline | |
parent | fcb144b91a91ef9b6016ede0be05e07dacc8aaf9 (diff) |
implement download-only for changelog command which downloads the
changelog to the file $PKGNAME.changelog in the current directory
Diffstat (limited to 'cmdline')
-rw-r--r-- | cmdline/apt-get.cc | 41 |
1 files changed, 29 insertions, 12 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; } /*}}}*/ |