Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

File::Glob Windows home directory expansion #11646

Closed
p5pRT opened this issue Sep 10, 2011 · 14 comments
Closed

File::Glob Windows home directory expansion #11646

p5pRT opened this issue Sep 10, 2011 · 14 comments

Comments

@p5pRT
Copy link

p5pRT commented Sep 10, 2011

Migrated from rt.perl.org#98812 (status was 'resolved')

Searchable as RT98812$

@p5pRT
Copy link
Author

p5pRT commented Sep 10, 2011

From doug@somethingdoug.com

Created by doug@somethingdoug.com

This is a bug report for perl from doug@​somethingdoug.com,
generated with the help of perlbug 1.39 running under perl 5.12.3.

-----------------------------------------------------------------
The currently bundled File​::Glob will expand a tilde character
to the current user's home directory. Now, the method this uses
is to check the HOME environment variable (which is does not
exist by default on Windows) and then using password file
functions (which are not implemented on Windows). I am including
a patch here that on Windows will fallback to expanding the home
directory from the USERPROFILE environment variable, which exists
by default on Windows and serves the same purpose as HOME.

Here is a patch I have made to add this support. I tested it on
Windows 7 and Ubuntu 11.04. It is based off the blead branch.

From c47ba121daf8af47e6161ea81cf96bf1318346cf Mon Sep 17 00​:00​:00 2001
From​: Douglas Christopher Wilson <doug@​somethingdoug.com>
Date​: Fri, 9 Sep 2011 22​:17​:18 -0400
Subject​: [PATCH] Add plain ~ expansion for Windows system in File​::Glob

Previously in File​::Glob, a plain ~ expansion will check
the $HOME environment variable, but that does not normally
exist on Windows systems. There is another variable that
holds the appropriate home path value, which is $USERPROFILE.

This adds a fallback to check $USERPROFILE when $HOME is
not there, the system does not support checking the password
file and the system is DOSISH.
---
ext/File-Glob/bsd_glob.c | 9 +++++++++
ext/File-Glob/t/basic.t | 36 +++++++++++++++++++++++++++++++++++-
2 files changed, 44 insertions(+), 1 deletions(-)

Inline Patch
diff --git a/ext/File-Glob/bsd_glob.c b/ext/File-Glob/bsd_glob.c
index f891d29..236f55d 100644
--- a/ext/File-Glob/bsd_glob.c
+++ b/ext/File-Glob/bsd_glob.c
@@ -457,6 +457,7 @@ globtilde(const Char *pattern, Char *patbuf, size_t 
patbuf_len, glob_t *pglob)   /\*   \* handle a plain ~ or ~/ by expanding $HOME   \* first and then trying the password file \+ \* or $USERPROFILE on DOSISH systems   \*/   if \(\(h = getenv\("HOME"\)\) == NULL\) \{ \#ifdef HAS\_PASSWD @​@​ \-465\,6 \+466\,14 @​@​ globtilde\(const Char \*pattern\, Char \*patbuf\, size\_t patbuf\_len\, glob\_t \*pglob\)   return pattern;   else   h = pwd\->pw\_dir; \+\#elif DOSISH \+ /\* \+ \* When no passwd file\, fallback to the USERPROFILE \+ \* environment variable on DOSish systems\. \+ \*/ \+ if \(\(h = getenv\("USERPROFILE"\)\) == NULL\) \{ \+ return pattern; \+ \} \#else   return pattern; \#endif
Inline Patch
diff --git a/ext/File-Glob/t/basic.t b/ext/File-Glob/t/basic.t
index ed83019..767ab79 100644
--- a/ext/File-Glob/t/basic.t
+++ b/ext/File-Glob/t/basic.t
@@ -10,7 +10,7 @@ BEGIN {
     }
} use strict; \-use Test​::More tests => 15; \+use Test​::More tests => 18; BEGIN \{use\_ok\('File​::Glob'\, '​:glob'\)\}; use Cwd \(\);

@​@​ -68,6 +68,40 @​@​ SKIP​: {
  is_deeply (\@​a, [$home]);
  }
}
+# check plain tilde expansion
+{
+ my $tilde_check = sub {
+ my @​a = bsd_glob('');
+
+ if (GLOB_ERROR) {
+ fail(GLOB_ERROR);
+ } else {
+ is_deeply (\@​a, [$_[0]], join ' - ', 'tilde expansion', @​_ > 1 ?
$_[1] : ());
+ }
+ };
+ my $passwd_home = eval { (getpwuid($&gt;))[7] };
+
+ {
+ local %ENV = %ENV;
+ delete $ENV{HOME};
+ delete $ENV{USERPROFILE};
+ $tilde_check->(defined $passwd_home ? $passwd_home : q{
}, 'no
environment');
+ }
+
+ SKIP​: {
+ skip 'MSWin32 only', 1 if $^O ne 'MSWin32';
+ local %ENV = %ENV;
+ delete $ENV{HOME};
+ $ENV{USERPROFILE} = 'sweet win32 home';
+ $tilde_check->(defined $passwd_home ? $passwd_home : $ENV{USERPROFILE},
'USERPROFILE');
+ }
+
+ my $home = exists $ENV{HOME} ? $ENV{HOME}
+ : eval { getpwuid($&gt;); 1 } ? (getpwuid($&gt;))[7]
+ : $^O eq 'MSWin32' && exists $ENV{USERPROFILE} ? $ENV{USERPROFILE}
+ : q{~};
+ $tilde_check->($home);
+}

# check backslashing
# should return a list with one item, and not set ERROR
--
1.7.6.msysgit.0

Perl Info

Flags:
    category=library
    severity=wishlist

This perlbug was built using Perl 5.15.2 - Fri Sep  9 20:14:33 2011
It is being executed now by  Perl 5.12.3 - Sun May 15 09:47:32 2011.

Site configuration information for perl 5.12.3:

Configured by 1 at Sun May 15 09:47:32 2011.

Summary of my perl5 (revision 5 version 12 subversion 3) configuration:

  Platform:
    osname=MSWin32, osvers=6.1, archname=MSWin32-x64-multi-thread
    uname='Win32 strawberryperl 5.12.3.0 #1 Sun May 15 09:43:50 2011 x64'
    config_args='undef'
    hint=recommended, useposix=true, d_sigaction=undef
    useithreads=define, usemultiplicity=define
    useperlio=define, d_sfio=undef, uselargefiles=define, usesocks=undef
    use64bitint=define, use64bitall=undef, uselongdouble=undef
    usemymalloc=n, bincompat5005=undef
  Compiler:
    cc='gcc', ccflags 
=' -s -O2 -DWIN32 -DHAVE_DES_FCRYPT -DWIN64 -DCONSERVATIVE  -DUSE_SITECUSTOMIZE 
 -DPERL_IMPLICIT_CONTEXT -DPERL_IMPLICIT_SYS -fno-strict-aliasing -mms-bitfields 
 -DPERL_MSVCRT_READFIX',
    optimize='-s -O2',
    cppflags='-DWIN32'
    ccversion='', gccversion='4.4.3', gccosandvers=''
    intsize=4, longsize=4, ptrsize=8, doublesize=8, byteorder=12345678
    d_longlong=define, longlongsize=8, d_longdbl=define, longdblsize=12
    ivtype='long long', ivsize=8, nvtype='double', nvsize=8, Off_t='long 
long', lseeksize=8
    alignbytes=8, prototype=define
  Linker and Libraries:
    ld='g++', ldflags 
='-s -L"C:\strawberry\perl\lib\CORE" -L"C:\strawberry\c\lib"'
    libpth=C:\strawberry\c\lib C:\strawberry\c\x86_64-w64-mingw32\lib
    libs=-lmoldname -lkernel32 -luser32 -lgdi32 -lwinspool -lcomdlg32 -ladvapi32 
 -lshell32 -lole32 -loleaut32 -lnetapi32 -luuid -lws2_32 -lmpr -lwinmm -lversion 
 -lodbc32 -lodbccp32 -lcomctl32
    perllibs=-lmoldname -lkernel32 -luser32 -lgdi32 -lwinspool -lcomdlg32 -ladvapi32 
 -lshell32 -lole32 -loleaut32 -lnetapi32 -luuid -lws2_32 -lmpr -lwinmm -lversion 
 -lodbc32 -lodbccp32 -lcomctl32
    libc=, so=dll, useshrplib=true, libperl=libperl512.a
    gnulibc_version=''
  Dynamic Linking:
    dlsrc=dl_win32.xs, dlext=dll, d_dlsymun=undef, ccdlflags=' '
    cccdlflags=' ', 
lddlflags='-mdll -s -L"C:\strawberry\perl\lib\CORE" -L"C:\strawberry\c\lib"'

Locally applied patches:



@INC for perl 5.12.3:
    C:/strawberry/perl/site/lib
    C:/strawberry/perl/vendor/lib
    C:/strawberry/perl/lib
    .


Environment for perl 5.12.3:
    HOME (unset)
    LANG (unset)
    LANGUAGE (unset)
    LD_LIBRARY_PATH (unset)
    LOGDIR (unset)
    PATH=C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;C:\Windows\System32\WindowsPowerShell\v1.0\;C:\strawberry\c\bin;C:\strawberry\perl\site\bin;C:\strawberry\perl\bin;C:\Program 
Files (x86)\Git\cmd
    PERL_BADLANG (unset)
    PERL_JSON_BACKEND=JSON::XS
    PERL_YAML_BACKEND=YAML
    SHELL (unset) 


@p5pRT
Copy link
Author

p5pRT commented Sep 10, 2011

From @cpansprout

On Fri Sep 09 22​:58​:37 2011, doug@​somethingdoug.com wrote​:

This is a bug report for perl from doug@​somethingdoug.com,
generated with the help of perlbug 1.39 running under perl 5.12.3.

-----------------------------------------------------------------
The currently bundled File​::Glob will expand a tilde character
to the current user's home directory. Now, the method this uses
is to check the HOME environment variable (which is does not
exist by default on Windows) and then using password file
functions (which are not implemented on Windows). I am including
a patch here that on Windows will fallback to expanding the home
directory from the USERPROFILE environment variable, which exists
by default on Windows and serves the same purpose as HOME.

Here is a patch I have made to add this support. I tested it on
Windows 7 and Ubuntu 11.04. It is based off the blead branch.

Thank you. I’ve just pushed that to the smoke-me/tilde branch.

BTW, are you the same Douglas Wilson who has a CPAN ID of DOUGW?

@p5pRT
Copy link
Author

p5pRT commented Sep 10, 2011

The RT System itself - Status changed from 'new' to 'open'

@p5pRT
Copy link
Author

p5pRT commented Sep 10, 2011

From @cpansprout

On Fri Sep 09 23​:55​:19 2011, sprout wrote​:

On Fri Sep 09 22​:58​:37 2011, doug@​somethingdoug.com wrote​:

This is a bug report for perl from doug@​somethingdoug.com,
generated with the help of perlbug 1.39 running under perl 5.12.3.

-----------------------------------------------------------------
The currently bundled File​::Glob will expand a tilde character
to the current user's home directory. Now, the method this uses
is to check the HOME environment variable (which is does not
exist by default on Windows) and then using password file
functions (which are not implemented on Windows). I am including
a patch here that on Windows will fallback to expanding the home
directory from the USERPROFILE environment variable, which exists
by default on Windows and serves the same purpose as HOME.

Here is a patch I have made to add this support. I tested it on
Windows 7 and Ubuntu 11.04. It is based off the blead branch.

Thank you. I’ve just pushed that to the smoke-me/tilde branch.

BTW, are you the same Douglas Wilson who has a CPAN ID of DOUGW?

No, you are not. :-) You are DOUGDUDE. That means you need a separate
entry in the AUTHORS file.

@p5pRT
Copy link
Author

p5pRT commented Sep 10, 2011

From @cpansprout

On Fri Sep 09 23​:55​:19 2011, sprout wrote​:

On Fri Sep 09 22​:58​:37 2011, doug@​somethingdoug.com wrote​:

This is a bug report for perl from doug@​somethingdoug.com,
generated with the help of perlbug 1.39 running under perl 5.12.3.

-----------------------------------------------------------------
The currently bundled File​::Glob will expand a tilde character
to the current user's home directory. Now, the method this uses
is to check the HOME environment variable (which is does not
exist by default on Windows) and then using password file
functions (which are not implemented on Windows). I am including
a patch here that on Windows will fallback to expanding the home
directory from the USERPROFILE environment variable, which exists
by default on Windows and serves the same purpose as HOME.

Here is a patch I have made to add this support. I tested it on
Windows 7 and Ubuntu 11.04. It is based off the blead branch.

Thank you. I’ve just pushed that to the smoke-me/tilde branch.

And to blead as 528bd3c.

@p5pRT
Copy link
Author

p5pRT commented Sep 10, 2011

@cpansprout - Status changed from 'open' to 'resolved'

@p5pRT
Copy link
Author

p5pRT commented Sep 10, 2011

From doug@somethingdoug.com

On Sat Sep 10 09​:50​:45 2011, sprout wrote​:

On Fri Sep 09 23​:55​:19 2011, sprout wrote​:

On Fri Sep 09 22​:58​:37 2011, doug@​somethingdoug.com wrote​:

Here is a patch I have made to add this support. I tested it on
Windows 7 and Ubuntu 11.04. It is based off the blead branch.

Thank you. I’ve just pushed that to the smoke-me/tilde branch.

And to blead as 528bd3c.

sprout, thank you for your quick inclusion of my patch (​: And yes,
my CPAN ID in indeed DOUGDUDE.

@p5pRT
Copy link
Author

p5pRT commented Sep 10, 2011

From doug@somethingdoug.com

On Sat Sep 10 11​:20​:46 2011, dougdude wrote​:

On Sat Sep 10 09​:50​:45 2011, sprout wrote​:

On Fri Sep 09 23​:55​:19 2011, sprout wrote​:

Thank you. I’ve just pushed that to the smoke-me/tilde branch.

And to blead as 528bd3c.

sprout, thank you for your quick inclusion of my patch (​: And yes,
my CPAN ID in indeed DOUGDUDE.

Also a patch for the checkAUTHORS.pl script on the smoke-me/tilde branch​:

From 6112c15f1f706e5524730b2537221c8159a2fd29 Mon Sep 17 00​:00​:00 2001
From​: Douglas Christopher Wilson <doug@​somethingdoug.com>
Date​: Sat, 10 Sep 2011 15​:20​:35 -0400
Subject​: [PATCH] Add DOUGDUDE to checkAUTHORS script


Porting/checkAUTHORS.pl | 2 +-
1 files changed, 1 insertions(+), 1 deletions(-)

Inline Patch
diff --git a/Porting/checkAUTHORS.pl b/Porting/checkAUTHORS.pl
index 47cdb5c..600a079 100755
--- a/Porting/checkAUTHORS.pl
+++ b/Porting/checkAUTHORS.pl
@@ -569,10 +569,10 @@ djberg86\100attbi.com                  
djberg96\100attbi.com domo\\100computer\.org shouldbedomo\\100mac\.com \+ domo\\100slipper\.ip\.lu \+ domo\\100tcp\.ip\.lu \+dougdude\\100cpan\.org doug\\100somethingdoug\.com dougm\\100covalent\.net dougm\\100opengroup\.org \+ dougm\\100osf\.org dougw\\100cpan\.org doug\_wilson\\100intuit\.com \-\+ doug\\100somethingdoug\.com dwegscheid\\100qtm\.net wegscd\\100whirlpool\.com edwardp\\100excitehome\.net epeschko\\100den\-mdev1 \+ epeschko\\100elmer\.tci\.com \-\- 1\.7\.4\.1

@p5pRT
Copy link
Author

p5pRT commented Sep 10, 2011

doug@somethingdoug.com - Status changed from 'resolved' to 'open'

@p5pRT
Copy link
Author

p5pRT commented Sep 10, 2011

From @cpansprout

On Sat Sep 10 12​:27​:13 2011, dougdude wrote​:

On Sat Sep 10 11​:20​:46 2011, dougdude wrote​:

On Sat Sep 10 09​:50​:45 2011, sprout wrote​:

On Fri Sep 09 23​:55​:19 2011, sprout wrote​:

Thank you. I’ve just pushed that to the smoke-me/tilde branch.

And to blead as 528bd3c.

sprout, thank you for your quick inclusion of my patch (​: And yes,
my CPAN ID in indeed DOUGDUDE.

Also a patch for the checkAUTHORS.pl script on the smoke-me/tilde branch​:

From 6112c15f1f706e5524730b2537221c8159a2fd29 Mon Sep 17 00​:00​:00 2001
From​: Douglas Christopher Wilson <doug@​somethingdoug.com>
Date​: Sat, 10 Sep 2011 15​:20​:35 -0400
Subject​: [PATCH] Add DOUGDUDE to checkAUTHORS script

---
Porting/checkAUTHORS.pl | 2 +-
1 files changed, 1 insertions(+), 1 deletions(-)

diff --git a/Porting/checkAUTHORS.pl b/Porting/checkAUTHORS.pl
index 47cdb5c..600a079 100755
--- a/Porting/checkAUTHORS.pl
+++ b/Porting/checkAUTHORS.pl
@​@​ -569,10 +569,10 @​@​ djberg86\100attbi.com
djberg96\100attbi.com
domo\100computer.org shouldbedomo\100mac.com
+ domo\100slipper.ip.lu
+ domo\100tcp.ip.lu
+dougdude\100cpan.org doug\100somethingdoug.com
dougm\100covalent.net dougm\100opengroup.org
+ dougm\100osf.org
dougw\100cpan.org doug_wilson\100intuit.com
-+ doug\100somethingdoug.com
dwegscheid\100qtm.net wegscd\100whirlpool.com
edwardp\100excitehome.net epeschko\100den-mdev1
+ epeschko\100elmer.tci.com

I’ve already removed that entry from checkAUTHORS.pl. The one you added
in your patch is not necessary unless the e-mail address in the commit
differs from the one in the AUTHORS file. Which e-mail address would you
prefer to use there?

(It’s confusing having two Douglas Wilsons contributing to perl. :-)

(I asked you about your CPAN ID just to find out whether you were the
same person as DOUGW.)

@p5pRT
Copy link
Author

p5pRT commented Sep 10, 2011

From doug@somethingdoug.com

On Sat Sep 10 14​:19​:51 2011, sprout wrote​:

I’ve already removed that entry from checkAUTHORS.pl. The one you added
in your patch is not necessary unless the e-mail address in the commit
differs from the one in the AUTHORS file. Which e-mail address would you
prefer to use there?

(It’s confusing having two Douglas Wilsons contributing to perl. :-)

(I asked you about your CPAN ID just to find out whether you were the
same person as DOUGW.)

Ah, OK. Sorry, I am new to contributing to the perl5 core. I prefer to
use the email address <doug@​somethingdoug.com>. I do have a common name,
which is why I usually include my middle name (​:

@p5pRT
Copy link
Author

p5pRT commented Sep 10, 2011

@cpansprout - Status changed from 'open' to 'resolved'

@p5pRT p5pRT closed this as completed Sep 10, 2011
@p5pRT
Copy link
Author

p5pRT commented Sep 11, 2011

From doug@somethingdoug.com

Actually, that is a different Douglas Wilson (​: I have the CPAN ID DOUGDUDE.

-----Original Message-----
From​: Father Chrysostomos via RT
Sent​: Saturday, September 10, 2011 2​:55
To​: doug@​somethingdoug.com
Subject​: [perl #98812] File​::Glob Windows home directory expansion

On Fri Sep 09 22​:58​:37 2011, doug@​somethingdoug.com wrote​:

This is a bug report for perl from doug@​somethingdoug.com,
generated with the help of perlbug 1.39 running under perl 5.12.3.

-----------------------------------------------------------------
The currently bundled File​::Glob will expand a tilde character
to the current user's home directory. Now, the method this uses
is to check the HOME environment variable (which is does not
exist by default on Windows) and then using password file
functions (which are not implemented on Windows). I am including
a patch here that on Windows will fallback to expanding the home
directory from the USERPROFILE environment variable, which exists
by default on Windows and serves the same purpose as HOME.

Here is a patch I have made to add this support. I tested it on
Windows 7 and Ubuntu 11.04. It is based off the blead branch.

Thank you. I’ve just pushed that to the smoke-me/tilde branch.

BTW, are you the same Douglas Wilson who has a CPAN ID of DOUGW?

@p5pRT
Copy link
Author

p5pRT commented Sep 11, 2011

From doug@somethingdoug.com

On Say Sep 10 12​:50 2011, Father Chrysostomos wrote​:

On Fri Sep 09 23​:55​:19 2011, sprout wrote​:

On Fri Sep 09 22​:58​:37 2011, doug@​somethingdoug.com wrote​:

Here is a patch I have made to add this support. I tested it on
Windows 7 and Ubuntu 11.04. It is based off the blead branch.

Thank you. I’ve just pushed that to the smoke-me/tilde branch.

And to blead as 528bd3c.

sprout, thank you for your quick inclusion of my patch (​: And yes,
my CPAN ID in indeed DOUGDUDE.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant