From fcb655877cc8135885a3d6d255ba72f0f2b039af Mon Sep 17 00:00:00 2001 From: Kieran Date: Mon, 13 Feb 2023 22:29:35 +0000 Subject: [PATCH] [9.x] Fix race condition in locks issued by the file cache driver (#46011) * Fix file lock race condition * wip * revert first commit * wip --- src/Illuminate/Cache/FileLock.php | 16 ++++++++++++++++ src/Illuminate/Cache/FileStore.php | 27 ++++++++++++++++++++++++++- 2 files changed, 42 insertions(+), 1 deletion(-) create mode 100644 src/Illuminate/Cache/FileLock.php diff --git a/src/Illuminate/Cache/FileLock.php b/src/Illuminate/Cache/FileLock.php new file mode 100644 index 000000000000..a5638b6832f4 --- /dev/null +++ b/src/Illuminate/Cache/FileLock.php @@ -0,0 +1,16 @@ +store->add($this->name, $this->owner, $this->seconds); + } +} diff --git a/src/Illuminate/Cache/FileStore.php b/src/Illuminate/Cache/FileStore.php index 42292295f0ce..6a6feb8a545f 100755 --- a/src/Illuminate/Cache/FileStore.php +++ b/src/Illuminate/Cache/FileStore.php @@ -12,7 +12,7 @@ class FileStore implements Store, LockProvider { - use InteractsWithTime, HasCacheLock, RetrievesMultipleKeys; + use InteractsWithTime, RetrievesMultipleKeys; /** * The Illuminate Filesystem instance. @@ -200,6 +200,31 @@ public function forever($key, $value) return $this->put($key, $value, 0); } + /** + * Get a lock instance. + * + * @param string $name + * @param int $seconds + * @param string|null $owner + * @return \Illuminate\Contracts\Cache\Lock + */ + public function lock($name, $seconds = 0, $owner = null) + { + return new FileLock($this, $name, $seconds, $owner); + } + + /** + * Restore a lock instance using the owner identifier. + * + * @param string $name + * @param string $owner + * @return \Illuminate\Contracts\Cache\Lock + */ + public function restoreLock($name, $owner) + { + return $this->lock($name, 0, $owner); + } + /** * Remove an item from the cache. *