Open
Description
From square/okhttp#8209
Want to be able to use this without making assumptions about the FileSystem
fun fileSystemLock(
directory: Path,
): Closeable {
val lockFile = directory / "lock"
lockFile.toFile().createNewFile()
val channel = FileChannel.open(lockFile.toNioPath(), StandardOpenOption.APPEND)
checkNotNull(channel.tryLock()) {
"Cache already open at '$directory' in another process"
}
return okio.Closeable {
channel.close()
}
}