Skip to content

Commit 8461d31

Browse files
committed
also check the custom installation path for spaces and non-ASCII characters on Windows
1 parent d0e7665 commit 8461d31

File tree

2 files changed

+19
-5
lines changed

2 files changed

+19
-5
lines changed

DESCRIPTION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
Package: tinytex
22
Type: Package
33
Title: Helper Functions to Install and Maintain TeX Live, and Compile LaTeX Documents
4-
Version: 0.48.3
4+
Version: 0.48.4
55
Authors@R: c(
66
person("Yihui", "Xie", role = c("aut", "cre", "cph"), email = "[email protected]", comment = c(ORCID = "0000-0003-0645-5666")),
77
person(given = "Posit Software, PBC", role = c("cph", "fnd")),

R/install.R

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -52,15 +52,17 @@ install_tinytex = function(
5252
"the installation is aborted."
5353
)
5454
if (!is.logical(force)) stop('The argument "force" must take a logical value.')
55+
continue_inst = function() {
56+
tolower(substr(readline('Continue the installation anyway? (Y/N) '), 1, 1)) == 'y'
57+
}
5558
# if tlmgr is detected in the system, ask in interactive mode whether to
5659
# continue the installation, and stop in non-interactive() mode
5760
p = which_bin(c('tlmgr', 'pdftex', 'xetex', 'luatex'))
5861
p = p[p != '']
5962
if (!force && length(p)) {
6063
message("Found '", p[1], "', which indicates a LaTeX distribution may have existed in the system.")
6164
if (interactive()) {
62-
if (tolower(substr(readline('Continue the installation anyway? (Y/N) '), 1, 1)) != 'y')
63-
return(invisible(''))
65+
if (!continue_inst()) return(invisible(''))
6466
} else stop(
6567
'If you want to force installing TinyTeX anyway, use tinytex::install_tinytex(force = TRUE).'
6668
)
@@ -77,8 +79,17 @@ install_tinytex = function(
7779
if (dir != '') {
7880
dir = gsub('[/\\]+$', '', dir) # remove trailing slashes
7981
check_dir(dir)
82+
dir = xfun::normalize_path(dir)
83+
if (is_windows() && !valid_path(dir)) {
84+
warning(
85+
"The directory path '", dir, "' contains spaces or non-ASCII characters, ",
86+
"and TinyTeX may not work. Please use a path with pure ASCII characters and no spaces.",
87+
immediate. = TRUE
88+
)
89+
if (!force && !(interactive() && continue_inst())) return(invisible(dir))
90+
}
8091
unlink(dir, recursive = TRUE)
81-
user_dir = normalizePath(dir, mustWork = FALSE)
92+
user_dir = dir
8293
}
8394

8495
repository = normalize_repo(repository)
@@ -218,13 +229,16 @@ win_app_dir = function(s) {
218229
)
219230
return(d2)
220231
}
221-
if (grepl('^[!-~]+$', d)) return(d2) # path is pure ASCII and has no spaces
232+
if (valid_path(d)) return(d2)
222233
}
223234
d = Sys.getenv('ProgramData')
224235
if (d == '') stop("The environment variable 'ProgramData' is not set.")
225236
file.path(d, s)
226237
}
227238

239+
# test if path is pure ASCII and has no spaces
240+
valid_path = function(x) grepl('^[!-~]+$', x)
241+
228242
# check if /usr/local/bin on macOS is writable
229243
check_local_bin = function() {
230244
if (os_index != 3 || is_writable(p <- '/usr/local/bin')) return()

0 commit comments

Comments
 (0)