diff options
author | Norbert Preining <norbert@preining.info> | 2022-05-24 08:25:08 +0900 |
---|---|---|
committer | Norbert Preining <norbert@preining.info> | 2022-06-06 08:18:56 +0900 |
commit | 4f2710ca193f06720b768ea2e46b5f1611c39cfb (patch) | |
tree | c2f41fd42c7b238df829d4c5ee168208b27c6725 /Master/tlpkg | |
parent | ec738ee7ddadcc3854de750b368d2bbe6c400d8f (diff) |
Unify homedir and tilde expansion
Diffstat (limited to 'Master/tlpkg')
-rw-r--r-- | Master/tlpkg/TeXLive/TLUtils.pm | 36 | ||||
-rw-r--r-- | Master/tlpkg/installer/install-menu-text.pl | 13 |
2 files changed, 39 insertions, 10 deletions
diff --git a/Master/tlpkg/TeXLive/TLUtils.pm b/Master/tlpkg/TeXLive/TLUtils.pm index 4751574b681..da229c052a0 100644 --- a/Master/tlpkg/TeXLive/TLUtils.pm +++ b/Master/tlpkg/TeXLive/TLUtils.pm @@ -43,6 +43,8 @@ C<TeXLive::TLUtils> - TeX Live infrastructure miscellany TeXLive::TLUtils::run_cmd($cmd [, @envvars ]); TeXLive::TLUtils::system_pipe($prog, $infile, $outfile, $removeIn, @args); TeXLive::TLUtils::diskfree($path); + TeXLive::TLUtils::get_user_home(); + TeXLive::TLUtils::expand_tilde($str); =head2 File utilities @@ -234,6 +236,8 @@ BEGIN { &run_cmd &system_pipe &diskfree + &get_user_home + &expand_tilde &announce_execute_actions &add_symlinks &remove_symlinks @@ -273,6 +277,9 @@ $::opt_verbosity = 0; # see process_logging_options our $SshURIRegex = '^((ssh|scp)://([^@]*)@([^/]*)/|([^@]*)@([^:]*):).*$'; +# only search for home directory once, and save expansion here +my $user_home_dir; + =head2 Platform detection =over 4 @@ -886,6 +893,35 @@ sub diskfree { } } +=item C<get_user_home()> + +Returns the current user's home directory (C<$HOME> on Unix, +C<$USERPROFILE> on Windows, and C<~> if none of the two are +set. + +=cut + +sub get_user_home { + return $user_home_dir if ($user_home_dir); + $user_home_dir = getenv('HOME'); + $user_home_dir = getenv('USERPROFILE') if win32(); + $user_home_dir ||= '~'; + return($user_home_dir); +} + +=item C<expand_tilde($str)> + +Expands initial C<~> with the user's home directory in C<$str>. + +=cut + +sub expand_tilde { + my $str = shift; + my $h = get_user_home(); + $str =~ s/^~/$h/; + return($str); +} + =back =head2 File utilities diff --git a/Master/tlpkg/installer/install-menu-text.pl b/Master/tlpkg/installer/install-menu-text.pl index a47eb11e467..f91cfd6f4cd 100644 --- a/Master/tlpkg/installer/install-menu-text.pl +++ b/Master/tlpkg/installer/install-menu-text.pl @@ -623,10 +623,7 @@ sub input_dirname $answer =~ s!\\!/!g if win32(); # switch to forward slashes if (!$noexpansion) { - my $home = getenv('HOME'); - $home = getenv('USERPROFILE') if win32(); - $home ||= '~'; - $answer =~ s/^~/$home/; # $home expansion + $answer = $TeXLive::TLUtils::expand_tilde($answer); } if ($answer !~ m/^~/) { @@ -844,9 +841,7 @@ EOF if (unix()) { if (("\u$answer" eq 'L') and !$vars{'instopt_portable'}) { - my $home = getenv('HOME'); - $home = getenv('USERPROFILE') if (win32()); - $home ||= '~'; + my $home = TeXLive::TLUtils::get_user_home(); toggle 'instopt_adjustpath'; if ($vars{'instopt_adjustpath'}) { print "New value for binary directory [$sys_bin]: "; @@ -874,9 +869,7 @@ EOF } } else { if (("\u$answer" eq 'L') and !$vars{'instopt_portable'}) { - my $home = getenv('HOME'); - $home = getenv('USERPROFILE') if (win32()); - $home ||= '~'; + my $home = TeXLive::TLUtils::get_user_home; toggle 'instopt_adjustpath'; return $command{'self'}; } |