siyuan-note/siyuan · error
template path is not a regular file or directory
Error message
template path is not a regular file or directory
What it means
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.
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
Example fix
# before: templates/x.md -> /home/user/other.md (symlink) # after cp -L /home/user/other.md templates/x.md # real file replaces the link
Defensive patterns
Strategy: validation
Validate before calling
info, err := os.Lstat(p)
if err != nil || info.Mode()&os.ModeSymlink != 0 || (!info.IsDir() && !info.Mode().IsRegular()) {
// refuse before calling the API
} Try / catch
if err := checkTemplateFilePath(root, p); err != nil { /* report symlink/special file to user */ } Prevention
- Use real files instead of symlinks in shared template folders
- Exclude links when syncing templates across machines
When it happens
Trigger: DocSaveAsTemplateInDirectory or ManageTemplateFiles targeting a symlinked template file, a named pipe, or a device file inside the templates tree.
Common situations: 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.
Understand the failure class
Background: Path traversal blocked: "path escapes the workspace" and "outside site root" errors when a path will not stay inside its allowed directory — this error's family across 26 libraries.
Related errors
- asset path resolves outside notebook assets directory
- skill path is not a regular file or directory
- symlink escapes workspace
- access to sensitive workspace file is forbidden
- archive entry resolves outside destination
AI-assisted analysis of siyuan-note/siyuan@9f775e8a12 (2026-09-19).
Data as JSON: /api/errors/1fd6e4f4de2e6bf6.
Report an issue: GitHub.
Appendix: source
Thrown at kernel/model/template_manage.go:112
return os.OpenRoot(filepath.Join(util.DataDir, "templates"))
}
// 除根目录外不接受符号链接,避免管理操作影响另一个模板包。
func checkTemplateFilePath(root *os.Root, p string) error {
if err := validateTemplateRelativePath(p, false); err != nil {
return err
}
parts := strings.Split(p, "/")
for i := range parts {
info, err := root.Lstat(strings.Join(parts[:i+1], "/"))
if errors.Is(err, os.ErrNotExist) && i == len(parts)-1 {
return nil
}
if err != nil {
return err
}
if info.Mode()&os.ModeSymlink != 0 || (!info.IsDir() && !info.Mode().IsRegular()) {
return errors.New("template path is not a regular file or directory")
}
}
return nil
}
func templateFileRevision(root *os.Root, p string) (string, error) {
info, err := root.Stat(p)
if err != nil {
return "", err
}
h := sha256.New()
if info.IsDir() {
err = fs.WalkDir(root.FS(), p, func(name string, entry fs.DirEntry, walkErr error) error {
if walkErr != nil {
return walkErr
}
stat, statErr := entry.Info()
if statErr != nil {View on GitHub (pinned to 9f775e8a12)