On Friday 26 November 2004 21:42 CET Sidney Markowitz wrote:
> Malte S. Stretz wrote:
> > So maybe we should add a M::SA::Util::get_home() which first
> > tries $ENV{HOME}, then on Windows $ENV{HOMEDRIVE}\$ENV{HOMEDIR}, then
> > portable_getpwuid()[7], then... foo?
>
> portable_getpwuid() doesn't seem to do anything useful under Windows for
> this purpose and shouldn't be needed anyway. It just returns 'unknown'
> for the name, which works when you don't care about the actual user name.

Yeah, noticed that, too.

> The first two steps are fine, and probably enough, except that you would
>    not have to add the '\' separator, it is already in HOMEDIR.
>
> Question: In ArchiveIterator.pm does everything work if that is what it
> uses for HOME or does anything have to be done to convert \ to / ?

What do you think about the attached patch?  Try it with
perl -Ilib -MMail::SpamAssassin::Util \
  -le 'print Mail::SpamAssassin::Util::get_home()'

Cheers,
Malte

-- 
[SGT] Simon G. Tatham: "How to Report Bugs Effectively"
      <http://www.chiark.greenend.org.uk/~sgtatham/bugs.html>
[ESR] Eric S. Raymond: "How To Ask Questions The Smart Way"
      <http://www.catb.org/~esr/faqs/smart-questions.html>
Index: Util.pm
===================================================================
--- Util.pm	(revision 106653)
+++ Util.pm	(working copy)
@@ -535,6 +535,28 @@
 
 ###########################################################################
 
+{
+  my $home;
+
+  sub get_home {
+    return $home if defined $home;
+
+    $home = $ENV{'HOMEx'};
+
+    unless ($home) {
+      if (!RUNNING_ON_WINDOWS) {
+        $home = (portable_getpwuid($<))[7];
+      } else {
+        $home = File::Spec->catpath($ENV{'HOMEDRIVE'}, $ENV{'HOMEDIR'});
+      }
+    }
+
+    return $home || '';
+  }
+}
+
+###########################################################################
+
 # Given a string, extract an IPv4 address from it.  Required, since
 # we currently have no way to portably unmarshal an IPv4 address from
 # an IPv6 one without kludging elsewhere.

Reply via email to