{"record":{"id":"1fd6e4f4de2e6bf6","repo":"siyuan-note/siyuan","slug":"template-path-is-not-a-regular-file-or-directory","errorCode":null,"errorMessage":"template path is not a regular file or directory","messagePattern":"template path is not a regular file or directory","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"kernel/model/template_manage.go","lineNumber":112,"sourceCode":"\treturn os.OpenRoot(filepath.Join(util.DataDir, \"templates\"))\n}\n\n// 除根目录外不接受符号链接，避免管理操作影响另一个模板包。\nfunc checkTemplateFilePath(root *os.Root, p string) error {\n\tif err := validateTemplateRelativePath(p, false); err != nil {\n\t\treturn err\n\t}\n\tparts := strings.Split(p, \"/\")\n\tfor i := range parts {\n\t\tinfo, err := root.Lstat(strings.Join(parts[:i+1], \"/\"))\n\t\tif errors.Is(err, os.ErrNotExist) && i == len(parts)-1 {\n\t\t\treturn nil\n\t\t}\n\t\tif err != nil {\n\t\t\treturn err\n\t\t}\n\t\tif info.Mode()&os.ModeSymlink != 0 || (!info.IsDir() && !info.Mode().IsRegular()) {\n\t\t\treturn errors.New(\"template path is not a regular file or directory\")\n\t\t}\n\t}\n\treturn nil\n}\n\nfunc templateFileRevision(root *os.Root, p string) (string, error) {\n\tinfo, err := root.Stat(p)\n\tif err != nil {\n\t\treturn \"\", err\n\t}\n\th := sha256.New()\n\tif info.IsDir() {\n\t\terr = fs.WalkDir(root.FS(), p, func(name string, entry fs.DirEntry, walkErr error) error {\n\t\t\tif walkErr != nil {\n\t\t\t\treturn walkErr\n\t\t\t}\n\t\t\tstat, statErr := entry.Info()\n\t\t\tif statErr != nil {","sourceCodeStart":94,"sourceCodeEnd":130,"githubUrl":"https://github.com/siyuan-note/siyuan/blob/9f775e8a12daef8255556097396f9b2739078892/kernel/model/template_manage.go#L94-L130","documentation":"checkTemplateFilePath uses os.Root-based Stat and rejects the target if it is a symbolic link, or if it is neither a directory nor a regular file (e.g. device nodes, FIFOs, sockets). This keeps template operations on plain files and directories only.","triggerScenarios":"DocSaveAsTemplateInDirectory or ManageTemplateFiles targeting a symlinked template file, a named pipe, or a device file inside the templates tree.","commonSituations":"Users symlinking templates from another folder (dotfiles repos, cloud-sync links), Unix sockets or FIFOs accidentally created in the workspace, or syncing tools leaving link artifacts.","solutions":["Replace the symlink with a real copy of the target file or directory","Remove or rename the special file (FIFO/socket/device) out of the templates tree","Re-sync the templates directory excluding symlinks"],"exampleFix":"# before: templates/x.md -> /home/user/other.md (symlink)\n# after\ncp -L /home/user/other.md templates/x.md  # real file replaces the link","handlingStrategy":"validation","validationCode":"info, err := os.Lstat(p)\nif err != nil || info.Mode()&os.ModeSymlink != 0 || (!info.IsDir() && !info.Mode().IsRegular()) {\n    // refuse before calling the API\n}","typeGuard":null,"tryCatchPattern":"if err := checkTemplateFilePath(root, p); err != nil { /* report symlink/special file to user */ }","preventionTips":["Use real files instead of symlinks in shared template folders","Exclude links when syncing templates across machines"],"tags":["filesystem","symlink","security"],"backgroundTag":"path-traversal-blocked","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"}