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();