Skip Menu |

This queue is for tickets about the Config-GitLike CPAN distribution.

Report information
The Basics
Id: 78350
Status: resolved
Priority: 0/
Queue: Config-GitLike

People
Owner: Nobody in particular
Requestors: peter [...] vereshagin.org
Cc:
AdminCc:

Bug Information
Severity: (no value)
Broken in: (no value)
Fixed in: 1.08



Subject: user_file() returns a shell-only tilde expansion
I use App::SD that inherits from Prophet with configuration based on Config::GitLike: $ SD_REPO=. sd config user.name='Peter Vereshagin' --user Can't open ~/.sdrc.lock for writing: No such file or directory I found this is because of Config::GitLike's ->user_file returns a file name to be used with the command execution supplied with a posix shell 'tilde expansion'. This can be handled by the both shell and a binary , e. g., git, to be executed from a configured application. I propose to use the $ENV{HOME} instead. This way the App::SD works 'just fine' I may know insufficient about yilde expansion for example it can use the getpwnam-like functino from posix to have the user's home directory name from system passwd database but I'm pretty sure that at least 'tilde expansion' doesn't work for perl's file system builtin subs. Patch supplied.
Subject: config-gitlike-tilde-expansion-00.patch
diff --git a/lib/Config/GitLike.pm b/lib/Config/GitLike.pm index 6052901..0c84c99 100644 --- a/lib/Config/GitLike.pm +++ b/lib/Config/GitLike.pm @@ -119,8 +119,10 @@ sub load_global { sub user_file { my $self = shift; + die 'No "HOME" environment variable is defined' + unless defined $ENV{HOME}; return - File::Spec->catfile( "~", "." . $self->confname ); + File::Spec->catfile( $ENV{HOME}, "." . $self->confname ); } sub load_user { diff --git a/t/t1500-user-file.t b/t/t1500-user-file.t index bff6ce4..0691613 100644 --- a/t/t1500-user-file.t +++ b/t/t1500-user-file.t @@ -17,6 +17,16 @@ use constant USER_FILE_BAD_PREFIX_LENGTH => length USER_FILE_BAD_PREFIX; # Continue till done_testing() use Test::More; +# But no tests if HOME can not be found in the environment +unless ( ( defined $ENV{'HOME'} ) and length $ENV{'HOME'} ) { + plan( + 'skip_all' => ( + 'User should supplky its home directory: " + ."the "HOME" environment variable should point there' + ) + ); +} + # Stuff being tested use Config::GitLike; @@ -40,5 +50,14 @@ isnt( "User config file does not start with literal '~': $user_file" ); +# Should contain a home directory +my $uf_good_prefix = $ENV{'HOME'}; +$uf_prefix = substr $user_file, 0 => length $uf_good_prefix; +is( + $uf_prefix => $uf_good_prefix, + "The ->user_file()' s result should start " + . "with the HOME environment variable" +); + # Every test is done done_testing();
From: peter [...] vereshagin.org
As a workaround one can use the symlink named '~' pointing to the home directory
attached is a test against the issue the patch's only the first clause is useful, the rest of the patch is about this test.
Subject: t1500-user-file.t
#!/usr/bin/env perl # Tests if the user's config directory6 isn't the literal '~' use strict; use warnings; # Required for comparison constants use File::Spec; ### CONSTANTS ### # # For user_file's bad prefix # Requires : File::Spec use constant USER_FILE_BAD_PREFIX => File::Spec->catfile( '~' => '.' ); use constant USER_FILE_BAD_PREFIX_LENGTH => length USER_FILE_BAD_PREFIX; # Continue till done_testing() use Test::More; # But no tests if HOME can not be found in the environment unless ( ( defined $ENV{'HOME'} ) and length $ENV{'HOME'} ) { plan( 'skip_all' => ( 'User should supplky its home directory: " ."the "HOME" environment variable should point there' ) ); } # Stuff being tested use Config::GitLike; ### MAIN ### # # Test if object can be created my $conf = Config::GitLike->new( confname => 'config' ); # Test if ->user_file works my $user_file; ok( $user_file = $conf->user_file(), 'user_file method works' ); # Prefix for comparison my $uf_prefix; ok( $uf_prefix = substr( $user_file, 0 => USER_FILE_BAD_PREFIX_LENGTH ), "Comparison prefix for '~/.' is: '$uf_prefix'" ); # Should not contain a literal '~' isnt( $uf_prefix => USER_FILE_BAD_PREFIX, "User config file does not start with literal '~': $user_file" ); # Should contain a home directory my $uf_good_prefix = $ENV{'HOME'}; $uf_prefix = substr $user_file, 0 => length $uf_good_prefix; is( $uf_prefix => $uf_good_prefix, "The ->user_file()' s result should start " . "with the HOME environment variable" ); # Every test is done done_testing();
Subject: Re: [rt.cpan.org #78350] user_file() returns a shell-only tilde expansion
Date: Sat, 28 Jul 2012 15:32:47 -0400
To: bug-Config-GitLike [...] rt.cpan.org
From: Alex Vandiver <alex [...] chmrr.net>
On Fri, 2012-07-13 at 07:53 -0400, http://peter.vereshagin.org/ via RT I use App::SD that inherits from Prophet with configuration based on Show quoted text
> Config::GitLike: > > $ SD_REPO=. sd config user.name='Peter Vereshagin' --user > Can't open ~/.sdrc.lock for writing: No such file or directory
I believe this bug was resolved in version 1.08, released 2012-02-15. Can you still replicate the failure with that version? - Alex
CC: alexmv [...] bestpractical.com
Subject: Re: [rt.cpan.org #78350] user_file() returns a shell-only tilde expansion
Date: Wed, 8 Aug 2012 23:29:04 +0400
To: Alex Vandiver via RT <bug-Config-GitLike [...] rt.cpan.org>
From: Peter Vereshagin <peter [...] vereshagin.org>
Hello. 2012/07/30 00:19:29 -0400 Alex Vandiver via RT <bug-Config-GitLike@rt.cpan.org> => To peter@vereshagin.org : Show quoted text
AVvR> <URL: https://rt.cpan.org/Ticket/Display.html?id=78350 > AVvR> AVvR> On Fri, 2012-07-13 at 07:53 -0400, http://peter.vereshagin.org/ via RT I AVvR> use App::SD that inherits from Prophet with configuration based on
AVvR> > Config::GitLike: AVvR> > AVvR> > $ SD_REPO=. sd config user.name='Peter Vereshagin' --user AVvR> > Can't open ~/.sdrc.lock for writing: No such file or directory
AVvR> AVvR> I believe this bug was resolved in version 1.08, released 2012-02-15.
Ouch. That's right. Show quoted text
AVvR> Can you still replicate the failure with that version?
No, sorry. I try that 'sd config' command now with 1.05 and 1.08 and everything is ok. I had no idea this was already recognized at the moment and do not remember the C:GL version I used ( took me long enough to discover that was C:GL ). I guess I had deen upgrading it from CPAN at the same moment thus didn't report the version here. -- Peter Vereshagin <peter@vereshagin.org> (http://vereshagin.org) pgp: A0E26627