|
7 | 7 | #' @param port Integer specifying the port to use for hosting the service. |
8 | 8 | #' If \code{NULL}, a free port is randomly selected. |
9 | 9 | #' @param wait Integer specifying the number of seconds to wait for service initialization. |
| 10 | +#' @param whitelist Character vector of users who are allowed to create symbolic links. |
| 11 | +#' If \code{NULL}, it defaults to the current user and all owners of \code{\link{tempdir}}. |
10 | 12 | #' @param overwrite Logical scalar indicating whether to redownload the Gobbler binary. |
11 | 13 | #' @param version String containing the desired version of the Gobbler binary. |
12 | 14 | #' |
|
25 | 27 | #' startSewerRat() # initialize a new instance. |
26 | 28 | #' |
27 | 29 | #' @export |
28 | | -startSewerRat <- function(db=tempfile(fileext=".sqlite3"), port=NULL, wait = 1, version = "1.2.0", overwrite = FALSE) { |
| 30 | +startSewerRat <- function(db=tempfile(fileext=".sqlite3"), port=NULL, wait = 1, version = "1.3.1", whitelist = NULL, overwrite = FALSE) { |
29 | 31 | if (!is.null(running$active)) { |
30 | 32 | return(list(new=FALSE, port=running$port, url=assemble_url(running$port))) |
31 | 33 | } |
@@ -73,9 +75,12 @@ startSewerRat <- function(db=tempfile(fileext=".sqlite3"), port=NULL, wait = 1, |
73 | 75 | if (is.null(port)) { |
74 | 76 | port <- choose_port() |
75 | 77 | } |
| 78 | + if (is.null(whitelist)) { |
| 79 | + whitelist <- choose_whitelist() |
| 80 | + } |
76 | 81 |
|
77 | 82 | script <- system.file("scripts", "deploy.sh", package="SewerRat", mustWork=TRUE) |
78 | | - pid <- system2(script, c(shQuote(exe), shQuote(db), shQuote(port)), stdout=TRUE) |
| 83 | + pid <- system2(script, c(shQuote(exe), shQuote(db), shQuote(port), shQuote(paste(whitelist, collapse=","))), stdout=TRUE) |
79 | 84 | Sys.sleep(wait) |
80 | 85 |
|
81 | 86 | process <- new.env() |
@@ -103,6 +108,20 @@ choose_port <- function() { |
103 | 108 | } |
104 | 109 | } |
105 | 110 |
|
| 111 | +choose_whitelist <- function() { |
| 112 | + whitelist <- Sys.info()[["user"]] |
| 113 | + tmp <- tempdir() |
| 114 | + repeat { |
| 115 | + whitelist <- union(whitelist, file.info(tmp)[["uname"]]) |
| 116 | + parent <- dirname(tmp) |
| 117 | + if (parent == tmp) { |
| 118 | + break |
| 119 | + } |
| 120 | + tmp <- parent |
| 121 | + } |
| 122 | + whitelist |
| 123 | +} |
| 124 | + |
106 | 125 | assemble_url <- function(port) { |
107 | 126 | paste0("http://0.0.0.0:", port) |
108 | 127 | } |
|
0 commit comments