Skip to content

Commit

Permalink
For #1026. Update repair_path() to work with network paths, add test.
Browse files Browse the repository at this point in the history
  • Loading branch information
bschneidr committed Nov 19, 2024
1 parent bceb482 commit bdb6042
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 2 deletions.
5 changes: 3 additions & 2 deletions R/utils.R
Original file line number Diff line number Diff line change
Expand Up @@ -128,8 +128,9 @@ repair_path <- function(path) {
}
path <- path.expand(path)
path <- gsub("\\\\", "/", path)
# WSL cmdstan path is a network path and needs the leading //
path <- gsub("//(?!wsl)", "/", path, perl = TRUE)
# Network paths (such as the cmdstan path on WSL) need the leading //
# https://github.com/stan-dev/cmdstanr/issues/1026
path <- gsub("(?<!^)//", "/", path, perl = TRUE)
# remove trailing "/"
path <- gsub("/$","", path)
path
Expand Down
2 changes: 2 additions & 0 deletions tests/testthat/test-utils.R
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,8 @@ test_that("cmdstan_diagnose works if bin/diagnose deleted file", {
test_that("repair_path() fixes slashes", {
# all slashes should be single "/", and no trailing slash
expect_equal(repair_path("a//b\\c/"), "a/b/c")
# but leading double slash is needed for UNC paths on (e.g. the cmdstan path on WSL)
expect_equal(repair_path("\\\\wsl//my-project//"), "//wsl/my-project")
})

test_that("repair_path works with zero length path or non-string path", {
Expand Down

0 comments on commit bdb6042

Please sign in to comment.