From dcaa912318e63f66b817cbfe4a8a490aac73f970 Mon Sep 17 00:00:00 2001 From: Yihui Xie Date: Wed, 13 May 2020 10:04:08 -0500 Subject: [PATCH] a more robust fix to #181: make sure Sys.which('tlmgr') is a symlink created by `tlmgr path add` (not 100% sure, but should be fairly sure under these conditions) --- R/tlmgr.R | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/R/tlmgr.R b/R/tlmgr.R index 7184a26c8..7507b4d66 100644 --- a/R/tlmgr.R +++ b/R/tlmgr.R @@ -116,13 +116,20 @@ tlmgr_install = function(pkgs = character(), usermode = FALSE, path = !usermode } if (Sys.which('gs') == '') warning('GhostScript is required for the epstopdf package.') } - # only run `tlmgr path add` if the symlink for tlmgr exists under - # /usr/local/bin; it may not exist when TinyTeX is installed with --no-path - if (missing(path)) path = path && file.exists('/usr/local/bin/tlmgr') + if (missing(path)) path = path && need_add_path() if (path) tlmgr_path('add') invisible(res) } +# we should run `tlmgr path add` after `tlmgr install` only when the `tlmgr` +# found from PATH is a symlink that links to another symlink (typically under +# TinyTeX/bin/platform/tlmgr, which is typically a symlink to tlmgr.pl) +need_add_path = function() { + (p <- Sys.which('tlmgr')) != '' && is_writable(p) && + (p2 <- Sys.readlink(p)) != '' && basename(Sys.readlink(p2)) == 'tlmgr.pl' && + basename(dirname(dirname(p2))) == 'bin' +} + is_writable = function(p) file.access(p, 2) == 0 # check of certain LaTeX packages are installed: if installed, `tlmgr info pkgs`