Skip to content

Avoid unlocking NULL#754

Merged
gaborcsardi merged 1 commit intor-lib:mainfrom
Fan-iX:main
Apr 28, 2025
Merged

Avoid unlocking NULL#754
gaborcsardi merged 1 commit intor-lib:mainfrom
Fan-iX:main

Conversation

@Fan-iX
Copy link
Copy Markdown
Contributor

@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.
@gaborcsardi gaborcsardi merged commit 15ae56e into r-lib:main Apr 28, 2025
14 checks passed
@gaborcsardi
Copy link
Copy Markdown
Member

Thanks!

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.

2 participants