Skip to content

Commit 3ec64d0

Browse files
committed
Lockdir prefix for install packages
Some distributed file systems do not support opening files in append mode. These file systems are often used in data analysis cloud platforms. R package installation relies on appending to files, for instance collating R code or when installing help pages. Therefore, packages can't be installed in those filesystems. Instead, users are forced to install packages into a local directory and copy them afterwards. However, the current package installation procedure already uses a 00LOCK directory to install packages there, before copying them to the final library directory. By globally modifying the location of the 00LOCK directory, it is possible to use a local filesystem to install packages, where append is allowed. The installation process takes care of copying the resulting package into the final out directory. This change introduces the environment variable PKG_LOCKDIR_PREFIX that, when set to a directory like "/tmp/r-lockdir", uses that root path to create all 00LOCK folders. This allows to install packages on file systems that do not support opening files in append mode.
1 parent 2e7ed46 commit 3ec64d0

File tree

1 file changed

+32
-17
lines changed

1 file changed

+32
-17
lines changed

src/library/tools/R/install.R

Lines changed: 32 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,14 @@ if(FALSE) {
5454

5555
## global variables
5656
curPkg <- character() # list of packages in current pkg
57+
58+
## Path to where lockdirs will be created. If empty, use lib directory
59+
lockdir_prefix <- Sys.getenv("PKG_LOCKDIR_PREFIX", "")
60+
if (lockdir_prefix == "") lockdir_prefix <- NULL
61+
## The lockdir, relative to lockdir_prefix
5762
lockdir <- ""
63+
## The lockdir, including the prefix
64+
lockdir_with_prefix <- ""
5865
is_first_package <- TRUE
5966
stars <- "*"
6067
user.tmpdir <- Sys.getenv("PKG_BUILD_DIR")
@@ -105,8 +112,8 @@ if(FALSE) {
105112
}
106113

107114
if (nzchar(lockdir) &&
108-
dir.exists(lp <- file.path(lockdir, curPkg)) &&
109-
is_subdir(lp, lockdir)) {
115+
dir.exists(lp <- file.path(lockdir_with_prefix, curPkg)) &&
116+
is_subdir(lp, lockdir_with_prefix)) {
110117
starsmsg(stars, "restoring previous ", sQuote(pkgdir))
111118
if (WINDOWS) {
112119
file.copy(lp, dirname(pkgdir), recursive = TRUE,
@@ -134,7 +141,7 @@ if(FALSE) {
134141
if (lib == .Library && "html" %in% build_help_types)
135142
utils::make.packages.html(.Library, docdir = R.home("doc"))
136143
}
137-
if (nzchar(lockdir)) unlink(lockdir, recursive = TRUE)
144+
if (nzchar(lockdir_with_prefix)) unlink(lockdir_with_prefix, recursive = TRUE)
138145
}
139146

140147
do_cleanup_tmpdir <- function()
@@ -478,7 +485,7 @@ if(FALSE) {
478485
if (file.exists(file.path(instdir, "DESCRIPTION"))) {
479486
if (nzchar(lockdir))
480487
system(paste("mv -f", shQuote(instdir),
481-
shQuote(file.path(lockdir, pkg))))
488+
shQuote(file.path(lockdir_with_prefix, pkg))))
482489
dir.create(instdir, recursive = TRUE, showWarnings = FALSE)
483490
}
484491
TAR <- Sys.getenv("TAR", 'tar')
@@ -1041,9 +1048,9 @@ if(FALSE) {
10411048
if (more_than_libs) unlink(instdir, recursive = TRUE)
10421049
} else if (more_than_libs)
10431050
system(paste("mv -f ", shQuote(instdir),
1044-
shQuote(file.path(lockdir, pkg_name))))
1051+
shQuote(file.path(lockdir_with_prefix, pkg_name))))
10451052
else
1046-
file.copy(instdir, lockdir, recursive = TRUE,
1053+
file.copy(instdir, lockdir_with_prefix, recursive = TRUE,
10471054
copy.date = TRUE)
10481055
} else if (more_than_libs) unlink(instdir, recursive = TRUE)
10491056
if (more_than_libs && dir.exists(instdir))
@@ -1073,10 +1080,10 @@ if(FALSE) {
10731080
final_rlibs <- Sys.getenv("R_LIBS")
10741081
final_libpaths <- .libPaths()
10751082

1076-
instdir <- file.path(lockdir, "00new", pkg_name)
1083+
instdir <- file.path(lockdir_with_prefix, "00new", pkg_name)
10771084
Sys.setenv(R_PACKAGE_DIR = instdir)
10781085
dir.create(instdir, recursive = TRUE, showWarnings = FALSE)
1079-
lib <- file.path(lockdir, "00new")
1086+
lib <- file.path(lockdir_with_prefix, "00new")
10801087

10811088
rlibs <- if (nzchar(final_rlibs))
10821089
paste(lib, final_rlibs, sep = .Platform$path.sep)
@@ -2348,23 +2355,23 @@ if(FALSE) {
23482355
## if(!WINDOWS && !more_than_libs) test_load <- FALSE
23492356

23502357

2351-
mk_lockdir <- function(lockdir)
2358+
mk_lockdir <- function(lockdir_with_prefix)
23522359
{
2353-
if (file.exists(lockdir)) {
2360+
if (file.exists(lockdir_with_prefix)) {
23542361
message("ERROR: failed to lock directory ", sQuote(lib),
2355-
" for modifying\nTry removing ", sQuote(lockdir),
2362+
" for modifying\nTry removing ", sQuote(lockdir_with_prefix),
23562363
domain = NA)
23572364
do_cleanup_tmpdir()
23582365
do_exit(status = 3)
23592366
}
2360-
dir.create(lockdir, recursive = TRUE)
2361-
if (!dir.exists(lockdir)) {
2362-
message("ERROR: failed to create lock directory ", sQuote(lockdir),
2367+
dir.create(lockdir_with_prefix, recursive = TRUE)
2368+
if (!dir.exists(lockdir_with_prefix)) {
2369+
message("ERROR: failed to create lock directory ", sQuote(lockdir_with_prefix),
23632370
domain = NA)
23642371
do_cleanup_tmpdir()
23652372
do_exit(status = 3)
23662373
}
2367-
if (debug) starsmsg(stars, "created lock directory ", sQuote(lockdir))
2374+
if (debug) starsmsg(stars, "created lock directory ", sQuote(lockdir_with_prefix))
23682375
}
23692376

23702377
if (is.na(lock)) {
@@ -2373,7 +2380,11 @@ if(FALSE) {
23732380
}
23742381
if (lock && !pkglock) {
23752382
lockdir <- file.path(lib, "00LOCK")
2376-
mk_lockdir(lockdir)
2383+
if (!is.null(lockdir_prefix))
2384+
lockdir_with_prefix <- file.path(lockdir_prefix, lockdir)
2385+
else
2386+
lockdir_with_prefix <- lockdir
2387+
mk_lockdir(lockdir_with_prefix)
23772388
}
23782389
if (is.na(staged_install)) {
23792390
# environment variable intended as temporary
@@ -2418,7 +2429,11 @@ if(FALSE) {
24182429
for(pkg in allpkgs) {
24192430
if (pkglock) {
24202431
lockdir <- file.path(lib, paste0("00LOCK-", basename(pkg)))
2421-
mk_lockdir(lockdir)
2432+
if (!is.null(lockdir_prefix))
2433+
lockdir_with_prefix <- file.path(lockdir_prefix, lockdir)
2434+
else
2435+
lockdir_with_prefix <- file.path(lockdir)
2436+
mk_lockdir(lockdir_with_prefix)
24222437
}
24232438
do_install(pkg)
24242439
}

0 commit comments

Comments
 (0)