{"record":{"id":"cb86ec8eb4b0d82b","repo":"LykosAI/StabilityMatrix","slug":"file-name-already-exists","errorCode":null,"errorMessage":"File name already exists","messagePattern":"File name already exists","errorType":"validation","errorClass":"DataValidationException","httpStatus":null,"severity":"warning","filePath":"StabilityMatrix.Avalonia/ViewModels/CheckpointManager/CheckpointFileViewModel.cs","lineNumber":353,"sourceCode":"    [RelayCommand]\n    private async Task RenameAsync()\n    {\n        // Parent folder path\n        var parentPath =\n            Path.GetDirectoryName((string?)CheckpointFile.GetFullPath(settingsManager.ModelsDirectory)) ?? \"\";\n\n        var textFields = new TextBoxField[]\n        {\n            new()\n            {\n                Label = \"File name\",\n                Validator = text =>\n                {\n                    if (string.IsNullOrWhiteSpace(text))\n                        throw new DataValidationException(\"File name is required\");\n\n                    if (File.Exists(Path.Combine(parentPath, text)))\n                        throw new DataValidationException(\"File name already exists\");\n                },\n                Text = CheckpointFile.FileName,\n            },\n        };\n\n        var dialog = DialogHelper.CreateTextEntryDialog(\"Rename Model\", \"\", textFields);\n\n        if (await dialog.ShowAsync() == ContentDialogResult.Primary)\n        {\n            var name = textFields[0].Text;\n            var nameNoExt = Path.GetFileNameWithoutExtension(name);\n            var originalNameNoExt = Path.GetFileNameWithoutExtension(CheckpointFile.FileName);\n            // Rename file in OS\n            try\n            {\n                var newFilePath = Path.Combine(parentPath, name);\n                File.Move(CheckpointFile.GetFullPath(settingsManager.ModelsDirectory), newFilePath);\n","sourceCodeStart":335,"sourceCodeEnd":371,"githubUrl":"https://github.com/LykosAI/StabilityMatrix/blob/af93d6ef57c01cd890d7e0ad0a9ea8c9fcda3002/StabilityMatrix.Avalonia/ViewModels/CheckpointManager/CheckpointFileViewModel.cs#L335-L371","documentation":"In CheckpointFileViewModel.RenameAsync, the dialog Validator throws DataValidationException(\"File name already exists\") when File.Exists confirms that parentPath + the entered name collides with an existing file. The rename is blocked to avoid overwriting another checkpoint file.","triggerScenarios":"Submitting the 'Rename Model' dialog with a name that matches an existing file in the same checkpoint folder (exact name, or same name ignoring case on case-insensitive filesystems).","commonSituations":"Renaming a model to a name another checkpoint already uses; duplicating a checkpoint then renaming the copy back to the original name; case-only renames on Windows/NTFS.","solutions":["Choose a unique file name that does not match any file in the target folder","If overwriting is intended, delete the existing file first, then rename","Add extension-aware or case-insensitive collision checking in the Validator if the current File.Exists check misses variants"],"exampleFix":"// before\nif (File.Exists(Path.Combine(parentPath, text)))\n    throw new DataValidationException(\"File name already exists\");\n\n// after\nvar candidate = Directory.EnumerateFiles(parentPath)\n    .FirstOrDefault(f => string.Equals(Path.GetFileName(f), text, StringComparison.OrdinalIgnoreCase));\nif (candidate is not null)\n    throw new DataValidationException($\"File name already exists: {Path.GetFileName(candidate)}\");","handlingStrategy":"validation","validationCode":"// Validate before confirming the rename\nvar target = Path.Combine(parentPath, newName);\nif (File.Exists(target))\n    throw new DataValidationException(\"File name already exists\");","typeGuard":"bool IsFreeFileName(string parent, string name) =>\n    !string.IsNullOrWhiteSpace(name) &&\n    !Directory.EnumerateFiles(parent)\n        .Any(f => string.Equals(Path.GetFileName(f), name, StringComparison.OrdinalIgnoreCase));","tryCatchPattern":"try\n{\n    await checkpointFileVm.RenameAsync();\n}\ncatch (DataValidationException ex) when (ex.Message == \"File name already exists\")\n{\n    Logger.Debug(\"Rename aborted: target file already exists\");\n    // surface 'choose another name' in UI\n}","preventionTips":["Check the target folder for existing files (case-insensitively on Windows) before renaming","Avoid renaming copies back to the original checkpoint's name","Consider auto-suffixing duplicates (e.g. name (1).safetensors) instead of failing","Remember case-only renames collide on NTFS/APFS default settings"],"tags":["validation","file-conflict","rename","filesystem"],"backgroundTag":"file-already-exists","analyzedSha":"af93d6ef57c01cd890d7e0ad0a9ea8c9fcda3002","analyzedAt":"2026-09-12T19:02:43.389Z","contentChangedAt":"2026-09-12T19:02:43.389Z","schemaVersion":2},"datasetVersion":"2026-09-16T04:17:20.429Z"}