summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNorbert Preining <norbert@preining.info>2022-05-24 08:25:08 +0900
committerNorbert Preining <norbert@preining.info>2022-06-06 08:18:56 +0900
commit4f2710ca193f06720b768ea2e46b5f1611c39cfb (patch)
treec2f41fd42c7b238df829d4c5ee168208b27c6725
parentec738ee7ddadcc3854de750b368d2bbe6c400d8f (diff)
Unify homedir and tilde expansion
-rwxr-xr-xMaster/install-tl6
-rw-r--r--Master/tlpkg/TeXLive/TLUtils.pm36
-rw-r--r--Master/tlpkg/installer/install-menu-text.pl13
3 files changed, 44 insertions, 11 deletions
diff --git a/Master/install-tl b/Master/install-tl
index 43fb7271bd7..44748078016 100755
--- a/Master/install-tl
+++ b/Master/install-tl
@@ -309,7 +309,7 @@ our $opt_in_place = 0;
my $opt_verify_downloads;
# debug options
my $opt_debug_fakenet = 0;
-my $opt_debug_setup_vars = 1;
+my $opt_debug_setup_vars = 0;
# show all options even those not relevant for that arch
$::opt_all_options = 0;
@@ -956,6 +956,10 @@ sub do_installation {
&& $vars{'n_collections_selected'} <= 0) {
tldie("$0: Nothing selected, nothing to install, exiting!\n");
}
+ # expand ~ in various variables just to be sure
+ for my $v (qw/TEXDIR TEXMFLOCAL TEXMFSYSVAR TEXMFSYSCONFIG TEXMFHOME TEXMFVAR TEXMFCONFIG/) {
+ $vars{$v} = TeXLive::TLUtils::expand_tilde($vars{$v}) if ($vars{$v});
+ }
# maybe_make_ro tests for admin, local drive and NTFS before proceeding.
# making the root read-only automatically locks everything below it.
# do TEXDIR now, before it loses its final slash
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'};
}