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

Daniel Burrows dburrows at costa.debian.org
Mon Sep 26 19:26:57 UTC 2005


Author: dburrows
Date: Mon Sep 26 19:26:54 2005
New Revision: 4289

Modified:
   branches/aptitude-0.3/aptitude/ChangeLog
   branches/aptitude-0.3/aptitude/src/edit_pkg_hier.cc
   branches/aptitude-0.3/aptitude/src/generic/apt/apt.cc
   branches/aptitude-0.3/aptitude/src/generic/apt/pkg_changelog.cc
   branches/aptitude-0.3/aptitude/src/ui.cc
Log:
Use getpwuid instead of getenv to find the home directory.

Modified: branches/aptitude-0.3/aptitude/ChangeLog
==============================================================================
--- branches/aptitude-0.3/aptitude/ChangeLog	(original)
+++ branches/aptitude-0.3/aptitude/ChangeLog	Mon Sep 26 19:26:54 2005
@@ -1,5 +1,10 @@
 2005-09-26  Daniel Burrows  <dburrows at debian.org>
 
+	* src/edit_pkg_hier.cc, src/generic/apt/apt.cc, src/generic/apt/pkg_changelog.cc, src/ui.cc:
+
+	  Consistently use pkg_homedir() instead of getenv("HOME").
+	  (Closes: #272429, #274216, #285334)
+
 	* src/generic/util/util.cc, src/generic/util/util.h:
 
 	  Write a utility routine to look up the current user's home

Modified: branches/aptitude-0.3/aptitude/src/edit_pkg_hier.cc
==============================================================================
--- branches/aptitude-0.3/aptitude/src/edit_pkg_hier.cc	(original)
+++ branches/aptitude-0.3/aptitude/src/edit_pkg_hier.cc	Mon Sep 26 19:26:54 2005
@@ -21,6 +21,7 @@
 #include "edit_pkg_hier.h"
 
 #include "aptitude.h"
+#include "ui.h"
 
 #include <apt-pkg/error.h>
 
@@ -30,6 +31,8 @@
 
 #include <generic/apt/apt.h>
 
+#include <generic/util/util.h>
+
 #include <vscreen/config/keybindings.h>
 #include <vscreen/vs_subtree.h>
 #include <vscreen/transcode.h>
@@ -320,9 +323,18 @@
 {
   if(global_bindings.key_matches(k, "SaveHier"))
     {
-      const char *cfgloc=getenv("HOME");
+      string homedir = get_homedir();
+      string cfgfile;
 
-      string cfgfile=string(cfgloc)+"/.aptitude/function_pkgs";
+      if(homedir.empty())
+	{
+	  show_message(_("Unable to look up your home directory, saving to /tmp/function_pkgs!"),
+		       NULL,
+		       get_style("Error"));
+	  cfgfile = "/tmp/function_pkgs";
+	}
+      else
+	cfgfile = homedir + "/.aptitude/function_pkgs";
       save_hier(cfgfile);
     }
   else if(global_bindings.key_matches(k, "Quit"))

Modified: branches/aptitude-0.3/aptitude/src/generic/apt/apt.cc
==============================================================================
--- branches/aptitude-0.3/aptitude/src/generic/apt/apt.cc	(original)
+++ branches/aptitude-0.3/aptitude/src/generic/apt/apt.cc	Mon Sep 26 19:26:54 2005
@@ -32,6 +32,7 @@
 #include "tasks.h"
 
 #include <generic/util/undo.h>
+#include <generic/util/util.h>
 
 #include <apt-pkg/configuration.h>
 #include <apt-pkg/depcache.h>
@@ -95,8 +96,8 @@
 
   user_pkg_hier->input_file(PKGDATADIR "/function_groups");
 
-  const char *cfgloc=getenv("HOME");
-  if(cfgloc)
+  string cfgloc(get_homedir());
+  if(!cfgloc.empty())
     {
       string user_hier=cfgloc+string("/.aptitude/function_pkgs");
       if(access(user_hier.c_str(), R_OK)==0)
@@ -119,11 +120,9 @@
   pkgInitSystem(*_config, _system);
 
   // Allow a user-specific customization file.
-  const char *HOME=getenv("HOME");
-
-  if(HOME)
+  string cfgloc(get_homedir());
+  if(!cfgloc.empty())
     {
-      string cfgloc=HOME;
       cfgloc+="/.aptitude/config";
 
       // This attempts to test whether the file is available
@@ -150,12 +149,11 @@
 
 void apt_dumpcfg(const char *root)
 {
-  const char *HOME=getenv("HOME");
+  string cfgloc(get_homedir());
 
-  if(!HOME)
+  if(cfgloc.empty())
     return;
 
-  string cfgloc=HOME;
   cfgloc+="/.aptitude";
 
   if(mkdir(cfgloc.c_str(), 0700)<0 && errno!=EEXIST)
@@ -185,7 +183,7 @@
     }
 }
 
-// Revert back to the default set of options.  Is it a hack?  Hmmm...
+// Revert back to the default set of options.  Is it a hack?  mHmm...
 void apt_revertoptions()
 {
   Configuration *old_user_config=user_config;

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	Mon Sep 26 19:26:54 2005
@@ -32,6 +32,8 @@
 #include <signal.h>
 #include <sys/stat.h>
 
+#include <generic/util/util.h>
+
 #include <apt-pkg/error.h>
 #include <apt-pkg/configuration.h>
 #include <apt-pkg/acquire-item.h>
@@ -101,9 +103,9 @@
 {
   string filename="aptitudeXXXXXX";
 
-  if(getenv("HOME"))
+  string dotdir(get_homedir());
+  if(!dotdir.empty())
     {
-      string dotdir(getenv("HOME"));
       dotdir+="/.aptitude";
       if(mkdir(dotdir.c_str(), 0700)<0 && errno!=EEXIST)
 	{

Modified: branches/aptitude-0.3/aptitude/src/ui.cc
==============================================================================
--- branches/aptitude-0.3/aptitude/src/ui.cc	(original)
+++ branches/aptitude-0.3/aptitude/src/ui.cc	Mon Sep 26 19:26:54 2005
@@ -372,9 +372,10 @@
 
   // Copied from pkg_changelog.cc.  This should be its own routine?
   string fifoname="aptitudeXXXXXX", statusfile="aptitudeXXXXXX";
-  if(getenv("HOME"))
+
+  string dotdir(get_homedir());
+  if(!dotdir.empty())
     {
-      string dotdir(getenv("HOME"));
       dotdir+="/.aptitude";
       if(mkdir(dotdir.c_str(), 0700)<0 && errno!=EEXIST)
 	{



More information about the Aptitude-svn-commit mailing list