View source: R/lockDirectory.R
lockDirectory | R Documentation |
Mark directories as locked or unlocked for thread-safe processing, using a standard naming scheme for the lock files.
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 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.
Concurrent read operations are also permitted by setting exclusive=FALSE
in ...
to define a shared lock..
The second 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 in the first 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 shared 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.