Documentation
¶
Index ¶
- Variables
- func BlocksWordCount(ids []string) (ret *util.BlockStatResult)
- func BuiltInTemplateFuncs() (ret template.FuncMap)
- func CheckDocumentAddressing(boxID string) error
- func CheckDocumentSpecJSON(boxID string, data []byte) error
- func ContentStat(content string) (ret *util.BlockStatResult)
- func CreateTreeWithJournal(tree *parse.Tree, prepare func([]byte) error) (err error)
- func DocIAL(absPath string) (ret map[string]string, err error)
- func DocumentAddressingMode(boxID string) (int, error)
- func FormatFloat(format string, n float64) string
- func LoadTree(boxID, p string, luteEngine *lute.Lute) (ret *parse.Tree, err error)
- func LoadTreeByData(data []byte, boxID, p string, luteEngine *lute.Lute) (ret *parse.Tree, err error)
- func LoadTreeSnapshot(boxID, p string, luteEngine *lute.Lute) (tree *parse.Tree, original []byte, err error)
- func LoadTreeSnapshotWithFix(boxID, p string, luteEngine *lute.Lute) (tree *parse.Tree, original []byte, needFix bool, err error)
- func LoadTreeWithFix(boxID, p string, luteEngine *lute.Lute) (ret *parse.Tree, needFix bool, err error)
- func LoadTrees(ids []string) (ret map[string]*parse.Tree)
- func LockDocumentConfiguration() func()
- func MutateDocumentSourceSet(collect func() ([]*treenode.BlockTree, error), mutate func() error) error
- func MutateDocumentSources(documents []*treenode.BlockTree, mutate func() error) error
- func NormalizeTreeForRead(tree *parse.Tree) (err error)
- func ObserveTreeWrites(tree *parse.Tree, before []byte, observe func([]byte) error, ...) error
- func ReadDocHPath(boxID, p string) (hpath string, properties map[string]string, err error)
- func ReadDocumentMetadataTree(boxID, p string) (*parse.Tree, error)
- func ReadTreeSnapshot(boxID, p string) (*parse.Tree, [sha256.Size]byte, error)
- func RecordTreeWrites(tree *parse.Tree, before []byte, record func([]byte) error, write func() error) error
- func RecoverDocumentMetadataWrite(doc *treenode.BlockTree) error
- func StatBlock(id string) (ret *util.BlockStatResult)
- func StatNodes(tree *parse.Tree, nodes []*ast.Node) (ret *util.BlockStatResult)
- func StatTree(id string) (ret *util.BlockStatResult)
- func StatTreeFromTree(tree *parse.Tree) (ret *util.BlockStatResult)
- func StatTreeInBox(id, boxID string) (ret *util.BlockStatResult)
- func SyAAD(boxID, relativePath string) (string, error)
- func SyObjectBase(relativePath string) (string, error)
- func TreeSize(tree *parse.Tree) (size uint64)
- func ValidateBoxRelativePath(boxID, p string) (string, error)
- func WalkTreeSnapshots(boxID string, paths []string, visit func(*parse.Tree) error) error
- func WriteTree(tree *parse.Tree) (size uint64, err error)
- func WriteTreeIfUnchanged(tree *parse.Tree, original []byte) (size uint64, err error)
- func WriteTreeIfUnchangedWithPreflight(tree *parse.Tree, original []byte, preflight func() error) (size uint64, err error)
- func WriteTreeWithPreflight(tree *parse.Tree, preflight func() error) (size uint64, err error)
- type CachedTreeSource
Constants ¶
This section is empty.
Variables ¶
var DEKLockAcquire func(boxID string)
DEKLockAcquire / DEKLockRelease 由 model 层注入,在获取 DEK 前后持 box 读锁, 防止 LockBox 在加解密期间清除缓存。非加密 box 的注入为空时不影响行为。
var DEKLockRelease func(boxID string)
var DEKProvider func(boxID string) ([]byte, error)
DEKProvider 由 model 层在 init 时注入,用于查询 boxID 对应的 DEK。 返回 (nil, nil) 表示该 box 非加密——加解密函数原样返回 data,对普通笔记本透明。 返回 (nil, error) 表示加密但未解锁——加解密函数拒绝读写,避免未解锁时静默落盘明文。 filesys 不能直接 import model(会形成 model → filesys → model 循环依赖),故采用回调注入。
var ErrInvalidDocIAL = errors.New("invalid document properties")
Functions ¶
func BlocksWordCount ¶
func BlocksWordCount(ids []string) (ret *util.BlockStatResult)
func BuiltInTemplateFuncs ¶
func CheckDocumentAddressing ¶
CheckDocumentAddressing 仅校验笔记本 ID 格式;访问权限、源格式与认证由调用方检查。
func CheckDocumentSpecJSON ¶
func ContentStat ¶
func ContentStat(content string) (ret *util.BlockStatResult)
func CreateTreeWithJournal ¶
CreateTreeWithJournal prepares the exact persisted bytes, then records recovery before creating a new source. The destination must remain absent.
func DocumentAddressingMode ¶
func FormatFloat ¶
func LoadTreeByData ¶
func LoadTreeSnapshot ¶
func LoadTreeSnapshot(boxID, p string, luteEngine *lute.Lute) (tree *parse.Tree, original []byte, err error)
LoadTreeSnapshot 从同一次磁盘读取返回文档及条件写基线,认证和格式兼容处理不写回源文件。
func LoadTreeSnapshotWithFix ¶
func LoadTreeSnapshotWithFix(boxID, p string, luteEngine *lute.Lute) (tree *parse.Tree, original []byte, needFix bool, err error)
LoadTreeSnapshotWithFix also reports compatibility repairs that need a conditional write-back.
func LoadTreeWithFix ¶
func LockDocumentConfiguration ¶
func LockDocumentConfiguration() func()
LockDocumentConfiguration 与源提交互斥,配置发布后旧的创建预览不能继续落盘。 持锁范围不能调用源写入或等待事务队列;配置反应在释放后执行。
func MutateDocumentSourceSet ¶
func MutateDocumentSourceSet(collect func() ([]*treenode.BlockTree, error), mutate func() error) error
MutateDocumentSourceSet 在提交范围内枚举目录,防止遗漏检查期间新增的文档。
func MutateDocumentSources ¶
MutateDocumentSources 将原始源变更纳入同一提交范围;恢复失败保留标记,不误报源未写入。 相同身份的最后一个路径为操作后的预期位置,目录操作按父级先于子级恢复。
func NormalizeTreeForRead ¶
NormalizeTreeForRead 对只读树应用与文件加载一致的规范化处理,但不写回磁盘。
func ObserveTreeWrites ¶
func ObserveTreeWrites(tree *parse.Tree, before []byte, observe func([]byte) error, write func() error) error
ObserveTreeWrites 保留外层事务的源记录与比较条件,仅观察本次指定树的写入字节。
func ReadDocHPath ¶
ReadDocHPath 只读文档属性并认证加密源文件,不解析块树、不修复或补建任何文件。
func ReadDocumentMetadataTree ¶
ReadDocumentMetadataTree 认证并检查源文件,仅构建根属性,恢复过程不补建或修复正文。
func ReadTreeSnapshot ¶
ReadTreeSnapshot 认证磁盘内容并构造独立快照,不使用内容缓存,也不修复或写回源文件。
func RecordTreeWrites ¶
func RecordTreeWrites(tree *parse.Tree, before []byte, record func([]byte) error, write func() error) error
RecordTreeWrites scopes recovery to this exact tree and writer invocation; unrelated saves are never captured by another transaction's recorder.
func RecoverDocumentMetadataWrite ¶
RecoverDocumentMetadataWrite 根据认证后的源完成中断写入,不用待写入的标题覆盖实际源。
func StatBlock ¶
func StatBlock(id string) (ret *util.BlockStatResult)
func StatTree ¶
func StatTree(id string) (ret *util.BlockStatResult)
func StatTreeFromTree ¶
func StatTreeFromTree(tree *parse.Tree) (ret *util.BlockStatResult)
StatTreeFromTree 统计整棵文档树。
func StatTreeInBox ¶
func StatTreeInBox(id, boxID string) (ret *util.BlockStatResult)
StatTreeInBox 只统计指定笔记本边界内的文档。
func SyAAD ¶
SyAAD 构造 .sy 密文的 AAD:siyuan:file:<boxID>:<稳定文件基名>。 父目录不进 AAD——同 box 内文件名不变的移动允许原样 Rename 密文,内容/box/类型/对象 ID 仍受认证。
func SyObjectBase ¶
SyObjectBase 从 box 内相对路径提取稳定文件基名并校验合法性。 接受形如 <rootID>.sy 的基名:扩展名必须是 .sy,且 stem 是合法节点 ID。 非法扩展名或非节点 ID 模式返回错误,避免把任意路径当 AAD 绑定物产生不可解密的数据。 由 filesys、model 历史查看/回滚、import 等所有 .sy 加解密路径共同使用,保证 AAD 一致。
func ValidateBoxRelativePath ¶
ValidateBoxRelativePath 校验 box 内相对路径是否安全。 拒绝 ..、绝对路径,确保最终路径位于 <DataDir>/<boxID> 内。 允许路径以 / 开头(如 /20230101/xxx.sy),会自动标准化再去掉前导斜杠。 根路径("/" 或 "")合法,返回空字符串。
func WalkTreeSnapshots ¶
WalkTreeSnapshots 在一次源只读遍历中复用模式、祖先标题和解析器,逐篇认证完整来源。 回调不得写入源;用于预检时,调用方须在实际源变更的提交范围内再次检查。
func WriteTreeIfUnchanged ¶
WriteTreeIfUnchanged 仅在文档仍与扫描源的原始文件字节一致时原子替换,防止覆盖并发修改。 加密源必须先通过认证,落盘沿用现有密文格式,缓存仅在条件写成功后更新。
Types ¶
type CachedTreeSource ¶
type CachedTreeSource struct {
// contains filtered or unexported fields
}
CachedTreeSource 保存普通文档缓存及父级标题的独立副本,解析不再访问文件或发布缓存。
func CaptureCachedTreeSource ¶
func CaptureCachedTreeSource(boxID, p string) (*CachedTreeSource, error)
CaptureCachedTreeSource 在调用方的读取边界内复制已缓存来源。 缓存缺失、加密来源和需要订正的父链返回 nil,由调用方完成完整加载。