[Aptitude-svn-commit] r4313 - in branches/aptitude-0.3/aptitude: . src/generic/apt

Daniel Burrows dburrows at costa.debian.org
Tue Sep 27 19:54:37 UTC 2005


Author: dburrows
Date: Tue Sep 27 19:54:34 2005
New Revision: 4313

Modified:
   branches/aptitude-0.3/aptitude/ChangeLog
   branches/aptitude-0.3/aptitude/src/generic/apt/pkg_changelog.cc
   branches/aptitude-0.3/aptitude/src/generic/apt/pkg_changelog.h
Log:
Use the new temp:: stuff to put temporary changelog files in /tmp.

Modified: branches/aptitude-0.3/aptitude/ChangeLog
==============================================================================
--- branches/aptitude-0.3/aptitude/ChangeLog	(original)
+++ branches/aptitude-0.3/aptitude/ChangeLog	Tue Sep 27 19:54:34 2005
@@ -1,5 +1,10 @@
 2005-09-27  Daniel Burrows  <dburrows at debian.org>
 
+	* src/generic/apt/pkg_changelog.cc, src/generic/apt/pkg_changeloh.h:
+
+	  Use the temp::* classes to manage the changelog instead of
+	  manually constructing a temporary name.
+
 	* src/generic/util/Makefile.am, src/generic/util/temp.cc, src/generic/util/temp.h, tests/Makefile.am, tests/test_temp.cc:
 
 	  Add C++-based support code for securely creating and cleaning up

Modified: branches/aptitude-0.3/aptitude/src/generic/apt/pkg_changelog.cc
==============================================================================
--- branches/aptitude-0.3/aptitude/src/generic/apt/pkg_changelog.cc	(original)
+++ branches/aptitude-0.3/aptitude/src/generic/apt/pkg_changelog.cc	Tue Sep 27 19:54:34 2005
@@ -41,17 +41,11 @@
 
 using namespace std;
 
-pkg_changelog::pkg_changelog(const string &_filename)
+pkg_changelog::pkg_changelog(const temp::name &_filename)
   :filename(_filename)
 {
 }
 
-pkg_changelog::~pkg_changelog()
-{
-  if(unlink(filename.c_str())==-1)
-    _error->WarningE("unlink", "%s", filename.c_str());
-}
-
 /** HACK: This just overrides the failure method to catch 404s. */
 class AcqWithFail:public pkgAcqFileSane
 {
@@ -101,34 +95,19 @@
 					 int PulseInterval,
 					 const string &name)
 {
-  string filename="aptitudeXXXXXX";
+  temp::dir tempdir;
+  temp::name tempname;
 
-  string dotdir(get_homedir());
-  if(!dotdir.empty())
+  try
     {
-      dotdir+="/.aptitude";
-      if(mkdir(dotdir.c_str(), 0700)<0 && errno!=EEXIST)
-	{
-	  _error->Errno("mkdir", "%s", dotdir.c_str());
-	  return NULL;
-	}
-      string tmpdotdir(dotdir+"/.tmp");
-      if(mkdir(tmpdotdir.c_str(), 0700)<0 && errno!=EEXIST)
-	{
-	  _error->Errno("mkdir", "%s", tmpdotdir.c_str());
-	  return NULL;
-	}
-      filename=tmpdotdir+"/"+filename;
+      tempdir = temp::dir("aptitude");
+      tempname = temp::name(tempdir, "changelog");
     }
-  else
+  catch(temp::TemporaryCreationFailure e)
     {
-      _error->Warning(_("Can't get value of $HOME, using TMPDIR (insecure)"));
-      if(getenv("TMPDIR"))
-	filename=getenv("TMPDIR")+("/"+filename);
-      else
-	filename="/tmp/"+filename;
+      _error->Error("%s", e.errmsg().c_str());
+      return NULL;
     }
-  filename=mktemp((char *) filename.c_str());
 
   char uribuf[1024];
 
@@ -172,7 +151,7 @@
 		  uribuf,
 		  buf,
 		  buf,
-		  filename,
+		  tempname.get_name().c_str(),
 		  failed);
 
   sigset_t signals,oldsigs;
@@ -180,16 +159,14 @@
   sigaddset(&signals, SIGWINCH);
   sigprocmask(SIG_UNBLOCK, &signals, &oldsigs);
 
-  if(fetcher.Run(PulseInterval)!=pkgAcquire::Continue || failed)
+  if(fetcher.Run(PulseInterval) != pkgAcquire::Continue || failed)
     {
       _error->Error("Couldn't fetch URL %s", uribuf);
 
       sigprocmask(SIG_SETMASK, &oldsigs, &signals);
-      if(unlink(filename.c_str())<0 && errno!=EEXIST)
-	_error->WarningE("unlink", "%s", filename.c_str());
       return NULL;
     }
 
   sigprocmask(SIG_SETMASK, &oldsigs, &signals);
-  return new pkg_changelog(filename);
+  return new pkg_changelog(tempname);
 }

Modified: branches/aptitude-0.3/aptitude/src/generic/apt/pkg_changelog.h
==============================================================================
--- branches/aptitude-0.3/aptitude/src/generic/apt/pkg_changelog.h	(original)
+++ branches/aptitude-0.3/aptitude/src/generic/apt/pkg_changelog.h	Tue Sep 27 19:54:34 2005
@@ -24,16 +24,16 @@
 
 #include <string>
 
+#include <generic/util/temp.h>
+
 #include <apt-pkg/acquire.h>
 #include <apt-pkg/pkgcache.h>
 
 class pkg_changelog
-// Mainly used to make it easy (transparent) to clean up the changelog when
-// you're done with it.
 {
-  std::string filename;
+  temp::name filename;
 
-  pkg_changelog::pkg_changelog(const std::string &_filename);
+  pkg_changelog::pkg_changelog(const temp::name &_filename);
   friend pkg_changelog *get_changelog_from_source(const std::string &,
 						  const std::string &,
 						  const std::string &,
@@ -41,9 +41,7 @@
 						  int,
 						  const std::string &);
 public:
-  std::string get_filename() {return filename;}
-
-  ~pkg_changelog();
+  std::string get_filename() { return filename.get_name(); }
 };
 
 pkg_changelog *get_changelog(pkgCache::VerIterator ver,



More information about the Aptitude-svn-commit mailing list