lockDirectory {dir.expiry}R Documentation

Lock and unlock directories

Description

Mark directories as locked or unlocked for thread-safe processing, using a standard naming scheme for the lock files.

Usage

lockDirectory(path, ...)

unlockDirectory(lock.info, clear = TRUE, ...)

Arguments

path

String containing the path to a versioned directory. The dirname should be the package cache while the basename should be a version number.

...

For lockDirectory, further arguments to pass to lock.

For unlockDirectory, further arguments to pass to clearDirectories.

lock.info

The list returned by lockDirectory.

clear

Logical scalar indicating whether to remove expired versions via clearDirectories.

Details

lockDirectory actually creates two locks:

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.

Value

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.

Author(s)

Aaron Lun

Examples

# 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)


[Package dir.expiry version 1.2.0 Index]