siyuan-note/siyuan · error

template directory contains a symbolic link

Error message

template directory contains a symbolic link

What it means

While hashing a template directory for revision, templateFileRevision walks its entries and aborts with this error if any contained entry is a symbolic link. Directories under template management must contain only real files so revision fingerprints and packaging stay trustworthy.

Solutions

  1. Replace each symlink inside the template directory with a real copy of its target
  2. Remove the symlinked entries from the package
  3. Rebuild the package so all assets are physical files

Example fix

# before: pkg/logo.png -> ../../assets/logo.png (symlink)
# after
cp -L ../../assets/logo.png pkg/logo.png  # real file
Defensive patterns

Strategy: validation

Validate before calling

filepath.WalkDir(dir, func(_ string, d fs.DirEntry, err error) error {
    if err != nil { return err }
    if d.Type()&fs.ModeSymlink != 0 { return errors.New("symlink found") }
    return nil
})

Prevention

When it happens

Trigger: ManageTemplateFiles computing a revision over a template package directory that contains a symlinked file (or symlinked child) anywhere in its tree.

Common situations: Dotfile-style setups linking assets into template packages, cloud-drive placeholder links, or shared template folders that use symlinks to deduplicate large assets.

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


AI-assisted analysis of siyuan-note/siyuan@9f775e8a12 (2026-09-19). Data as JSON: /api/errors/a94aabe9a0663313. Report an issue: GitHub.

Appendix: source

Thrown at kernel/model/template_manage.go:134

}

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 {
				return statErr
			}
			if stat.Mode()&os.ModeSymlink != 0 {
				return errors.New("template directory contains a symbolic link")
			}
			fmt.Fprintf(h, "%s\x00%d\x00%d\x00%d\n", name, stat.Size(), stat.ModTime().UnixNano(), stat.Mode())
			return nil
		})
	} else {
		if info.Size() > maxTemplateSourceSize {
			return "", errors.New("template source is too large")
		}
		var content []byte
		content, err = root.ReadFile(p)
		h.Write(content)
	}
	return fmt.Sprintf("%x", h.Sum(nil)), err
}

func readTemplateSource(root *os.Root, p string) (string, error) {
	info, err := root.Stat(p)
	if err != nil {

View on GitHub (pinned to 9f775e8a12)