{"record":{"id":"ce33fef425ac5042","repo":"octobercms/october","slug":"cms-lang-lang-error-deleting-file","errorCode":null,"errorMessage":"cms::lang.lang.error_deleting_file","messagePattern":"cms::lang\\.lang\\.error_deleting_file","errorType":"exception","errorClass":"ApplicationException","httpStatus":null,"severity":"error","filePath":"modules/cms/classes/Lang.php","lineNumber":315,"sourceCode":"     * delete the object from disk\n     */\n    public function delete()\n    {\n        $fullPath = $this->getFilePath();\n\n        $this->validateFileName();\n\n        if (!FileHelper::validateInTheme($this->theme, $fullPath)) {\n            throw new ValidationException(['fileName' =>\n                LangHelper::get('cms::lang.cms_object.invalid_file', [\n                    'name' => $this->fileName\n                ])\n            ]);\n        }\n\n        if (File::exists($fullPath)) {\n            if (!@File::delete($fullPath)) {\n                throw new ApplicationException(LangHelper::get(\n                    'cms::lang.lang.error_deleting_file',\n                    ['name' => $this->fileName]\n                ));\n            }\n        }\n    }\n\n    /**\n     * validateFileName supplied with extension and path.\n     */\n    protected function validateFileName($fileName = null)\n    {\n        if ($fileName === null) {\n            $fileName = $this->fileName;\n        }\n\n        $fileName = trim($fileName);\n","sourceCodeStart":297,"sourceCodeEnd":333,"githubUrl":"https://github.com/octobercms/october/blob/b608633a7e8922487d91a8161499020121c3b3bf/modules/cms/classes/Lang.php#L297-L333","documentation":"ApplicationException thrown by `Lang::delete()` when `File::delete($fullPath)` fails although the file exists: PHP could not unlink it. Almost always a permissions problem — no write/execute permission on the containing directory or the file is owned by a different user than the web server.","triggerScenarios":"Deleting a lang file created by a root CLI session so www-data cannot unlink it; directory without write permission for the PHP user; file held open / immutable flag set on some filesystems.","commonSituations":"Mixed CLI/web file ownership after deploys; hardened production dirs; containers where the volume is mounted read-only.","solutions":["Fix ownership of the file and its directory: `chown -R www-data:www-data themes/<theme>/lang`.","Ensure the directory itself is writable by the web server (unlink permission lives on the directory, not the file).","As a last resort delete the file manually over SSH, then retry the UI operation."],"exampleFix":"# before — directory owned by root; unlink denied\n$ ls -ld themes/mytheme/lang\ndrwxr-xr-x root root themes/mytheme/lang\n\n# after — unlink permission is on the directory\nsudo chown www-data:www-data themes/mytheme/lang\nsudo chmod u+rwx themes/mytheme/lang","handlingStrategy":"validation","validationCode":"$path = $lang->getFilePath();\nif (file_exists($path) && (!is_writable($path) || !is_writable(dirname($path)))) {\n    return back()->with('error', 'File or directory is not writable — fix ownership before deleting.');\n}\n$lang->delete();","typeGuard":null,"tryCatchPattern":"try {\n    $lang->delete();\n} catch (ApplicationException $e) {\n    // unlink failed: report which path and its perms for quick ops triage\n    Log::error('Lang delete failed', ['path' => $lang->getFilePath(), 'perms' => @fileperms($lang->getFilePath())]);\n    throw $e;\n}","preventionTips":["Remember unlink permission depends on the directory, not the file — check both.","Standardize on a single owning user for web and CLI file operations.","Automate ownership repair (chown) as part of post-deploy steps."],"tags":["filesystem","permissions","delete","io","lang"],"backgroundTag":"file-delete-permission-denied","analyzedSha":"b608633a7e8922487d91a8161499020121c3b3bf","analyzedAt":"2026-08-21T04:24:57.515Z","schemaVersion":2},"datasetVersion":"2026-08-21T11:28:35.574Z"}