summaryrefslogtreecommitdiff
path: root/Master/tlpkg/TeXLive/TLUtils.pm
diff options
context:
space:
mode:
Diffstat (limited to 'Master/tlpkg/TeXLive/TLUtils.pm')
-rw-r--r--Master/tlpkg/TeXLive/TLUtils.pm36
1 files changed, 36 insertions, 0 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