rstudio / plumber
1
# Taken from shiny
2
# @author shiny authors
3
resolve_path <- function(dir, relpath) {
4 1
  abs.path <- file.path(dir, relpath)
5 1
  if (!file.exists(abs.path))
6 1
    return(NULL)
7 1
  abs.path <- normalizePath(abs.path, winslash='/', mustWork=TRUE)
8 1
  dir <- normalize_dir_path(dir)
9 1
  if (nchar(abs.path) <= nchar(dir) + 1)
10 0
    return(NULL)
11 1
  if (substr(abs.path, 1, nchar(dir)) != dir ||
12 1
      substr(abs.path, nchar(dir)+1, nchar(dir)+1) != '/') {
13 0
    return(NULL)
14
  }
15 1
  return(abs.path)
16
}
17

18
normalize_dir_path <- function(dir) {
19 1
  dir <- normalizePath(dir, winslash = '/', mustWork = TRUE)
20
  # trim the possible trailing slash under Windows (#306)
21 1
  if (isWindows()) {
22 0
    dir <- sub('/$', '', dir)
23
  }
24 1
  dir
25
}

Read our documentation on viewing source code .

Loading