Write USERS_DIR/siteConfig.json atomically (unencrypted). */
(array $publicSubset)
| 377 | |
| 378 | /** Write USERS_DIR/siteConfig.json atomically (unencrypted). */ |
| 379 | public static function writeSiteConfig(array $publicSubset): array |
| 380 | { |
| 381 | $dest = rtrim(USERS_DIR, '/\\') . DIRECTORY_SEPARATOR . 'siteConfig.json'; |
| 382 | $tmp = $dest . '.tmp'; |
| 383 | |
| 384 | $json = json_encode($publicSubset, JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE); |
| 385 | if ($json === false) { |
| 386 | return ["error" => "Failed to encode siteConfig.json"]; |
| 387 | } |
| 388 | |
| 389 | if (file_put_contents($tmp, $json, LOCK_EX) === false) { |
| 390 | return ["error" => "Failed to write temp siteConfig.json"]; |
| 391 | } |
| 392 | |
| 393 | if (!@rename($tmp, $dest)) { |
| 394 | @unlink($tmp); |
| 395 | return ["error" => "Failed to move siteConfig.json into place"]; |
| 396 | } |
| 397 | |
| 398 | @chmod($dest, 0664); // readable in bind mounts |
| 399 | return ["success" => true]; |
| 400 | } |
| 401 | |
| 402 | /** |
| 403 | * Updates the admin configuration file. |
no outgoing calls
no test coverage detected