From 2316ee54ad4005d9494875ef8bac20ceae41d82c Mon Sep 17 00:00:00 2001 From: bnomei Date: Wed, 14 Aug 2024 14:46:19 +0200 Subject: [PATCH] :bug: un-/lock handling --- classes/Nitro.php | 6 +++--- classes/Nitro/SingleFileCache.php | 9 +++++++-- composer.json | 2 +- composer.lock | 29 ++++++++++++++--------------- index.php | 2 +- vendor/composer/installed.php | 8 ++++---- 6 files changed, 30 insertions(+), 26 deletions(-) diff --git a/classes/Nitro.php b/classes/Nitro.php index 05fdc8d..ef51f7b 100644 --- a/classes/Nitro.php +++ b/classes/Nitro.php @@ -55,10 +55,10 @@ public function dir(): DirInventory return $this->dirInventory; } - public function cache(): SingleFileCache + public function cache(array $options = []): SingleFileCache { - if (! $this->singleFileCache) { - $this->singleFileCache = new SingleFileCache($this->options); + if (! $this->singleFileCache || ! empty($options)) { + $this->singleFileCache = new SingleFileCache($this->options + $options); } return $this->singleFileCache; diff --git a/classes/Nitro/SingleFileCache.php b/classes/Nitro/SingleFileCache.php index a12f417..f2c1d8d 100644 --- a/classes/Nitro/SingleFileCache.php +++ b/classes/Nitro/SingleFileCache.php @@ -31,6 +31,8 @@ public function __construct(array $options = []) 'debug' => option('debug'), ], $options); + $this->atomic(); + $data = F::exists($this->file()) ? F::read($this->file()) : null; $data = $data ? json_decode($data, true) : null; if (is_array($data)) { @@ -40,8 +42,6 @@ public function __construct(array $options = []) if ($this->options['auto-clean-cache']) { $this->clean(); } - - $this->atomic(); } public function __destruct() @@ -174,6 +174,11 @@ protected function file(?string $key = null): string public function write(bool $lock = true): bool { + // if is atomic but has no file, don't write + if ($this->options['atomic'] && ! F::exists($this->file().'.lock')) { + return false; + } + $this->unlock(); if ($this->isDirty === 0) { diff --git a/composer.json b/composer.json index 760aa26..7824d49 100644 --- a/composer.json +++ b/composer.json @@ -1,7 +1,7 @@ { "name": "bnomei/kirby-nitro", "type": "kirby-plugin", - "version": "2.0.0", + "version": "2.0.1", "description": "Nitro speeds up the loading of content in your Kirby project.", "license": "MIT", "authors": [ diff --git a/composer.lock b/composer.lock index 4d3f3fe..f372158 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "ad5f22f88551a76ab8d53f045f043b7a", + "content-hash": "1fd74cb26e8e617c922ff44c62606e93", "packages": [ { "name": "getkirby/composer-installer", @@ -3830,16 +3830,16 @@ }, { "name": "phpmyadmin/sql-parser", - "version": "5.9.0", + "version": "5.9.1", "source": { "type": "git", "url": "https://github.com/phpmyadmin/sql-parser.git", - "reference": "011fa18a4e55591fac6545a821921dd1d61c6984" + "reference": "169a9f11f1957ea36607c9b29eac1b48679f1ecc" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/phpmyadmin/sql-parser/zipball/011fa18a4e55591fac6545a821921dd1d61c6984", - "reference": "011fa18a4e55591fac6545a821921dd1d61c6984", + "url": "https://api.github.com/repos/phpmyadmin/sql-parser/zipball/169a9f11f1957ea36607c9b29eac1b48679f1ecc", + "reference": "169a9f11f1957ea36607c9b29eac1b48679f1ecc", "shasum": "" }, "require": { @@ -3857,8 +3857,7 @@ "phpstan/extension-installer": "^1.1", "phpstan/phpstan": "^1.9.12", "phpstan/phpstan-phpunit": "^1.3.3", - "phpunit/php-code-coverage": "*", - "phpunit/phpunit": "^7.5 || ^8.5 || ^9.5", + "phpunit/phpunit": "^8.5 || ^9.6", "psalm/plugin-phpunit": "^0.16.1", "vimeo/psalm": "^4.11", "zumba/json-serializer": "~3.0.2" @@ -3914,7 +3913,7 @@ "type": "other" } ], - "time": "2024-01-20T20:34:02+00:00" + "time": "2024-08-13T19:01:01+00:00" }, { "name": "phpstan/phpdoc-parser", @@ -5250,16 +5249,16 @@ }, { "name": "sebastian/comparator", - "version": "5.0.1", + "version": "5.0.2", "source": { "type": "git", "url": "https://github.com/sebastianbergmann/comparator.git", - "reference": "2db5010a484d53ebf536087a70b4a5423c102372" + "reference": "2d3e04c3b4c1e84a5e7382221ad8883c8fbc4f53" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/comparator/zipball/2db5010a484d53ebf536087a70b4a5423c102372", - "reference": "2db5010a484d53ebf536087a70b4a5423c102372", + "url": "https://api.github.com/repos/sebastianbergmann/comparator/zipball/2d3e04c3b4c1e84a5e7382221ad8883c8fbc4f53", + "reference": "2d3e04c3b4c1e84a5e7382221ad8883c8fbc4f53", "shasum": "" }, "require": { @@ -5270,7 +5269,7 @@ "sebastian/exporter": "^5.0" }, "require-dev": { - "phpunit/phpunit": "^10.3" + "phpunit/phpunit": "^10.4" }, "type": "library", "extra": { @@ -5315,7 +5314,7 @@ "support": { "issues": "https://github.com/sebastianbergmann/comparator/issues", "security": "https://github.com/sebastianbergmann/comparator/security/policy", - "source": "https://github.com/sebastianbergmann/comparator/tree/5.0.1" + "source": "https://github.com/sebastianbergmann/comparator/tree/5.0.2" }, "funding": [ { @@ -5323,7 +5322,7 @@ "type": "github" } ], - "time": "2023-08-14T13:18:12+00:00" + "time": "2024-08-12T06:03:08+00:00" }, { "name": "sebastian/complexity", diff --git a/index.php b/index.php index 65bfb2e..867d327 100644 --- a/index.php +++ b/index.php @@ -76,7 +76,7 @@ function nitro(): \Bnomei\Nitro 'command' => static function ($cli): void { $cli->out('🛼 Unlocking...'); - $success = nitro()->cache()->unlock(); + $success = nitro()->cache(['atomic' => false, 'auto-clean-cache' => false])->unlock(); $success ? $cli->success('🔓 Unlocked.') : $cli->error('❌ Failed.'); // the flush is necessary as the current instance might not have valid data anymore diff --git a/vendor/composer/installed.php b/vendor/composer/installed.php index 8f6c67e..f05ced9 100644 --- a/vendor/composer/installed.php +++ b/vendor/composer/installed.php @@ -1,8 +1,8 @@ array( 'name' => 'bnomei/kirby-nitro', - 'pretty_version' => '2.0.0', - 'version' => '2.0.0.0', + 'pretty_version' => '2.0.1', + 'version' => '2.0.1.0', 'reference' => null, 'type' => 'kirby-plugin', 'install_path' => __DIR__ . '/../../', @@ -11,8 +11,8 @@ ), 'versions' => array( 'bnomei/kirby-nitro' => array( - 'pretty_version' => '2.0.0', - 'version' => '2.0.0.0', + 'pretty_version' => '2.0.1', + 'version' => '2.0.1.0', 'reference' => null, 'type' => 'kirby-plugin', 'install_path' => __DIR__ . '/../../',