Skip to content

Commit

Permalink
Merge pull request #31 from Enchufa2/fix/27
Browse files Browse the repository at this point in the history
more robust implementation of #27
  • Loading branch information
Enchufa2 authored Jun 24, 2021
2 parents 0aaa340 + 52934bd commit 70c06ec
Show file tree
Hide file tree
Showing 6 changed files with 20 additions and 32 deletions.
3 changes: 1 addition & 2 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@
- Fix spurious error with `options(bspm.always.install.deps=TRUE)` (#25).
- Ensure that `options(bspm.sudo=TRUE)` forces `sudo` unconditionally (#28).
- Add new `options(bspm.sudo.autodetect=TRUE)` (not set by default) to enable
passwordless `sudo` autodetection on package load, which then sets
`options(bspm.sudo=TRUE)` accordingly (#27).
passwordless `sudo` autodetection on every call (#27).

# bspm 0.3.7

Expand Down
9 changes: 8 additions & 1 deletion R/bridge.R
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@ backend_call <- function(method, pkgs=NULL) {
if (root())
return(invisible(root_call(method, pkgs)))

if (getOption("bspm.sudo", FALSE))
sudo <- getOption("bspm.sudo.autodetect", FALSE) && sudo_available()
if (sudo || getOption("bspm.sudo", FALSE))
return(invisible(sudo_call(method, pkgs)))

if (dbus_service_alive())
Expand Down Expand Up @@ -111,3 +112,9 @@ sudo_call <- function(method, pkgs=NULL) {

root_call(method, pkgs, sudo=sudo)
}

sudo_available <- function() {
nopass <- !system2nowarn("sudo", c("-n", "true"), stdout=FALSE, stderr=FALSE)
toolbox <- file.exists("/run/.toolboxenv") # see #27
nopass || toolbox
}
14 changes: 0 additions & 14 deletions R/init.R

This file was deleted.

8 changes: 4 additions & 4 deletions R/manager.R
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,10 @@
#' that, if you want to fall back to \code{sudo} in a non-interactive session,
#' you need to set \code{options(bspm.sudo=TRUE)}.
#'
#' If \code{options(bspm.sudo.autodetect=TRUE)} on start-up, \pkg{bspm} tries
#' to detect whether it is running in an environment where password-less
#' \code{sudo} can be used (e.g., in a containerized environment such as a
#' Fedora Toolbox), and then sets \code{options(bspm.sudo=TRUE)} accordingly.
#' If \code{options(bspm.sudo.autodetect=TRUE)}, \pkg{bspm} tries to detect
#' whether it is running in an environment where password-less \code{sudo} can
#' be used (e.g., in a containerized environment such as a Fedora Toolbox) for
#' every call, and then uses \code{sudo} accordingly.
#'
#' By default, if a package is not available in the system repositories, it is
#' installed from R's configured repositories along with all its dependencies.
Expand Down
10 changes: 3 additions & 7 deletions inst/tinytest/test_manager_ci.R
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,13 @@ if (!at_home() || !bspm:::root())

sudo.avail <- unname(nchar(Sys.which("sudo")) > 0)
in.toolbox <- file.exists("/run/.toolboxenv")
expect_false(getOption("bspm.sudo", FALSE))
bspm:::sudo_autodetect()
if (sudo.avail || in.toolbox) {
expect_true(getOption("bspm.sudo", FALSE))
expect_true(bspm:::sudo_available())
} else {
expect_false(getOption("bspm.sudo", FALSE))
expect_false(bspm:::sudo_available())
file.create("/run/.toolboxenv")
bspm:::sudo_autodetect()
expect_true(getOption("bspm.sudo", FALSE))
expect_true(bspm:::sudo_available())
}
options(bspm.sudo = NULL)

if (requireNamespace("Rcpp", quietly=TRUE))
exit_file("not in a clean environment")
Expand Down
8 changes: 4 additions & 4 deletions man/manager.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 70c06ec

Please sign in to comment.