getSyncFilePath($key); $fileUtils = abj_service('functions'); // Fixed: TOCTOU race condition - catch exception instead of check-then-read try { $contents = $fileUtils->readFileContents($filePath, false); return $contents; } catch (Exception $e) { // allow-silent-catch: TOCTOU-safe file read; missing or unreadable file returns empty, caller treats as "no lock owner" return ""; } } /** * @param string $key * @param string $uniqueID * @return void */ function writeOwnerToFile(string $key, string $uniqueID): void { $filePath = $this->getSyncFilePath($key); // Fixed: Check return value to handle write failures (disk full, permissions, etc.) $result = @file_put_contents($filePath, $uniqueID, LOCK_EX); if ($result === false) { throw new Exception("Failed to write lock file: " . $filePath); } } /** * @param string $uniqueID * @param string $key * @return void */ function releaseLock(string $uniqueID, string $key): void { $filePath = $this->getSyncFilePath($key); $fileUtils = abj_service('functions'); $fileUtils->safeUnlink($filePath); } }