{"record":{"id":"8d98681d143066bb","repo":"siyuan-note/siyuan","slug":"template-packages-cannot-be-renamed-or-moved","errorCode":null,"errorMessage":"template packages cannot be renamed or moved","messagePattern":"template packages cannot be renamed or moved","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"kernel/model/template_manage.go","lineNumber":294,"sourceCode":"\t}\n\tswitch request.Action {\n\tcase \"write\":\n\t\tif info == nil {\n\t\t\tif err = validateNewTemplateName(request.Path); err != nil {\n\t\t\t\treturn nil, err\n\t\t\t}\n\t\t}\n\t\tif len(request.Content) > maxTemplateSourceSize {\n\t\t\treturn nil, errors.New(\"template source is too large\")\n\t\t}\n\t\tif info != nil && info.IsDir() {\n\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)","sourceCodeStart":276,"sourceCodeEnd":312,"githubUrl":"https://github.com/siyuan-note/siyuan/blob/9f775e8a12daef8255556097396f9b2739078892/kernel/model/template_manage.go#L276-L312","documentation":"The 'move' action refuses to rename or relocate directories that isManagedTemplatePackage identifies as managed template packages. These packages have internal structure (managed metadata/content layout) whose integrity depends on their path, so renaming them would corrupt the package identity. Only plain directories and .md files may be moved.","triggerScenarios":"Calling ManageTemplateFiles with Action \"move\" where request.Path is an existing directory and isManagedTemplatePackage(root, request.Path) returns true — typically a package directory created/managed by the template system rather than a user-made folder.","commonSituations":"Trying to rename an installed/imported template package from the UI or API; scripting bulk reorganization that treats package folders like plain folders; migrating templates across workspace layouts by moving package roots.","solutions":["Move or rename only plain directories and .md files; leave managed packages in place","If reorganization is required, recreate the package under the new name and copy files manually via read/write of the inner .md files","Check IsPackage on list entries (TemplateFileEntry.IsPackage) before attempting a move","Delete and re-import the package under the desired name if the source allows"],"exampleFix":"// before\nmove(TemplateFileRequest{Action: \"move\", Path: pkgPath, Target: newPath})\n// after\nif !entry.IsPackage { move(TemplateFileRequest{Action: \"move\", Path: pkgPath, Target: newPath}) }","handlingStrategy":"type-guard","validationCode":"if entry.IsPackage { skip } // from TemplateFileEntry.IsPackage in list results","typeGuard":"func isMovable(e TemplateFileEntry) bool { return !e.IsPackage }","tryCatchPattern":"if err != nil && strings.Contains(err.Error(), \"template packages cannot be renamed or moved\") {\n    // offer recreate-and-copy workflow instead\n}","preventionTips":["Filter managed packages out of bulk-move scripts","Check IsPackage in list results before move operations","Treat package directories as immutable paths managed by the app"],"tags":["unsupported-operation","templates","packages"],"backgroundTag":"operation-not-supported","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"}