Skip to content

Commit 95afa78

Browse files
author
Sergio Oller Moreno
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 d3f7a18 commit 95afa78

File tree

1 file changed

+28
-10
lines changed

1 file changed

+28
-10
lines changed

src/library/tools/R/install.R

+28-10
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,23 @@ 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 == "")
61+
lockdir_prefix <- NULL
62+
else
63+
lockdir_prefix <- path.expand(lockdir_prefix)
64+
## The lockdir, relative to lockdir_prefix
5765
lockdir <- ""
66+
## The lockdir, including the prefix
67+
lockdir_with_prefix <- ""
68+
get_lockdir_with_prefix <- function(lockdir) {
69+
if (!is.null(lockdir_prefix))
70+
file.path(lockdir_prefix, lockdir)
71+
else
72+
lockdir
73+
}
5874
is_first_package <- TRUE
5975
stars <- "*"
6076
user.tmpdir <- Sys.getenv("PKG_BUILD_DIR")
@@ -105,8 +121,8 @@ if(FALSE) {
105121
}
106122

107123
if (nzchar(lockdir) &&
108-
dir.exists(lp <- file.path(lockdir, curPkg)) &&
109-
is_subdir(lp, lockdir)) {
124+
dir.exists(lp <- file.path(lockdir_with_prefix, curPkg)) &&
125+
is_subdir(lp, lockdir_with_prefix)) {
110126
starsmsg(stars, "restoring previous ", sQuote(pkgdir))
111127
if (WINDOWS) {
112128
file.copy(lp, dirname(pkgdir), recursive = TRUE,
@@ -134,7 +150,7 @@ if(FALSE) {
134150
if (lib == .Library && "html" %in% build_help_types)
135151
utils::make.packages.html(.Library, docdir = R.home("doc"))
136152
}
137-
if (nzchar(lockdir)) unlink(lockdir, recursive = TRUE)
153+
if (nzchar(lockdir_with_prefix)) unlink(lockdir_with_prefix, recursive = TRUE)
138154
}
139155

140156
do_cleanup_tmpdir <- function()
@@ -478,7 +494,7 @@ if(FALSE) {
478494
if (file.exists(file.path(instdir, "DESCRIPTION"))) {
479495
if (nzchar(lockdir))
480496
system(paste("mv -f", shQuote(instdir),
481-
shQuote(file.path(lockdir, pkg))))
497+
shQuote(file.path(lockdir_with_prefix, pkg))))
482498
dir.create(instdir, recursive = TRUE, showWarnings = FALSE)
483499
}
484500
TAR <- Sys.getenv("TAR", 'tar')
@@ -1041,9 +1057,9 @@ if(FALSE) {
10411057
if (more_than_libs) unlink(instdir, recursive = TRUE)
10421058
} else if (more_than_libs)
10431059
system(paste("mv -f ", shQuote(instdir),
1044-
shQuote(file.path(lockdir, pkg_name))))
1060+
shQuote(file.path(lockdir_with_prefix, pkg_name))))
10451061
else
1046-
file.copy(instdir, lockdir, recursive = TRUE,
1062+
file.copy(instdir, lockdir_with_prefix, recursive = TRUE,
10471063
copy.date = TRUE)
10481064
} else if (more_than_libs) unlink(instdir, recursive = TRUE)
10491065
if (more_than_libs && dir.exists(instdir))
@@ -1073,10 +1089,10 @@ if(FALSE) {
10731089
final_rlibs <- Sys.getenv("R_LIBS")
10741090
final_libpaths <- .libPaths()
10751091

1076-
instdir <- file.path(lockdir, "00new", pkg_name)
1092+
instdir <- file.path(lockdir_with_prefix, "00new", pkg_name)
10771093
Sys.setenv(R_PACKAGE_DIR = instdir)
10781094
dir.create(instdir, recursive = TRUE, showWarnings = FALSE)
1079-
lib <- file.path(lockdir, "00new")
1095+
lib <- file.path(lockdir_with_prefix, "00new")
10801096

10811097
rlibs <- if (nzchar(final_rlibs))
10821098
paste(lib, final_rlibs, sep = .Platform$path.sep)
@@ -2373,7 +2389,8 @@ if(FALSE) {
23732389
}
23742390
if (lock && !pkglock) {
23752391
lockdir <- file.path(lib, "00LOCK")
2376-
mk_lockdir(lockdir)
2392+
lockdir_with_prefix <- get_lockdir_with_prefix(lockdir)
2393+
mk_lockdir(lockdir_with_prefix)
23772394
}
23782395
if (is.na(staged_install)) {
23792396
# environment variable intended as temporary
@@ -2418,7 +2435,8 @@ if(FALSE) {
24182435
for(pkg in allpkgs) {
24192436
if (pkglock) {
24202437
lockdir <- file.path(lib, paste0("00LOCK-", basename(pkg)))
2421-
mk_lockdir(lockdir)
2438+
lockdir_with_prefix <- get_lockdir_with_prefix(lockdir)
2439+
mk_lockdir(lockdir_with_prefix)
24222440
}
24232441
do_install(pkg)
24242442
}

0 commit comments

Comments
 (0)