From 9fd684ef8ddc8bf81ca59669bc3e6fa5cb9261bd Mon Sep 17 00:00:00 2001 From: Denys Moskovchenko Date: Fri, 9 Sep 2022 19:15:11 +0300 Subject: [PATCH 1/2] Set permissions for new directory via `chmod()` --- CHANGELOG.md | 2 +- src/FileCache.php | 12 +++++++++++- tests/FileCacheTest.php | 4 ++-- 3 files changed, 14 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index f5a71d3..19d41c6 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,7 +2,7 @@ ## 2.0.1 under development -- no changes in this release. +- Chg #47: Set permissions for new directory via `chmod()` (@dehbka) ## 2.0.0 July 21, 2022 diff --git a/src/FileCache.php b/src/FileCache.php index 40e34a7..5e3badf 100644 --- a/src/FileCache.php +++ b/src/FileCache.php @@ -343,7 +343,17 @@ private function normalizeTtl(null|int|string|DateInterval $ttl = null): ?int */ private function createDirectoryIfNotExists(string $path): bool { - return is_dir($path) || (!is_file($path) && mkdir($path, $this->directoryMode, true) && is_dir($path)); + if (is_dir($path)) { + return true; + } + + $result = !is_file($path) && mkdir(directory: $path, recursive: true) && is_dir($path); + + if ($result) { + chmod($path, $this->directoryMode); + } + + return $result; } /** diff --git a/tests/FileCacheTest.php b/tests/FileCacheTest.php index 319b572..6178bfd 100644 --- a/tests/FileCacheTest.php +++ b/tests/FileCacheTest.php @@ -440,7 +440,7 @@ public function testDirMode(): void } $cache = new FileCache($this->tmpDir); - $newCache = $cache->withDirectoryMode(0755); + $newCache = $cache->withDirectoryMode(0777); $this->assertInstanceOf(FileCache::class, $newCache); $this->assertNotSame($cache, $newCache); @@ -451,7 +451,7 @@ public function testDirMode(): void $cacheFile = $this->invokeMethod($newCache, 'getCacheFile', ['a']); $permissions = substr(sprintf('%o', fileperms(dirname($cacheFile))), -4); - $this->assertEquals('0755', $permissions); + $this->assertEquals('0777', $permissions); } public function testDirectoryLevel(): void From e330d419b08b3851dd8ce3694dee593069f1f7b2 Mon Sep 17 00:00:00 2001 From: Sergei Predvoditelev Date: Sun, 18 Sep 2022 16:32:10 +0300 Subject: [PATCH 2/2] Fix changelog --- CHANGELOG.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 19d41c6..2e26ea5 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,7 +2,7 @@ ## 2.0.1 under development -- Chg #47: Set permissions for new directory via `chmod()` (@dehbka) +- Bug #47: Set permissions for new directory via `chmod()` (@dehbka) ## 2.0.0 July 21, 2022 @@ -10,7 +10,7 @@ ## 1.0.1 March 23, 2021 -- Chg: Adjust config for new config plugin (samdark) +- Chg: Adjust config for new config plugin (@samdark) ## 1.0.0 February 02, 2021