From 30e080c4d3f58962a65b7e7cfc1c6d5a6ee44019 Mon Sep 17 00:00:00 2001 From: Chirag Aggarwal Date: Mon, 30 Mar 2026 14:04:20 +0530 Subject: [PATCH] Address review: race-safe mkdir and separate encode/write errors --- src/Appwrite/Platform/Tasks/Specs.php | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/src/Appwrite/Platform/Tasks/Specs.php b/src/Appwrite/Platform/Tasks/Specs.php index 336f578a05..6453977a39 100644 --- a/src/Appwrite/Platform/Tasks/Specs.php +++ b/src/Appwrite/Platform/Tasks/Specs.php @@ -351,10 +351,8 @@ class Specs extends Action $email = System::getEnv('_APP_SYSTEM_TEAM_EMAIL', APP_EMAIL_TEAM); $specsDir = __DIR__ . '/../../../../app/config/specs'; - if (!is_dir($specsDir)) { - if (!mkdir($specsDir, 0755, true)) { - throw new Exception('Failed to create specs directory: ' . $specsDir); - } + if (!is_dir($specsDir) && !@mkdir($specsDir, 0755, true) && !is_dir($specsDir)) { + throw new Exception('Failed to create specs directory: ' . $specsDir); } foreach ($platforms as $platform) { @@ -479,7 +477,11 @@ class Specs extends Action unset($parsedSpecs); - if ($encodedSpecs === false || !file_put_contents($path, $encodedSpecs)) { + if ($encodedSpecs === false) { + throw new Exception('Failed to encode ' . ($mocks ? 'mocks ' : '') . 'spec file: ' . \json_last_error_msg()); + } + + if (\file_put_contents($path, $encodedSpecs) === false) { throw new Exception('Failed to save ' . ($mocks ? 'mocks ' : '') . 'spec file: ' . $path); }