Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Avoid unlocking NULL #754

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open

Avoid unlocking NULL #754

wants to merge 1 commit into from

Conversation

Fan-iX
Copy link

@Fan-iX Fan-iX commented Mar 13, 2025

When options(install.lock = FALSE) is set in .Rprofile, an error will be thrown when a package is successfully installed:

Error:                                           
! error in pak subprocess
Caused by error in `filelock::unlock(lockfile)`:
! `unlock()` needs a lock object, not a file name

This will abort the installation of other packages.


In install-binary.R, lock_cache will return NULL if getOption("install.lock")==FALSE, which is not a valid parameter for filelock::unlock :

lockfile <- lock_cache(lib_cache, pkg_name, getOption("install.lock"))
on.exit(filelock::unlock(lockfile), add = TRUE)

lock_cache <- function(cache, pkg_name, lock = TRUE) {
use_lock <- !identical(lock, FALSE)
my_lock <- NULL
if (use_lock) {
lockfile <- file.path(cache, sprintf("%s.lock", pkg_name))
# TODO: timeout and fail?
my_lock <- filelock::lock(lockfile)
}
my_lock
}

unlock <- function(lock) {
if (!inherits(lock, "filelock_lock")) {
stop("`unlock()` needs a lock object, not a file name")
}
.Call(c_filelock_unlock, lock)
}

This PR adds a NULL check to avoid the error.

When `options(install.lock = FALSE)` is set in `.Rprofile`, an error will be thrown when a package is successfully installed, aborting the installation of other packages.

```
Error:                                           
! error in pak subprocess
Caused by error in `filelock::unlock(lockfile)`:
! `unlock()` needs a lock object, not a file name
```

Add a NULL check to prevent this behavior.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant