{"record":{"id":"51cda9f41abbe61c","repo":"nextcloud/all-in-one","slug":"failed-to-write-temporary-config-file-tempfile","errorCode":null,"errorMessage":"Failed to write temporary config file: ${tempFile}","messagePattern":"Failed to write temporary config file: (.+?)","errorType":"exception","errorClass":"InvalidSettingConfigurationException","httpStatus":422,"severity":"error","filePath":"php/src/Data/ConfigurationManager.php","lineNumber":855,"sourceCode":"        if ($this->config === []) {\n            return;\n        }\n        $df = disk_free_space(DataConst::GetDataDirectory());\n        $content = json_encode($this->config, JSON_UNESCAPED_SLASHES|JSON_PRETTY_PRINT|JSON_THROW_ON_ERROR);\n        $size = strlen($content) + 10240;\n        if ($df !== false && (int)$df < $size) {\n            throw new InvalidSettingConfigurationException(DataConst::GetDataDirectory() . \" does not have enough space for writing the config file! Not writing it back!\");\n        }\n        // Write to a temp file first to avoid truncating the config file if the\n        // disk fills up mid-write. rename() is atomic on POSIX filesystems, so the\n        // original config is never touched until the new content is fully on disk.\n        $tempFile = DataConst::GetConfigFile() . '.tmp';\n        if (file_put_contents($tempFile, $content) === false) {\n            // The file probably wasn't created, but better check nonetheless.\n            if (file_exists($tempFile)) {\n                unlink($tempFile);\n            }\n            throw new InvalidSettingConfigurationException(\"Failed to write temporary config file: \" . $tempFile);\n        }\n        if (!rename($tempFile, DataConst::GetConfigFile())) {\n            unlink($tempFile);\n            throw new InvalidSettingConfigurationException(\"Failed to rename \" . $tempFile . \" to \" . DataConst::GetConfigFile());\n        }\n        $this->config = [];\n    }\n\n    private function getEnvironmentalVariableOrConfig(string $envVariableName, string $configName, string $defaultValue) : string {\n        $envVariableOutput = getenv($envVariableName);\n        $configValue = $this->get($configName, '');\n        if ($envVariableOutput === false) {\n            if ($configValue === '') {\n                return $defaultValue;\n            }\n            return $configValue;\n        }\n","sourceCodeStart":837,"sourceCodeEnd":873,"githubUrl":"https://github.com/nextcloud/all-in-one/blob/6b788eec5e61733cf03ed380a3572e43ae3f11ce/php/src/Data/ConfigurationManager.php#L837-L873","documentation":"Thrown when file_put_contents fails to write configuration.json.tmp, the staging file used to keep config writes atomic. The temp file is unlinked on failure, leaving the original config untouched. It indicates a low-level I/O problem rather than bad input: permissions, read-only filesystem, I/O errors, or disk that filled between the free-space check and the write.","triggerScenarios":"Committing any config change while the data directory (or its parent filesystem) denies writes: directory owned by root while the PHP process runs as www-data, a read-only mount, SELinux/AppArmor denial, or a race where the disk filled after the disk_free_space check passed.","commonSituations":"Data directory chowned incorrectly after a manual restore; bind mount mounted ro; SELinux enforcing on CentOS/RHEL without proper labels; NFS stale-handle or quota exceeded; host disk filled mid-request.","solutions":["Check the exact path in the message inside the container: `docker exec nextcloud-aio-nextcloud touch <path>.tmp`.","Fix ownership/permissions of the data directory so the AIO container user can create files.","Remount the filesystem read-write or fix the NFS/quota issue; re-check free space (df).","Look for SELinux denials (`ausearch -m avc`) and label the mount correctly."],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":"$tmp = DataConst::GetConfigFile() . '.tmp';\nif (!is_writable(dirname($tmp))) {\n    // fix permissions before attempting config changes\n}","typeGuard":null,"tryCatchPattern":"try {\n    $configurationManager->timezone = 'Europe/Berlin';\n} catch (\\AIO\\Data\\InvalidSettingConfigurationException $e) {\n    if (str_contains($e->getMessage(), 'Failed to write temporary config file')) {\n        // I/O problem: check perms/ro-mount/disk, original config untouched\n    }\n}","preventionTips":["Ensure the AIO container user can create files in the data directory.","Avoid read-only or quota-limited mounts for the data directory."],"tags":["php","nextcloud-aio","filesystem","permissions","io-error","configuration"],"backgroundTag":"temp-file-write-failed","analyzedSha":"6b788eec5e61733cf03ed380a3572e43ae3f11ce","analyzedAt":"2026-08-21T05:47:24.382Z","schemaVersion":2},"datasetVersion":"2026-08-21T11:28:35.574Z"}