{"record":{"id":"75f50bf20f015aec","repo":"nextcloud/all-in-one","slug":"failed-to-rename-tempfile-to-dataconst-getco","errorCode":null,"errorMessage":"Failed to rename ${tempFile} to ${DataConst::GetConfigFile()}","messagePattern":"Failed to rename (.+?) to (.+?)","errorType":"exception","errorClass":"InvalidSettingConfigurationException","httpStatus":422,"severity":"error","filePath":"php/src/Data/ConfigurationManager.php","lineNumber":859,"sourceCode":"        $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\n        if (file_exists(DataConst::GetConfigFile())) {\n            if ($envVariableOutput !== $configValue) {\n                $this->set($configName, $envVariableOutput);\n            }","sourceCodeStart":841,"sourceCodeEnd":877,"githubUrl":"https://github.com/nextcloud/all-in-one/blob/6b788eec5e61733cf03ed380a3572e43ae3f11ce/php/src/Data/ConfigurationManager.php#L841-L877","documentation":"Thrown when rename() cannot move configuration.json.tmp over configuration.json after a successful temp write. The temp file is unlinked before throwing, so the previous config file remains intact. rename() failing at this point is almost always a cross-device or permission situation (EXDEV) or an immutable target.","triggerScenarios":"Committing a config change when the temp file and final config file end up on different mounts (e.g. configuration.json is a bind-mounted single file while .tmp is created on the container's local filesystem), when the target file/directory permissions block the replace, or when the filesystem is read-only/remounted ro.","commonSituations":"Bind-mounting configuration.json as a single file instead of its parent directory; immutable attribute (chattr +i) set on the config file during hardening; mount flipped to read-only after disk errors; overlayfs quirks with single-file bind mounts.","solutions":["Mount the whole AIO data directory as a volume, not the single configuration.json file.","Clear immutability if set: `chattr -i <host>/configuration.json`.","Verify both files sit on the same filesystem and the directory is writable: `docker exec ... ls -la <data-dir>`.","Remount the affected filesystem read-write and retry the settings change."],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"try {\n    $configurationManager->set('password', $newPassword);\n} catch (\\AIO\\Data\\InvalidSettingConfigurationException $e) {\n    if (str_contains($e->getMessage(), 'Failed to rename')) {\n        // temp file cleaned up, original config intact; check for single-file bind mounts / immutability\n    }\n}","preventionTips":["Mount the directory, never the individual configuration.json file.","Do not set chattr +i on AIO config files."],"tags":["php","nextcloud-aio","filesystem","atomic-write","permissions","configuration"],"backgroundTag":"file-rename-failed","analyzedSha":"6b788eec5e61733cf03ed380a3572e43ae3f11ce","analyzedAt":"2026-08-21T05:47:24.382Z","schemaVersion":2},"datasetVersion":"2026-08-21T11:28:35.574Z"}