View source: R/lockDirectory.R
| lockDirectory | R Documentation |
Lock and unlock the package and version directories for thread-safe processing.
lockDirectory(path, ...)
unlockDirectory(lock.info, clear = TRUE, ...)
path |
String containing the path to a versioned directory.
The |
... |
For For |
lock.info |
The list returned by |
clear |
Logical scalar indicating whether to remove expired versions via |
lockDirectory actually creates two locks:
The first āVā lock is applied to the versioned directory (i.e., basename(path)) within the package cache (i.e., dirname(path)).
This provides thread-safe read/write on its contents, protecting against other processes that want to write to the same versioned directory.
If the caller is only reading from path, they can set exclusive=FALSE in ... to define a shared lock for concurrent reads across multiple processes.
The second āPā lock is applied to the package cache and is always a shared lock, regardless of the contents of ....
This provides thread-safe access to the lock file used by the V lock, protecting it from deletion when the relevant directory expires in clearDirectories.
If dirname(path) does not exist, it will be created by lockDirectory.
clearDirectories is called in unlockDirectory as the former needs to hold an exclusive lock on the package cache.
Thus, the clearing can only be performed after the P lock created by lockDirectory is released.
lockDirectory returns a list of locking information, including lock handles generated by the filelock package.
unlockDirectory unlocks the handles generated by lockDirectory.
If clear=TRUE, versioned directories that have expired are removed by clearDirectories.
It returns a NULL invisibly.
Aaron Lun
# Creating the relevant directories.
cache.dir <- tempfile(pattern="expired_demo")
version <- package_version("1.11.0")
handle <- lockDirectory(file.path(cache.dir, version))
handle
unlockDirectory(handle)
list.files(cache.dir)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.