diff --git a/app/Services/Nzb/NzbService.php b/app/Services/Nzb/NzbService.php index 7f95fc4b3..e9ee00daa 100644 --- a/app/Services/Nzb/NzbService.php +++ b/app/Services/Nzb/NzbService.php @@ -368,6 +368,14 @@ class NzbService { $nzbPath = $this->siteNzbPath; + if ($createIfNotExist && ! File::isDirectory($nzbPath)) { + if (! File::makeDirectory($nzbPath, 0775, true) && ! File::isDirectory($nzbPath)) { // @phpstan-ignore booleanNot.alwaysTrue + throw new \RuntimeException(sprintf('Directory "%s" was not created', $nzbPath)); + } + + File::chmod($nzbPath, 02775); + } + for ($i = 0; $i < $levelsToSplit && $i < 32; $i++) { $nzbPath .= $releaseGuid[$i].'/'; diff --git a/tests/Unit/NzbServicePathResolutionTest.php b/tests/Unit/NzbServicePathResolutionTest.php index 7311809ef..96b5e1fba 100644 --- a/tests/Unit/NzbServicePathResolutionTest.php +++ b/tests/Unit/NzbServicePathResolutionTest.php @@ -124,7 +124,6 @@ final class NzbServicePathResolutionTest extends TestCase { $tempDir = sys_get_temp_dir().'/nzb-path-permissions-'.uniqid('', true); $basePath = $tempDir.'/'; - mkdir($basePath, 0775, true); $previousUmask = umask(0022); try { @@ -140,7 +139,7 @@ final class NzbServicePathResolutionTest extends TestCase $path = $service->buildNzbPath('4aabfe07-daff-4d28-9d1d-d2a4ab7b6511', 4, true); $this->assertSame($basePath.'4/a/a/b/', $path); - foreach ([$basePath.'4', $basePath.'4/a', $basePath.'4/a/a', $basePath.'4/a/a/b'] as $directory) { + foreach ([rtrim($basePath, '/'), $basePath.'4', $basePath.'4/a', $basePath.'4/a/a', $basePath.'4/a/a/b'] as $directory) { $this->assertSame(02775, fileperms($directory) & 07777); } } finally {