{"record":{"id":"300d69fea5332f81","repo":"siyuan-note/siyuan","slug":"template-destination-already-exists-or-is-inaccess","errorCode":null,"errorMessage":"template destination already exists or is inaccessible","messagePattern":"template destination already exists or is inaccessible","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"kernel/model/template_manage.go","lineNumber":306,"sourceCode":"\t\t\treturn nil, errors.New(\"cannot write a template directory\")\n\t\t}\n\t\terr = writeTemplateSource(root, request.Path, request.Content, info == nil)\n\t\treturn map[string]string{\"revision\": fmt.Sprintf(\"%x\", sha256.Sum256([]byte(request.Content)))}, err\n\tcase \"move\":\n\t\tif info.IsDir() && isManagedTemplatePackage(root, request.Path) {\n\t\t\treturn nil, errors.New(\"template packages cannot be renamed or moved\")\n\t\t}\n\t\tif err = checkTemplateFilePath(root, request.Target); err != nil {\n\t\t\treturn nil, err\n\t\t}\n\t\tif err = validateNewTemplateName(request.Target); err != nil {\n\t\t\treturn nil, err\n\t\t}\n\t\tif !info.IsDir() && !strings.EqualFold(path.Ext(request.Target), \".md\") {\n\t\t\treturn nil, errors.New(\"template source must use the .md extension\")\n\t\t}\n\t\tif _, err = root.Stat(request.Target); !errors.Is(err, os.ErrNotExist) {\n\t\t\treturn nil, errors.New(\"template destination already exists or is inaccessible\")\n\t\t}\n\t\treturn nil, root.Rename(request.Path, request.Target)\n\tcase \"remove\":\n\t\t// 路径边界和版本校验完成后，直接删除选中项目及其内容。\n\t\tif info.IsDir() {\n\t\t\treturn nil, root.RemoveAll(request.Path)\n\t\t}\n\t\treturn nil, root.Remove(request.Path)\n\tdefault:\n\t\treturn nil, errors.New(\"unsupported template operation\")\n\t}\n}\n","sourceCodeStart":288,"sourceCodeEnd":319,"githubUrl":"https://github.com/siyuan-note/siyuan/blob/9f775e8a12daef8255556097396f9b2739078892/kernel/model/template_manage.go#L288-L319","documentation":"Before executing a rename, the 'move' action stats the destination: the move proceeds only if root.Stat(request.Target) returns os.ErrNotExist. Any other outcome — the target already exists, or stat fails with an unrelated error (permissions, I/O) — produces this error, which conservatively refuses to clobber or proceed in doubt.","triggerScenarios":"Calling ManageTemplateFiles with Action \"move\" where request.Target already exists in the templates root, or Stat on Target returns an error other than ErrNotExist (e.g. a component of the path is not a directory or is unreadable).","commonSituations":"Renaming a template to a name that another template already uses; a sync or another window created the destination between listing and moving; the target path contains an invalid segment causing stat to fail with ENOTDIR; case-only renames on case-sensitive filesystems where the target technically exists.","solutions":["Choose a Target name that does not exist (verify with Action \"list\" first)","If the existing destination should be replaced, delete it explicitly (Action \"remove\") and then move","Fix the Target path so all parent segments are valid existing directories","Retry after resolving filesystem/permission issues if stat failed for an environmental reason"],"exampleFix":"// before\nmove(TemplateFileRequest{Action: \"move\", Path: \"a.md\", Target: \"b.md\"})\n// after\nif !templateExists(\"b.md\") { move(TemplateFileRequest{Action: \"move\", Path: \"a.md\", Target: \"b.md\"}) } else { /* prompt for another name */ }","handlingStrategy":"validation","validationCode":"if _, err := statTemplate(target); !errors.Is(err, os.ErrNotExist) { return errors.New(\"destination already exists\") }","typeGuard":null,"tryCatchPattern":"if err != nil && strings.Contains(err.Error(), \"template destination already exists\") {\n    // prompt for a different name or delete destination explicitly\n}","preventionTips":["Refresh the template list right before a move to detect new collisions","Use unique names (timestamp/uuid suffix) for automated moves","Handle case-sensitivity differences when generating target names"],"tags":["conflict","file-already-exists","rename"],"backgroundTag":"file-already-exists","analyzedSha":"9f775e8a12daef8255556097396f9b2739078892","analyzedAt":"2026-09-19T03:17:15.984Z","contentChangedAt":"2026-09-19T03:17:15.984Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}