filesys

package
v0.0.0-...-be17ed1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 10, 2026 License: AGPL-3.0 Imports: 37 Imported by: 1

Documentation

Index

Constants

This section is empty.

Variables

View Source
var DEKLockAcquire func(boxID string)

DEKLockAcquire / DEKLockRelease 由 model 层注入,在获取 DEK 前后持 box 读锁, 防止 LockBox 在加解密期间清除缓存。非加密 box 的注入为空时不影响行为。

View Source
var DEKLockRelease func(boxID string)
View Source
var DEKProvider func(boxID string) ([]byte, error)

DEKProvider 由 model 层在 init 时注入,用于查询 boxID 对应的 DEK。 返回 (nil, nil) 表示该 box 非加密——加解密函数原样返回 data,对普通笔记本透明。 返回 (nil, error) 表示加密但未解锁——加解密函数拒绝读写,避免未解锁时静默落盘明文。 filesys 不能直接 import model(会形成 model → filesys → model 循环依赖),故采用回调注入。

View Source
var ErrInvalidDocIAL = errors.New("invalid document properties")

Functions

func BlocksWordCount

func BlocksWordCount(ids []string) (ret *util.BlockStatResult)

func BuiltInTemplateFuncs

func BuiltInTemplateFuncs() (ret template.FuncMap)

func CheckDocumentAddressing

func CheckDocumentAddressing(boxID string) error

CheckDocumentAddressing 仅校验笔记本 ID 格式;访问权限、源格式与认证由调用方检查。

func CheckDocumentSpecJSON

func CheckDocumentSpecJSON(boxID string, data []byte) error

func ContentStat

func ContentStat(content string) (ret *util.BlockStatResult)

func CreateTreeWithJournal

func CreateTreeWithJournal(tree *parse.Tree, prepare func([]byte) error) (err error)

CreateTreeWithJournal prepares the exact persisted bytes, then records recovery before creating a new source. The destination must remain absent.

func DocIAL

func DocIAL(absPath string) (ret map[string]string, err error)

func DocumentAddressingMode

func DocumentAddressingMode(boxID string) (int, error)

func FormatFloat

func FormatFloat(format string, n float64) string

func LoadTree

func LoadTree(boxID, p string, luteEngine *lute.Lute) (ret *parse.Tree, err error)

func LoadTreeByData

func LoadTreeByData(data []byte, boxID, p string, luteEngine *lute.Lute) (ret *parse.Tree, err error)

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 LoadTreeWithFix(boxID, p string, luteEngine *lute.Lute) (ret *parse.Tree, needFix bool, err error)

func LoadTrees

func LoadTrees(ids []string) (ret map[string]*parse.Tree)

func LockDocumentConfiguration

func LockDocumentConfiguration() func()

LockDocumentConfiguration 与源提交互斥,配置发布后旧的创建预览不能继续落盘。 持锁范围不能调用源写入或等待事务队列;配置反应在释放后执行。

func MutateDocumentSourceSet

func MutateDocumentSourceSet(collect func() ([]*treenode.BlockTree, error), mutate func() error) error

MutateDocumentSourceSet 在提交范围内枚举目录,防止遗漏检查期间新增的文档。

func MutateDocumentSources

func MutateDocumentSources(documents []*treenode.BlockTree, mutate func() error) error

MutateDocumentSources 将原始源变更纳入同一提交范围;恢复失败保留标记,不误报源未写入。 相同身份的最后一个路径为操作后的预期位置,目录操作按父级先于子级恢复。

func NormalizeTreeForRead

func NormalizeTreeForRead(tree *parse.Tree) (err error)

NormalizeTreeForRead 对只读树应用与文件加载一致的规范化处理,但不写回磁盘。

func ObserveTreeWrites

func ObserveTreeWrites(tree *parse.Tree, before []byte, observe func([]byte) error, write func() error) error

ObserveTreeWrites 保留外层事务的源记录与比较条件,仅观察本次指定树的写入字节。

func ReadDocHPath

func ReadDocHPath(boxID, p string) (hpath string, properties map[string]string, err error)

ReadDocHPath 只读文档属性并认证加密源文件,不解析块树、不修复或补建任何文件。

func ReadDocumentMetadataTree

func ReadDocumentMetadataTree(boxID, p string) (*parse.Tree, error)

ReadDocumentMetadataTree 认证并检查源文件,仅构建根属性,恢复过程不补建或修复正文。

func ReadTreeSnapshot

func ReadTreeSnapshot(boxID, p string) (*parse.Tree, [sha256.Size]byte, error)

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

func RecoverDocumentMetadataWrite(doc *treenode.BlockTree) error

RecoverDocumentMetadataWrite 根据认证后的源完成中断写入,不用待写入的标题覆盖实际源。

func StatBlock

func StatBlock(id string) (ret *util.BlockStatResult)

func StatNodes

func StatNodes(tree *parse.Tree, nodes []*ast.Node) (ret *util.BlockStatResult)

StatNodes 统计指定节点及其子节点。

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

func SyAAD(boxID, relativePath string) (string, error)

SyAAD 构造 .sy 密文的 AAD:siyuan:file:<boxID>:<稳定文件基名>。 父目录不进 AAD——同 box 内文件名不变的移动允许原样 Rename 密文,内容/box/类型/对象 ID 仍受认证。

func SyObjectBase

func SyObjectBase(relativePath string) (string, error)

SyObjectBase 从 box 内相对路径提取稳定文件基名并校验合法性。 接受形如 <rootID>.sy 的基名:扩展名必须是 .sy,且 stem 是合法节点 ID。 非法扩展名或非节点 ID 模式返回错误,避免把任意路径当 AAD 绑定物产生不可解密的数据。 由 filesys、model 历史查看/回滚、import 等所有 .sy 加解密路径共同使用,保证 AAD 一致。

func TreeSize

func TreeSize(tree *parse.Tree) (size uint64)

func ValidateBoxRelativePath

func ValidateBoxRelativePath(boxID, p string) (string, error)

ValidateBoxRelativePath 校验 box 内相对路径是否安全。 拒绝 ..、绝对路径,确保最终路径位于 <DataDir>/<boxID> 内。 允许路径以 / 开头(如 /20230101/xxx.sy),会自动标准化再去掉前导斜杠。 根路径("/" 或 "")合法,返回空字符串。

func WalkTreeSnapshots

func WalkTreeSnapshots(boxID string, paths []string, visit func(*parse.Tree) error) error

WalkTreeSnapshots 在一次源只读遍历中复用模式、祖先标题和解析器,逐篇认证完整来源。 回调不得写入源;用于预检时,调用方须在实际源变更的提交范围内再次检查。

func WriteTree

func WriteTree(tree *parse.Tree) (size uint64, err error)

func WriteTreeIfUnchanged

func WriteTreeIfUnchanged(tree *parse.Tree, original []byte) (size uint64, err error)

WriteTreeIfUnchanged 仅在文档仍与扫描源的原始文件字节一致时原子替换,防止覆盖并发修改。 加密源必须先通过认证,落盘沿用现有密文格式,缓存仅在条件写成功后更新。

func WriteTreeIfUnchangedWithPreflight

func WriteTreeIfUnchangedWithPreflight(tree *parse.Tree, original []byte, preflight func() error) (size uint64, err error)

WriteTreeIfUnchangedWithPreflight 在同一源写入锁内同时检查业务条件和认证源快照。

func WriteTreeWithPreflight

func WriteTreeWithPreflight(tree *parse.Tree, preflight func() error) (size uint64, err error)

WriteTreeWithPreflight 在源写入协调范围内检查业务条件,检查失败时不创建目录或发布缓存。

Types

type CachedTreeSource

type CachedTreeSource struct {
	// contains filtered or unexported fields
}

CachedTreeSource 保存普通文档缓存及父级标题的独立副本,解析不再访问文件或发布缓存。

func CaptureCachedTreeSource

func CaptureCachedTreeSource(boxID, p string) (*CachedTreeSource, error)

CaptureCachedTreeSource 在调用方的读取边界内复制已缓存来源。 缓存缺失、加密来源和需要订正的父链返回 nil,由调用方完成完整加载。

func (*CachedTreeSource) Parse

func (source *CachedTreeSource) Parse(luteEngine *lute.Lute) (*parse.Tree, error)

Parse 在调用方释放事务锁后构造独立树,按捕获时的模式验证源格式,不再次访问磁盘。

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL
⌂ 换网址