{"record":{"id":"13a0461c69f07d5a","repo":"octobercms/october","slug":"editor-lang-filesystem-already-exists","errorCode":null,"errorMessage":"editor::lang.filesystem.already_exists","messagePattern":"editor::lang\\.filesystem\\.already_exists","errorType":"validation","errorClass":"ApplicationException","httpStatus":null,"severity":"warning","filePath":"modules/editor/traits/FileSystemFunctions.php","lineNumber":44,"sourceCode":"        if (!strlen($newName)) {\n            throw new ApplicationException(Lang::get('editor::lang.filesystem.directory_name_cant_be_empty'));\n        }\n\n        if (!$this->validateFileSystemPath($newName)) {\n            throw new ApplicationException(Lang::get('editor::lang.filesystem.invalid_path'));\n        }\n\n        if (strlen($parent) && !$this->validateFileSystemPath($parent)) {\n            throw new ApplicationException(Lang::get('editor::lang.filesystem.invalid_path'));\n        }\n\n        if (!$this->validateFileSystemName($newName)) {\n            throw new ApplicationException(Lang::get('editor::lang.filesystem.invalid_name'));\n        }\n\n        $newFullPath = $basePath.'/'.$parent.'/'.$newName;\n        if (file_exists($newFullPath) && is_dir($newFullPath)) {\n            throw new ApplicationException(Lang::get('editor::lang.filesystem.already_exists'));\n        }\n\n        if (!File::makeDirectory($newFullPath, 0755, true, true)) {\n            throw new ApplicationException(Lang::get(\n                'editor::lang.filesystem.error_creating_directory',\n                ['name' => $newName]\n            ));\n        }\n    }\n\n    /**\n     * editorRenameFileOrDirectory\n     */\n    protected function editorRenameFileOrDirectory($basePath, $name, $originalPath, $allowedFileExtensions)\n    {\n        $newName = trim($name);\n        if (!strlen($newName)) {\n            throw new ApplicationException(Lang::get('editor::lang.filesystem.name_cant_be_empty'));","sourceCodeStart":26,"sourceCodeEnd":62,"githubUrl":"https://github.com/octobercms/october/blob/b608633a7e8922487d91a8161499020121c3b3bf/modules/editor/traits/FileSystemFunctions.php#L26-L62","documentation":"editorCreateDirectory assembles the target as basePath/parent/newName and checks file_exists() plus is_dir() before creating anything. If a directory already exists at that exact location it throws editor::lang.filesystem.already_exists, preventing accidental overwrite of theme directories.","triggerScenarios":"Creating a directory that already exists (e.g. 'assets' under a theme root); duplicate submissions when the user double-clicks 'create'; a case-insensitive filesystem where 'Partials' collides with 'partials'; stale UI state listing an outdated tree.","commonSituations":"Editor tree not refreshed after a previous create; race between two browser tabs both creating the same folder; deploying to macOS/Windows where case-insensitivity turns distinct names into collisions.","solutions":["Refresh the file tree and pick a different, unused name.","Guard against double submission (disable the create button until the request finishes).","On case-insensitive filesystems, choose a name differing by more than letter case.","If the directory is intended, reuse it instead of creating a duplicate."],"exampleFix":"// before\n$name = 'partials'; // already exists\n$this->editorCreateDirectory($basePath, $name, $parent);\n\n// after\nif (is_dir($basePath.'/'.$parent.'/'.$name)) {\n    // reuse the existing directory\n} else {\n    $this->editorCreateDirectory($basePath, $name, $parent);\n}","handlingStrategy":"validation","validationCode":"$target = $basePath.'/'.$parent.'/'.$newName;\nif (is_dir($target)) {\n    throw new \\ValidationException(['name' => \"A directory named '{$newName}' already exists\"]);\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Refresh the file tree before creating directories.","Prevent double submission of the create form.","On case-insensitive filesystems, treat names differing only by case as duplicates."],"tags":["editor","filesystem","duplicate","directory"],"backgroundTag":"file-already-exists","analyzedSha":"b608633a7e8922487d91a8161499020121c3b3bf","analyzedAt":"2026-08-21T04:24:57.515Z","schemaVersion":2},"datasetVersion":"2026-08-21T11:28:35.574Z"}