Skip to content

Commit

Permalink
Disallow installation of also a source package on Windows when it is …
Browse files Browse the repository at this point in the history
…in use

(related to PR#17478).


git-svn-id: https://svn.r-project.org/R/trunk@76693 00db46b3-68df-0310-9c12-caf00c1e9a41
  • Loading branch information
kalibera committed Jun 11, 2019
1 parent 0434ff2 commit ebef820
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 17 deletions.
19 changes: 19 additions & 0 deletions src/library/utils/R/packages2.R
Original file line number Diff line number Diff line change
Expand Up @@ -244,6 +244,25 @@ install.packages <-
}
}

if (.Platform$OS.type == "windows" && length(pkgs)) {
## look for package in use.
pkgnames <- get_package_name(pkgs)
## there is no guarantee we have got the package name right:
## foo.zip might contain package bar or Foo or FOO or ....
## but we can't tell without trying to unpack it.
inuse <- search()
inuse <- sub("^package:", "", inuse[grep("^package:", inuse)])
inuse <- pkgnames %in% inuse
if(any(inuse)) {
warning(sprintf(ngettext(sum(inuse),
"package %s is in use and will not be installed",
"packages %s are in use and will not be installed"),
paste(sQuote(pkgnames[inuse]), collapse=", ")),
call. = FALSE, domain = NA, immediate. = TRUE)
pkgs <- pkgs[!inuse]
}
}

if(!length(pkgs)) return(invisible())

if(missing(lib) || is.null(lib)) {
Expand Down
16 changes: 0 additions & 16 deletions src/library/utils/R/windows/install.packages.R
Original file line number Diff line number Diff line change
Expand Up @@ -205,25 +205,9 @@ unpackPkgZip <- function(pkg, pkgname, lib, libs_only = FALSE,
lock = getOption("install.lock", FALSE), quiet = FALSE, ...)
{
if(!length(pkgs)) return(invisible())
## look for package in use.
pkgnames <- basename(pkgs)
pkgnames <- sub("\\.zip$", "", pkgnames)
pkgnames <- sub("_[0-9.-]+$", "", pkgnames)
## there is no guarantee we have got the package name right:
## foo.zip might contain package bar or Foo or FOO or ....
## but we can't tell without trying to unpack it.
inuse <- search()
inuse <- sub("^package:", "", inuse[grep("^package:", inuse)])
inuse <- pkgnames %in% inuse
if(any(inuse)) {
warning(sprintf(ngettext(sum(inuse),
"package %s is in use and will not be installed",
"packages %s are in use and will not be installed"),
paste(sQuote(pkgnames[inuse]), collapse=", ")),
call. = FALSE, domain = NA, immediate. = TRUE)
pkgs <- pkgs[!inuse]
pkgnames <- pkgnames[!inuse]
}

if(is.null(contriburl)) {
for(i in seq_along(pkgs)) {
Expand Down
2 changes: 1 addition & 1 deletion src/library/utils/man/install.packages.Rd
Original file line number Diff line number Diff line change
Expand Up @@ -256,7 +256,7 @@ install.packages(pkgs, lib, repos = getOption("repos"),
installing from a repository or tarballs, although it will be a little
slower.)

When installing a binary package, \code{install.packages} will abort
When installing a package on Windows, \code{install.packages} will abort
the install if it detects that the package is already installed and is
currently in use. In some circumstances (e.g., multiple instances of
\R running at the same time and sharing a library) it will not detect a
Expand Down

0 comments on commit ebef820

Please sign in to comment.