Przeglądaj źródła

implement download-only for changelog command which downloads the
changelog to the file $PKGNAME.changelog in the current directory

David Kalnischkies 15 lat temu
rodzic
commit
72dd5bec06
2 zmienionych plików z 39 dodań i 14 usunięć
  1. 29 12
      cmdline/apt-get.cc
  2. 10 2
      test/integration/test-changelog

+ 29 - 12
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;
 }
 									/*}}}*/

+ 10 - 2
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/'