Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit baca712

Browse files
kevinusheyjjallaire
authored andcommitted
check for 00LOCK directory when getting completions
1 parent 1ba21e4 commit baca712

File tree

1 file changed

+25
-5
lines changed

1 file changed

+25
-5
lines changed

src/cpp/session/modules/SessionCodeTools.R

Lines changed: 25 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -978,15 +978,35 @@
978978
# Explicitly load the library, and do everything we can to hide any
979979
# package startup messages (because we don't want to put non-JSON
980980
# on stdout)
981-
invisible(capture.output(suppressPackageStartupMessages(suppressWarnings(
982-
success <- library(x, character.only = TRUE, quietly = TRUE, logical.return = TRUE)
983-
))))
981+
invisible(capture.output(suppressPackageStartupMessages(suppressWarnings({
982+
983+
## Don't load the package if a corresponding 00LOCK directory exists.
984+
## This gives partial protection against attempting to load a package
985+
## while another R process is attempting to modify the library directory.
986+
has00LOCK <- FALSE
987+
for (libPath in .libPaths())
988+
{
989+
globalLockPath <- file.path(libPath, "00LOCK")
990+
pkgLockPath <- file.path(libPath, paste("00LOCK", basename(x), sep = "-"))
991+
if (file.exists(globalLockPath) || file.exists(pkgLockPath))
992+
{
993+
has00LOCK <- TRUE
994+
break
995+
}
996+
}
997+
998+
success <- if (has00LOCK)
999+
FALSE
1000+
else
1001+
library(x, character.only = TRUE, quietly = TRUE, logical.return = TRUE)
1002+
1003+
}))))
9841004

9851005
if (!success)
9861006
return(.rs.emptyFunctionInfo())
9871007

988-
# Get the exported items in the NAMESPACE (for search path + `::`
989-
# completions).
1008+
# Get the exported items in the NAMESPACE
1009+
# (for search path + `::` completions).
9901010
ns <- asNamespace(x)
9911011
exports <- getNamespaceExports(ns)
9921012
objects <- mget(exports, ns, inherits = TRUE)

0 commit comments

Comments
 (0)