Skip to content

Commit

Permalink
also check the custom installation path for spaces and non-ASCII char…
Browse files Browse the repository at this point in the history
…acters on Windows
  • Loading branch information
yihui committed Nov 17, 2023
1 parent d0e7665 commit 8461d31
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 5 deletions.
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Package: tinytex
Type: Package
Title: Helper Functions to Install and Maintain TeX Live, and Compile LaTeX Documents
Version: 0.48.3
Version: 0.48.4
Authors@R: c(
person("Yihui", "Xie", role = c("aut", "cre", "cph"), email = "[email protected]", comment = c(ORCID = "0000-0003-0645-5666")),
person(given = "Posit Software, PBC", role = c("cph", "fnd")),
Expand Down
22 changes: 18 additions & 4 deletions R/install.R
Original file line number Diff line number Diff line change
Expand Up @@ -52,15 +52,17 @@ install_tinytex = function(
"the installation is aborted."
)
if (!is.logical(force)) stop('The argument "force" must take a logical value.')
continue_inst = function() {
tolower(substr(readline('Continue the installation anyway? (Y/N) '), 1, 1)) == 'y'
}
# if tlmgr is detected in the system, ask in interactive mode whether to
# continue the installation, and stop in non-interactive() mode
p = which_bin(c('tlmgr', 'pdftex', 'xetex', 'luatex'))
p = p[p != '']
if (!force && length(p)) {
message("Found '", p[1], "', which indicates a LaTeX distribution may have existed in the system.")
if (interactive()) {
if (tolower(substr(readline('Continue the installation anyway? (Y/N) '), 1, 1)) != 'y')
return(invisible(''))
if (!continue_inst()) return(invisible(''))
} else stop(
'If you want to force installing TinyTeX anyway, use tinytex::install_tinytex(force = TRUE).'
)
Expand All @@ -77,8 +79,17 @@ install_tinytex = function(
if (dir != '') {
dir = gsub('[/\\]+$', '', dir) # remove trailing slashes
check_dir(dir)
dir = xfun::normalize_path(dir)
if (is_windows() && !valid_path(dir)) {
warning(
"The directory path '", dir, "' contains spaces or non-ASCII characters, ",
"and TinyTeX may not work. Please use a path with pure ASCII characters and no spaces.",
immediate. = TRUE
)
if (!force && !(interactive() && continue_inst())) return(invisible(dir))
}
unlink(dir, recursive = TRUE)
user_dir = normalizePath(dir, mustWork = FALSE)
user_dir = dir
}

repository = normalize_repo(repository)
Expand Down Expand Up @@ -218,13 +229,16 @@ win_app_dir = function(s) {
)
return(d2)
}
if (grepl('^[!-~]+$', d)) return(d2) # path is pure ASCII and has no spaces
if (valid_path(d)) return(d2)
}
d = Sys.getenv('ProgramData')
if (d == '') stop("The environment variable 'ProgramData' is not set.")
file.path(d, s)
}

# test if path is pure ASCII and has no spaces
valid_path = function(x) grepl('^[!-~]+$', x)

# check if /usr/local/bin on macOS is writable
check_local_bin = function() {
if (os_index != 3 || is_writable(p <- '/usr/local/bin')) return()
Expand Down

0 comments on commit 8461d31

Please sign in to comment.