Skip to content

An open-source, privacy-first, self-hosted knowledge workspace where humans and AI agents work together 开源、隐私优先、自托管的知识工作空间,让人与智能体在此协作

:art: Unify terminology: use 加密笔记本 instead of 加密 box in comments

Danielb51f19f7b2be
diff --git a/kernel/api/asset.go b/kernel/api/asset.go
index bb26c550dd..d8f4be10d0 100644
--- a/kernel/api/asset.go
+++ b/kernel/api/asset.go
@@ -281,7 +281,7 @@ func setFileAnnotation(c *gin.Context) {
return
}
} else {
- // 加密笔记本的 .sya 写盘前必须加密;加密 box 未解锁时拒绝写入(fail-closed,避免明文落盘)
+ // 加密笔记本的 .sya 写盘前必须加密;加密笔记本未解锁时拒绝写入(fail-closed,避免明文落盘)
writeData := []byte(data)
if boxID := model.ExtractBoxIDFromAssetsPath(writePath); boxID != "" && model.IsEncryptedBox(boxID) {
dek, dekErr := model.GetDEKIfUnlocked(boxID)
diff --git a/kernel/av/av.go b/kernel/av/av.go
index f879e8c7e5..9bc1088400 100644
--- a/kernel/av/av.go
+++ b/kernel/av/av.go
@@ -666,11 +666,11 @@ func SaveAttributeView(av *AttributeView) (err error) {
}
// 缓存与待写入数据一致时跳过落盘;缓存未命中时再读盘比对,避免无变更的重复写入
- // 通过 fallback 查找 AV 定义的实际路径(普通 box 全局,加密 box 笔记本级)
+ // 通过 fallback 查找 AV 定义的实际路径(普通 box 全局,加密笔记本笔记本级)
avJSONPath, avBoxID := FindAttributeViewPath(av.ID)
if avJSONPath == "" {
// 文件不存在(首次创建),使用全局路径,boxID 为空(普通 box)
- // 加密 box 的首次创建由 handler 层通过 SetAVBoxID 预设路径
+ // 加密笔记本的首次创建由 handler 层通过 SetAVBoxID 预设路径
avJSONPath = GetAttributeViewDataPath(av.ID)
}
if cachedData, ok := cache.GetAVData(av.ID); ok {
@@ -679,7 +679,7 @@ func SaveAttributeView(av *AttributeView) (err error) {
}
} else {
if diskData, readErr := filelock.ReadFile(avJSONPath); nil == readErr {
- // 加密 box 的磁盘数据是密文,需先解密再比对
+ // 加密笔记本的磁盘数据是密文,需先解密再比对
if avBoxID != "" {
diskData, _ = decryptAVData(avBoxID, diskData)
}
@@ -690,7 +690,7 @@ func SaveAttributeView(av *AttributeView) (err error) {
}
}
- // 加密 box 的数据需加密后再写盘
+ // 加密笔记本的数据需加密后再写盘
writeData := data
if avBoxID != "" {
writeData, err = encryptAVData(avBoxID, data)
@@ -699,7 +699,7 @@ func SaveAttributeView(av *AttributeView) (err error) {
return
}
}
- // 确保目录存在(加密 box 的笔记本级 AV 目录可能尚不存在)
+ // 确保目录存在(加密笔记本的笔记本级 AV 目录可能尚不存在)
if err = os.MkdirAll(filepath.Dir(avJSONPath), 0755); nil != err {
logging.LogErrorf("create attribute view dir [%s] failed: %s", filepath.Dir(avJSONPath), err)
return
diff --git a/kernel/av/encrypted_hook.go b/kernel/av/encrypted_hook.go
index 82af08d71d..e2483d0bef 100644
--- a/kernel/av/encrypted_hook.go
+++ b/kernel/av/encrypted_hook.go
@@ -19,7 +19,7 @@ import (
"github.com/vmihailenco/msgpack/v5"
)
-// AVDEKProvider 由 model 层注入,返回已解锁加密 box 的 DEK。
+// AVDEKProvider 由 model 层注入,返回已解锁加密笔记本的 DEK。
// 返回 (nil, nil) 表示该 box 非加密或未解锁——此时 AV 定义明文存储,对普通笔记本透明。
var AVDEKProvider func(boxID string) ([]byte, error)
@@ -32,7 +32,7 @@ var AVIsEncryptedBox func(boxID string) bool
// pendingAVBox 记录首次创建的 AV 归属哪个加密 box。
// handler 层创建 AV 前调 SetAVBoxID(avID, boxID),SaveAttributeView 时
-// findAttributeViewPath 会先查 pending 映射,找到则写入对应加密 box 路径。
+// findAttributeViewPath 会先查 pending 映射,找到则写入对应加密笔记本路径。
var pendingAVBox = map[string]string{}
var pendingAVBoxLock = sync.RWMutex{}
@@ -66,7 +66,7 @@ func attributeViewDataPathByBox(avID, boxID string) string {
// FindAttributeViewPath 按 fallback 逻辑查找 AV 定义文件的实际路径。
// 1. 先查 pendingAVBox(首次创建预设的 boxID)
// 2. 查全局 storage/av/(普通 box)
-// 3. 遍历已打开的加密 box 查找
+// 3. 遍历已打开的加密笔记本查找
// 返回找到的路径和对应的 boxID(普通 box 返回空 boxID)。找不到返回空串。
func FindAttributeViewPath(avID string) (path string, boxID string) {
// 先查 pendingAVBox(首次创建场景)
@@ -101,7 +101,7 @@ func readAttributeViewData(avID string) ([]byte, error) {
if err != nil {
return nil, err
}
- // 加密 box 的数据需解密
+ // 加密笔记本的数据需解密
if boxID != "" {
data, err = decryptAVData(boxID, data)
if err != nil {
@@ -112,13 +112,13 @@ func readAttributeViewData(avID string) ([]byte, error) {
}
// ReadAttributeViewData 是 readAttributeViewData 的导出版本,供 model.export 等外部包
-// 读取 AV 定义明文(含加密 box 的笔记本级 AV 自动解密)。
+// 读取 AV 定义明文(含加密笔记本的笔记本级 AV 自动解密)。
func ReadAttributeViewData(avID string) ([]byte, error) {
return readAttributeViewData(avID)
}
// writeAttributeViewData 写入 AV 定义数据(自动加密)。
-// boxID 为空时写全局路径(普通 box),非空时写加密 box 路径并加密。
+// boxID 为空时写全局路径(普通 box),非空时写加密笔记本路径并加密。
func writeAttributeViewData(avID, boxID string, data []byte) error {
path := attributeViewDataPathByBox(avID, boxID)
// 确保目录存在
@@ -126,7 +126,7 @@ func writeAttributeViewData(avID, boxID string, data []byte) error {
if err := os.MkdirAll(dir, 0755); err != nil {
return err
}
- // 加密 box 的数据需加密
+ // 加密笔记本的数据需加密
if boxID != "" {
var err error
data, err = encryptAVData(boxID, data)
@@ -156,7 +156,7 @@ func mirrorBlocksPathByAvID(avID string) string {
}
// readMirrorBlocks 按路径读取镜像索引(boxID 为空读全局,非空读加密 box)。
-// 加密 box 的镜像索引是 DEK 加密的密文,读取后需解密。
+// 加密笔记本的镜像索引是 DEK 加密的密文,读取后需解密。
func readMirrorBlocks(boxID string) (ret map[string][]string) {
ret = map[string][]string{}
p := mirrorBlocksPath(boxID)
@@ -169,7 +169,7 @@ func readMirrorBlocks(boxID string) (ret map[string][]string) {
return
}
if boxID != "" {
- // 加密 box 的镜像索引是密文,解密后再反序列化
+ // 加密笔记本的镜像索引是密文,解密后再反序列化
dec, decErr := decryptAVData(boxID, data)
if decErr != nil {
logging.LogErrorf("decrypt attribute view blocks failed: %s", decErr)
@@ -185,7 +185,7 @@ func readMirrorBlocks(boxID string) (ret map[string][]string) {
}
// writeMirrorBlocks 按路径写入镜像索引。
-// 加密 box 的镜像索引写入前用 DEK 加密。
+// 加密笔记本的镜像索引写入前用 DEK 加密。
func writeMirrorBlocks(boxID string, data map[string][]string) error {
p := mirrorBlocksPath(boxID)
if err := os.MkdirAll(filepath.Dir(p), 0755); err != nil {
@@ -196,7 +196,7 @@ func writeMirrorBlocks(boxID string, data map[string][]string) error {
return err
}
if boxID != "" {
- // 加密 box 的镜像索引写入前加密
+ // 加密笔记本的镜像索引写入前加密
enc, encErr := encryptAVData(boxID, raw)
if encErr != nil {
return encErr
@@ -219,7 +219,7 @@ func avBoxIDFromPath(absPath string) string {
return ""
}
boxID := parts[0]
- // 全局路径的第一段是 "storage",加密 box 路径的第一段是 boxID(节点 ID 格式)
+ // 全局路径的第一段是 "storage",加密笔记本路径的第一段是 boxID(节点 ID 格式)
if boxID == "storage" {
return ""
}
diff --git a/kernel/av/mirror.go b/kernel/av/mirror.go
index 351c583b3f..0798de45b5 100644
--- a/kernel/av/mirror.go
+++ b/kernel/av/mirror.go
@@ -21,7 +21,7 @@ func GetBlockRels() (ret map[string][]string) {
for k, v := range readMirrorBlocks("") {
ret[k] = v
}
- // 加密 box 的镜像索引(已打开的)
+ // 加密笔记本的镜像索引(已打开的)
if AVEncryptedBoxIDs != nil {
for _, encBoxID := range AVEncryptedBoxIDs() {
for k, v := range readMirrorBlocks(encBoxID) {
@@ -76,7 +76,7 @@ func BatchUpsertBlockRel(nodes []*ast.Node) {
AttributeViewBlocksLock.Lock()
defer AttributeViewBlocksLock.Unlock()
- // 按 boxID 分桶:普通 box 的 avID 写全局镜像,加密 box 的 avID 写笔记本级镜像
+ // 按 boxID 分桶:普通 box 的 avID 写全局镜像,加密笔记本的 avID 写笔记本级镜像
boxAvBlocks := map[string]map[string][]string{} // boxID → avBlocks
for _, n := range nodes {
diff --git a/kernel/av/relation.go b/kernel/av/relation.go
index c52d0382d0..3d8719ab36 100644
--- a/kernel/av/relation.go
+++ b/kernel/av/relation.go
@@ -80,7 +80,7 @@ func writeRelations(boxID string, avRels map[string][]string) {
}
// relationsBoxIDByAvID 由 destAvID 反查归属 boxID,决定 relations 索引的存储位置。
-// 加密 box 的 AV 返回其 boxID;普通 box 的 AV 返回空串(全局路径)。
+// 加密笔记本的 AV 返回其 boxID;普通 box 的 AV 返回空串(全局路径)。
func relationsBoxIDByAvID(avID string) string {
_, boxID := FindAttributeViewPath(avID)
return boxID
diff --git a/kernel/filesys/crypto_hook.go b/kernel/filesys/crypto_hook.go
index 9e8e217b1a..bd26f5c457 100644
--- a/kernel/filesys/crypto_hook.go
+++ b/kernel/filesys/crypto_hook.go
@@ -31,7 +31,7 @@ import (
var DEKProvider func(boxID string) ([]byte, error)
// encryptData 若 boxID 是已解锁的加密 box,用 fileKey(DEK 派生子密钥)加密 data 并绑定 boxID 为 AAD;
-// 非加密 box 原样返回;加密但未解锁时返回 error,拒绝写盘(防止明文泄漏)。
+// 非加密笔记本原样返回;加密但未解锁时返回 error,拒绝写盘(防止明文泄漏)。
func encryptData(boxID string, data []byte) ([]byte, error) {
if DEKProvider == nil {
return data, nil
@@ -47,7 +47,7 @@ func encryptData(boxID string, data []byte) ([]byte, error) {
return util.EncryptWithAAD(fileKey, data, []byte(boxID))
}
-// decryptData 对应解密。非加密 box 原样返回;加密但未解锁时返回 error,拒绝读盘。
+// decryptData 对应解密。非加密笔记本原样返回;加密但未解锁时返回 error,拒绝读盘。
func decryptData(boxID string, data []byte) ([]byte, error) {
if DEKProvider == nil {
return data, nil
diff --git a/kernel/filesys/tree.go b/kernel/filesys/tree.go
index 37ea5161c4..62aaee29ca 100644
--- a/kernel/filesys/tree.go
+++ b/kernel/filesys/tree.go
@@ -50,7 +50,7 @@ func LoadTrees(ids []string) (ret map[string]*parse.Tree) {
bts := treenode.GetBlockTrees(ids)
- // 全局 blocktree 未命中的 id,遍历已打开的加密 box 查找
+ // 全局 blocktree 未命中的 id,遍历已打开的加密笔记本查找
foundSet := map[string]bool{}
for id := range bts {
foundSet[id] = true
@@ -157,7 +157,7 @@ func LoadTreeWithFix(boxID, p string, luteEngine *lute.Lute) (ret *parse.Tree, n
return
}
- // 加密笔记本的 .sy 是密文,读盘后解密成明文供后续解析;非加密 box 原样返回
+ // 加密笔记本的 .sy 是密文,读盘后解密成明文供后续解析;非加密笔记本原样返回
if data, err = decryptData(boxID, data); nil != err {
logging.LogErrorf("decrypt tree [%s] failed: %s", p, err)
return
@@ -246,7 +246,7 @@ func LoadTreeByData(data []byte, boxID, p string, luteEngine *lute.Lute) (ret *p
func DocIAL(absPath string) (ret map[string]string) {
// 加密笔记本的 .sy 是密文,流式 jsoniter 解析无法处理,需先整体读+解密。
- // 反推 boxID:路径形如 <DataDir>/<boxID>/...;非加密 box 走原流式逻辑。
+ // 反推 boxID:路径形如 <DataDir>/<boxID>/...;非加密笔记本走原流式逻辑。
boxID := docIALBoxID(absPath)
if boxID != "" && DEKProvider != nil {
if dek, err := DEKProvider(boxID); err == nil && dek != nil {
@@ -331,7 +331,7 @@ func WriteTree(tree *parse.Tree) (size uint64, err error) {
return
}
} else {
- // 读盘比对:加密 box 的磁盘数据是密文,需先解密成明文再与 data 比对
+ // 读盘比对:加密笔记本的磁盘数据是密文,需先解密成明文再与 data 比对
if diskData, readErr := filelock.ReadFile(filePath); nil == readErr {
decDisk, decErr := decryptData(tree.Box, diskData)
if decErr == nil && len(decDisk) == len(data) && bytes.Equal(decDisk, data) {
diff --git a/kernel/model/assets.go b/kernel/model/assets.go
index 3dd5bdd8b8..0aea71ea79 100644
--- a/kernel/model/assets.go
+++ b/kernel/model/assets.go
@@ -69,8 +69,8 @@ func GetAssetImgSize(assetPath string) (width, height int) {
return
}
-// GetAssetPathByHash 按 hash 查已存在的 asset 路径用于去重。boxID 非空且为加密 box 时返回空——
-// 加密 box 不参与全局去重(避免复用普通明文 asset);普通 box 走全局 cache/SQL(加密 box 数据不在全局表)。
+// GetAssetPathByHash 按 hash 查已存在的 asset 路径用于去重。boxID 非空且为加密笔记本时返回空——
+// 加密笔记本不参与全局去重(避免复用普通明文 asset);普通 box 走全局 cache/SQL(加密笔记本数据不在全局表)。
func GetAssetPathByHash(hash, boxID string) string {
if boxID != "" && IsEncryptedBox(boxID) {
return "" // 加密 box:跳过全局去重,强制新写(防跨边界复用明文 asset)
@@ -634,7 +634,7 @@ func getAssetAbsPath(relativePath string, includeEncrypted bool) (absPath string
}
for _, notebook := range notebooks {
if !includeEncrypted && IsEncryptedBox(notebook.ID) {
- continue // 加密 box 的资源不参与全局路径解析(孤岛,资源不跨边界)
+ continue // 加密笔记本的资源不参与全局路径解析(孤岛,资源不跨边界)
}
notebookAbsPath := filepath.Join(util.DataDir, notebook.ID)
filelock.Walk(notebookAbsPath, func(path string, d fs.DirEntry, err error) error {
@@ -1127,7 +1127,7 @@ func UnusedAssets(sorted bool) (ret []*UnusedItem) {
if err != nil {
return
}
- // 排除加密笔记本的资源:加密 box 锁定时 loadTree 失败会误判引用关系,
+ // 排除加密笔记本的资源:加密笔记本锁定时 loadTree 失败会误判引用关系,
// 且加密笔记本是孤岛,资源不参与全局未引用清理
for dest, absPath := range assetsPathMap {
if boxID := ExtractBoxIDFromAssetsPath(absPath); boxID != "" && IsEncryptedBox(boxID) {
diff --git a/kernel/model/attribute_view.go b/kernel/model/attribute_view.go
index a79dc71ec9..790f8ecb12 100644
--- a/kernel/model/attribute_view.go
+++ b/kernel/model/attribute_view.go
@@ -255,8 +255,8 @@ func getAvIDs(tree *parse.Tree, allAvIDs []string) (ret []string) {
func getAllAvIDs() (ret []string, err error) {
ret = []string{}
- // 只扫全局 AV 目录。加密 box 的 AV 存在笔记本级目录(密文),不参与全局枚举——
- // 未引用清理功能在加密 box 锁定时无法确认引用关系(loadTree 失败),枚举加密 AV 有误删风险
+ // 只扫全局 AV 目录。加密笔记本的 AV 存在笔记本级目录(密文),不参与全局枚举——
+ // 未引用清理功能在加密笔记本锁定时无法确认引用关系(loadTree 失败),枚举加密 AV 有误删风险
entries, err := os.ReadDir(filepath.Join(util.DataDir, "storage", "av"))
if nil != err {
return
@@ -1637,7 +1637,7 @@ func insertItemAfter(items []string, item, previousItemID string) []string {
}
func DuplicateDatabaseBlock(avID string) (newAvID, newBlockID string, err error) {
- // 加密 box 的 AV 定义在笔记本级目录,通过 fallback 查找实际路径
+ // 加密笔记本的 AV 定义在笔记本级目录,通过 fallback 查找实际路径
oldAvPath, avBoxID := av.FindAttributeViewPath(avID)
if oldAvPath == "" {
oldAvPath = av.GetAttributeViewDataPath(avID)
@@ -1655,7 +1655,7 @@ func DuplicateDatabaseBlock(avID string) (newAvID, newBlockID string, err error)
return
}
- // 加密 box 的 AV 是密文,需先解密再处理(av.DecryptAVData 内部按 box 加密/已解锁路由)
+ // 加密笔记本的 AV 是密文,需先解密再处理(av.DecryptAVData 内部按 box 加密/已解锁路由)
if avBoxID != "" && IsEncryptedBox(avBoxID) {
var decErr error
data, decErr = av.DecryptAVData(avBoxID, data)
@@ -1693,7 +1693,7 @@ func DuplicateDatabaseBlock(avID string) (newAvID, newBlockID string, err error)
return
}
- // 加密 box 的新 AV 定义也存笔记本级目录,且需 avKey 加密
+ // 加密笔记本的新 AV 定义也存笔记本级目录,且需 avKey 加密
newAvPath := filepath.Join(util.DataDir, "storage", "av", newAvID+".json")
if avBoxID != "" {
newAvPath = filepath.Join(util.DataDir, avBoxID, "storage", "av", newAvID+".json")
@@ -1922,7 +1922,7 @@ func SearchAttributeView(keyword string, excludeAvIDs []string) (ret []*AvSearch
keywords := strings.Fields(keyword)
var avSearchTmpResults []*AvSearchTempResult
- // 只扫全局 AV 目录。加密 box 的 AV 不参与全局搜索——避免跨加密边界暴露数据库名等元信息
+ // 只扫全局 AV 目录。加密笔记本的 AV 不参与全局搜索——避免跨加密边界暴露数据库名等元信息
avDir := filepath.Join(util.DataDir, "storage", "av")
entries, err := os.ReadDir(avDir)
if err != nil {
diff --git a/kernel/model/attribute_view_render.go b/kernel/model/attribute_view_render.go
index 3f98dbc352..de890cb885 100644
--- a/kernel/model/attribute_view_render.go
+++ b/kernel/model/attribute_view_render.go
@@ -56,7 +56,7 @@ func RenderAttributeView(blockID, avID, viewID, query string, page, pageSize int
}
}
- // 通过 fallback 查找 AV 定义路径(普通 box 全局,加密 box 笔记本级)
+ // 通过 fallback 查找 AV 定义路径(普通 box 全局,加密笔记本笔记本级)
existPath, _ := av.FindAttributeViewPath(avID)
if "" == existPath {
// fallback 找不到时按全局路径检查(首次创建场景)
@@ -540,7 +540,7 @@ func getRenderAttributeViewView(attrView *av.AttributeView, viewID, nodeID strin
}
// avBoxIDFromRepoPath 从快照文件路径反查 boxID。
-// 全局路径 /storage/av/<avID>.json 返回空串;加密 box 路径 /<boxID>/storage/av/<avID>.json 返回 boxID。
+// 全局路径 /storage/av/<avID>.json 返回空串;加密笔记本路径 /<boxID>/storage/av/<avID>.json 返回 boxID。
func avBoxIDFromRepoPath(repoPath string) string {
parts := strings.Split(repoPath, "/")
// 全局路径: ["", "storage", "av", "xxx.json"] → parts[1]=="storage"
@@ -568,7 +568,7 @@ func RenderRepoSnapshotAttributeView(indexID, avID string) (viewable av.Viewable
}
var avFile *entity.File
for _, f := range files {
- // 匹配全局 /storage/av/<avID>.json 或加密 box /<boxID>/storage/av/<avID>.json
+ // 匹配全局 /storage/av/<avID>.json 或加密笔记本/<boxID>/storage/av/<avID>.json
if strings.HasSuffix(f.Path, "/storage/av/"+avID+".json") {
avFile = f
break
@@ -684,7 +684,7 @@ func RenderHistoryAttributeView(blockID, avID, viewID, query string, page, pageS
}
// 加密笔记本的历史 AV 定义是密文,需要解密后才能解析。
- // 从路径提取 boxID,提取不到时遍历所有已打开的加密 box 尝试解密。
+ // 从路径提取 boxID,提取不到时遍历所有已打开的加密笔记本尝试解密。
avAbsSlash := filepath.ToSlash(avJSONPath)
var histBoxID string
if idx := strings.Index(avAbsSlash, "/storage/av/"); idx > 0 {
@@ -704,7 +704,7 @@ func RenderHistoryAttributeView(blockID, avID, viewID, query string, page, pageS
return
}
} else {
- // 路径没提取到 boxID(如历史目录无 boxID 前缀的旧路径),尝试遍历已打开的加密 box 解密
+ // 路径没提取到 boxID(如历史目录无 boxID 前缀的旧路径),尝试遍历已打开的加密笔记本解密
for _, encBoxID := range treenode.GetOpenedEncryptedBoxIDs() {
if dec, decErr := av.DecryptAVData(encBoxID, data); decErr == nil {
data = dec
diff --git a/kernel/model/backlink.go b/kernel/model/backlink.go
index a5fe4b4d2e..83854b0767 100644
--- a/kernel/model/backlink.go
+++ b/kernel/model/backlink.go
@@ -44,7 +44,7 @@ func RefreshBacklink(id string) {
}
func refreshRefsByDefID(defID string) {
- // 全局查 + 加密 box fallback
+ // 全局查 + 加密笔记本fallback
refs := sql.QueryRefsByDefID(defID, true)
if len(refs) == 0 {
for _, encBoxID := range treenode.GetOpenedEncryptedBoxIDs() {
diff --git a/kernel/model/blockinfo.go b/kernel/model/blockinfo.go
index 00a3ada28d..ea2687b8b1 100644
--- a/kernel/model/blockinfo.go
+++ b/kernel/model/blockinfo.go
@@ -398,7 +398,7 @@ func GetBlockRefs(defID string) (refDefs []*RefDefs, originalRefBlockIDs map[str
return
}
- // 加密 box 的 refs 在加密 db,用 bt.BoxID 路由
+ // 加密笔记本的 refs 在加密 db,用 bt.BoxID 路由
refDefs = queryBlockRefDefsInBox(bt, bt.BoxID)
originalRefBlockIDs = buildBacklinkListItemRefsInBox(refDefs, bt.BoxID)
return
diff --git a/kernel/model/encrypted_ops.go b/kernel/model/encrypted_ops.go
index fe56bf1587..14ca49f84e 100644
--- a/kernel/model/encrypted_ops.go
+++ b/kernel/model/encrypted_ops.go
@@ -24,9 +24,9 @@ import (
// 本文件提供加密笔记本的专用操作函数。每个函数接收 boxID,路由到加密 db。
// 与原函数(GetBlockRefText、GetDoc 等)完全独立,原函数行为不变。
-// 调用方为 API handler 层:当请求带 notebook 参数且为加密 box 时,调这里的 InBox 版。
+// 调用方为 API handler 层:当请求带 notebook 参数且为加密笔记本时,调这里的 InBox 版。
-// GetBlockRefTextInBox 在指定加密 box 内解析块引锚文本。
+// GetBlockRefTextInBox 在指定加密笔记本内解析块引锚文本。
func GetBlockRefTextInBox(id, boxID string) string {
FlushTxQueue()
@@ -59,7 +59,7 @@ func GetBlockRefTextInBox(id, boxID string) string {
return getNodeRefText(node)
}
-// GetRefTextInBox 在指定加密 box 内查块的引用文本(SQL 查询版,不走文件系统)。
+// GetRefTextInBox 在指定加密笔记本内查块的引用文本(SQL 查询版,不走文件系统)。
func GetRefTextInBox(defBlockID, boxID string) string {
return sql.GetRefTextInBox(defBlockID, boxID)
}
diff --git a/kernel/model/export.go b/kernel/model/export.go
index 46a1bb95f3..506069c680 100644
--- a/kernel/model/export.go
+++ b/kernel/model/export.go
@@ -682,7 +682,7 @@ func ExportResources(resourcePaths []string, mainName string) (exportFilePath st
resourceBaseName := filepath.Base(resourceFullPath) // 资源名称
resourceCopyPath := filepath.Join(exportFolderPath, resourceBaseName) // 资源副本完整路径
- // 加密 box 未解锁时拒绝导出(copyAssetDecryptIfEncrypted 锁定时复制密文,这里提前拦截避免产出无效文件)
+ // 加密笔记本未解锁时拒绝导出(copyAssetDecryptIfEncrypted 锁定时复制密文,这里提前拦截避免产出无效文件)
if resBoxID := ExtractBoxIDFromAssetsPath(resourceFullPath); resBoxID != "" && IsEncryptedBox(resBoxID) && !IsBoxUnlocked(resBoxID) {
err = errors.New(Conf.Language(314))
return
@@ -2123,7 +2123,7 @@ func exportSYZip(boxID, rootDirPath, baseFolderName string, docPaths []string) (
// 按文件夹结构复制选择的树
// 注意:tree 已被 filesys.LoadTree 透明解密成明文,这里序列化为明文 JSON 写盘
- // (不可 filelock.ReadFile 直接读盘,加密 box 的磁盘 .sy 是密文)。
+ // (不可 filelock.ReadFile 直接读盘,加密笔记本的磁盘 .sy 是密文)。
total := len(trees) + len(refTrees)
for _, tree := range trees {
writePath := strings.TrimPrefix(tree.Path, rootDirPath)
@@ -2346,7 +2346,7 @@ func exportSYZip(boxID, rootDirPath, baseFolderName string, docPaths []string) (
}
func exportAv(avID, exportStorageAvDir, exportFolder string, assetPathMap map[string]string) {
- // 用 box-aware 路径解析 + 自动解密读取 AV 定义明文(加密 box 的 AV 在 <boxID>/storage/av/,
+ // 用 box-aware 路径解析 + 自动解密读取 AV 定义明文(加密笔记本的 AV 在 <boxID>/storage/av/,
// GetAttributeViewDataPath 只查全局路径会漏;filelock.Copy 会拷密文)。
avData, readErr := av.ReadAttributeViewData(avID)
if readErr != nil {
@@ -2952,7 +2952,7 @@ func exportTree(tree *parse.Tree, wysiwyg, keepFold, avHiddenCol bool,
}
avID := n.AttributeViewID
- // 用 box-aware 路径解析(加密 box 的 AV 在 <boxID>/storage/av/,GetAttributeViewDataPath 只查全局会漏)
+ // 用 box-aware 路径解析(加密笔记本的 AV 在 <boxID>/storage/av/,GetAttributeViewDataPath 只查全局会漏)
if avJSONPath, _ := av.FindAttributeViewPath(avID); "" == avJSONPath {
return ast.WalkContinue
}
diff --git a/kernel/model/file.go b/kernel/model/file.go
index 6b2f573ddf..c222b579ac 100644
--- a/kernel/model/file.go
+++ b/kernel/model/file.go
@@ -502,7 +502,7 @@ func GetDoc(startID, endID, id string, index int, query string, queryTypes, quer
}
// GetDocInBox 与 GetDoc 一致,但按 boxID 路由到加密 db 或全局 db。
-// 加密 box 打开文档时传入 boxID,blocktree/content 查询走加密 db;boxID 为空时 fall-through 全局 db。
+// 加密笔记本打开文档时传入 boxID,blocktree/content 查询走加密 db;boxID 为空时 fall-through 全局 db。
func GetDocInBox(startID, endID, id string, index int, query string, queryTypes, querySubTypes map[string]bool, queryMethod, mode int, size int, isBacklink bool, originalRefBlockIDs map[string]string, highlight bool, boxID string) (
blockCount int, dom, parentID, parent2ID, rootID, typ string, eof, scroll bool, boxIDOut, docPath string, isBacklinkExpand bool, keywords []string, err error) {
//os.MkdirAll("pprof", 0755)
@@ -1393,7 +1393,7 @@ func MoveDocs(fromPaths []string, toBoxID, toPath string, callback any) (err err
}
}
- // 禁止跨加密边界移动文档:加密笔记本是孤岛,不同加密 box 各有独立 DEK,
+ // 禁止跨加密边界移动文档:加密笔记本是孤岛,不同加密笔记本各有独立 DEK,
// 跨边界移动(普通↔加密、加密 A↔加密 B)会导致密文用错 DEK 损坏数据
for _, fromBox := range pathsBoxes {
if fromBox.ID != toBox.ID && !IsSameCryptoBoundary(fromBox.ID, toBox.ID) {
diff --git a/kernel/model/filesys_init.go b/kernel/model/filesys_init.go
index 1c52b65b94..4d071cfcf8 100644
--- a/kernel/model/filesys_init.go
+++ b/kernel/model/filesys_init.go
@@ -25,7 +25,7 @@ import (
// init 把加密相关的回调注入各底层包,让它们能查询 box 的 DEK / 加密状态。
// filesys / av / sql / treenode 不能直接 import model(循环依赖),故通过回调注入。
-// sql / treenode 的路由函数据此 fail-closed:加密 box 未解锁时绝不回退全局库。
+// sql / treenode 的路由函数据此 fail-closed:加密笔记本未解锁时绝不回退全局库。
func init() {
filesys.DEKProvider = GetDEKIfUnlocked
av.AVDEKProvider = GetDEKIfUnlocked
diff --git a/kernel/model/heading.go b/kernel/model/heading.go
index 7c20a8a9f3..ce71d21bd1 100644
--- a/kernel/model/heading.go
+++ b/kernel/model/heading.go
@@ -178,7 +178,7 @@ func Doc2Heading(srcID, targetID string, after bool) (srcTreeBox, srcTreePath st
}
// 禁止跨加密边界:Doc2Heading 会合并 srcTree 和 targetTree 的内容,
- // 不同加密 box 各有独立 DEK,跨边界合并会导致密文用错 DEK 损坏数据
+ // 不同加密笔记本各有独立 DEK,跨边界合并会导致密文用错 DEK 损坏数据
if !IsSameCryptoBoundary(srcTree.Box, targetTree.Box) {
err = errors.New(Conf.Language(313))
return
diff --git a/kernel/model/history.go b/kernel/model/history.go
index 2202f8534b..81a4790af6 100644
--- a/kernel/model/history.go
+++ b/kernel/model/history.go
@@ -328,7 +328,7 @@ func RollbackDocHistory(historyPath string) (err error) {
avNodes := tree.Root.ChildrenByType(ast.NodeAttributeView)
for _, avNode := range avNodes {
srcAvPath := filepath.Join(historyDir, "storage", "av", avNode.AttributeViewID+".json")
- // 加密 box 的 AV 定义在笔记本级目录
+ // 加密笔记本的 AV 定义在笔记本级目录
destAvPath := filepath.Join(util.DataDir, "storage", "av", avNode.AttributeViewID+".json")
if IsEncryptedBox(boxID) {
// 历史目录里 AV 也可能在 boxID 子目录下
@@ -491,13 +491,13 @@ func RollbackAssetsHistory(historyPath string) (err error) {
}
from := historyPath
- // 从路径提取 boxID 判断是否加密 box 的资源
+ // 从路径提取 boxID 判断是否加密笔记本的资源
relPath := strings.TrimPrefix(filepath.ToSlash(historyPath), filepath.ToSlash(util.HistoryDir))
relPath = strings.TrimPrefix(relPath, "/")
pathParts := strings.SplitN(relPath, "/", 3)
to := filepath.Join(util.DataDir, "assets", filepath.Base(historyPath))
if len(pathParts) >= 2 && IsEncryptedBox(pathParts[1]) {
- // 加密 box 的资源回滚到笔记本级 assets 目录
+ // 加密笔记本的资源回滚到笔记本级 assets 目录
to = filepath.Join(util.DataDir, pathParts[1], "assets", filepath.Base(historyPath))
if err = os.MkdirAll(filepath.Dir(to), 0755); err != nil {
return
@@ -541,13 +541,13 @@ func RollbackAttributeViewHistory(historyPath string) (err error) {
}
from := historyPath
- // 从路径提取 boxID 判断是否加密 box 的 AV
+ // 从路径提取 boxID 判断是否加密笔记本的 AV
relPath := strings.TrimPrefix(filepath.ToSlash(historyPath), filepath.ToSlash(util.HistoryDir))
relPath = strings.TrimPrefix(relPath, "/")
pathParts := strings.SplitN(relPath, "/", 3)
to := filepath.Join(util.DataDir, "storage", "av", filepath.Base(historyPath))
if len(pathParts) >= 2 && IsEncryptedBox(pathParts[1]) {
- // 加密 box 的 AV 定义回滚到笔记本级目录
+ // 加密笔记本的 AV 定义回滚到笔记本级目录
to = filepath.Join(util.DataDir, pathParts[1], "storage", "av", filepath.Base(historyPath))
if err = os.MkdirAll(filepath.Dir(to), 0755); err != nil {
return
@@ -971,7 +971,7 @@ func generateTreeHistory(tree *parse.Tree, historyDir string) {
func generateAvHistoryInTree(tree *parse.Tree, historyDir string) {
avNodes := tree.Root.ChildrenByType(ast.NodeAttributeView)
for _, avNode := range avNodes {
- // 用 FindAttributeViewPath 解析 AV 定义的真实路径(自动路由全局/加密 box 笔记本级)
+ // 用 FindAttributeViewPath 解析 AV 定义的真实路径(自动路由全局/加密笔记本笔记本级)
srcAvPath, _ := av.FindAttributeViewPath(avNode.AttributeViewID)
if srcAvPath == "" {
continue
diff --git a/kernel/model/import.go b/kernel/model/import.go
index c2e1b79526..a695e636a9 100644
--- a/kernel/model/import.go
+++ b/kernel/model/import.go
@@ -413,7 +413,7 @@ func ImportSY(zipPath, boxID, toPath string) (err error) {
if readErr != nil {
return readErr
}
- // av.EncryptAVData 内部按 box 是否加密/已解锁路由,加密 box 用 avKey+AAD
+ // av.EncryptAVData 内部按 box 是否加密/已解锁路由,加密笔记本用 avKey+AAD
enc, encErr := av.EncryptAVData(boxID, src)
if encErr != nil {
return encErr
@@ -678,7 +678,7 @@ func ImportSY(zipPath, boxID, toPath string) (err error) {
}
}
- // AV 定义已在 storage 删除前处理(加密 box DEK 加密拷到笔记本级,
+ // AV 定义已在 storage 删除前处理(加密笔记本DEK 加密拷到笔记本级,
// 普通 box 拷到全局 storage/av/),这里不再重复处理
// 将包含的自定义表情统一移动到 data/emojis/ 下
diff --git a/kernel/model/index.go b/kernel/model/index.go
index 6a05e3d9d1..8052ba5155 100644
--- a/kernel/model/index.go
+++ b/kernel/model/index.go
@@ -229,7 +229,7 @@ func IndexRefs() {
util.SetBootDetails(Conf.Language(305))
var defBlockIDs []string
- defBlockBoxes := map[string]string{} // defBlockID -> boxID,加密 box 下需按 box 路由后续加载
+ defBlockBoxes := map[string]string{} // defBlockID -> boxID,加密笔记本下需按 box 路由后续加载
luteEngine := util.NewLute()
boxes := Conf.GetOpenedBoxes()
for _, box := range boxes {
@@ -239,7 +239,7 @@ func IndexRefs() {
for _, treeAbsPath := range paths {
p := filepath.ToSlash(strings.TrimPrefix(treeAbsPath, filepath.Join(util.DataDir, box.ID)))
- // 加密 box 的 .sy 是密文,必须走 filesys.LoadTree 透明解密;无法用 bytes.Contains 预检
+ // 加密笔记本的 .sy 是密文,必须走 filesys.LoadTree 透明解密;无法用 bytes.Contains 预检
var tree *parse.Tree
if encryptedBox {
loadTree, loadErr := filesys.LoadTree(box.ID, p, luteEngine)
@@ -290,7 +290,7 @@ func IndexRefs() {
bootProgressPart := int32(10.0 / float64(size))
for _, defBlockID := range defBlockIDs {
- // 加密 box 的 defBlock 在加密 blocktree db,需按 box 路由加载
+ // 加密笔记本的 defBlock 在加密 blocktree db,需按 box 路由加载
var defTree *parse.Tree
var loadErr error
if boxID, ok := defBlockBoxes[defBlockID]; ok && IsEncryptedBox(boxID) {
diff --git a/kernel/model/repository.go b/kernel/model/repository.go
index caa5048a3f..51aafbf473 100644
--- a/kernel/model/repository.go
+++ b/kernel/model/repository.go
@@ -616,7 +616,7 @@ func decryptRepoDataIfNeeded(data []byte, filePath string) []byte {
}
dek, err := GetDEKIfUnlocked(boxID)
if err != nil {
- return data // 加密 box 未解锁:同步快照解析返回原数据(调用方解析失败时按文件名回退)
+ return data // 加密笔记本未解锁:同步快照解析返回原数据(调用方解析失败时按文件名回退)
}
plain, err := DecryptFile(boxID, dek, data)
if err != nil {
diff --git a/kernel/model/search.go b/kernel/model/search.go
index 1d18679128..3347e37b96 100644
--- a/kernel/model/search.go
+++ b/kernel/model/search.go
@@ -323,7 +323,7 @@ func SearchRefBlock(id, rootID, keyword string, beforeLen int, isSquareBrackets,
}
// SearchRefBlockInBox 与 SearchRefBlock 一致,但按 boxID 路由到加密 db 或全局 db。
-// 加密 box 内搜索块引目标时传入 boxID,只搜该 box 自己的加密 db,避免跨加密边界引用。
+// 加密笔记本内搜索块引目标时传入 boxID,只搜该 box 自己的加密 db,避免跨加密边界引用。
func SearchRefBlockInBox(id, rootID, keyword string, beforeLen int, isSquareBrackets, isDatabase bool, boxID string) (ret []*Block, newDoc bool) {
cachedTrees := map[string]*parse.Tree{}
nodeTrees := map[string]*parse.Tree{}
@@ -1176,7 +1176,7 @@ func FullTextSearchBlock(query string, boxes, paths []string, types, subTypes ma
}
// FullTextSearchBlockInBox 与 FullTextSearchBlock 一致,但按 boxID 路由到加密 db 或全局 db。
-// 加密 box 内搜索时传入 boxID,所有 sql/treenode 查询走加密 db;boxID 为空时 fall-through 全局 db。
+// 加密笔记本内搜索时传入 boxID,所有 sql/treenode 查询走加密 db;boxID 为空时 fall-through 全局 db。
func FullTextSearchBlockInBox(query string, boxes, paths []string, types, subTypes map[string]bool, method, orderBy, groupBy, page, pageSize int, boxID string) (ret []*Block, matchedBlockCount, matchedRootCount, pageCount int, docMode bool) {
ret = []*Block{}
if "" == query {
diff --git a/kernel/model/transaction.go b/kernel/model/transaction.go
index 825663004d..b3d835a05c 100644
--- a/kernel/model/transaction.go
+++ b/kernel/model/transaction.go
@@ -1242,7 +1242,7 @@ func (tx *Transaction) doInsert(operation *Operation) (ret *TxErr) {
}
}
if nil == bt {
- // 全局 blocktree 找不到时,遍历已打开的加密 box 查找
+ // 全局 blocktree 找不到时,遍历已打开的加密笔记本查找
for _, encBoxID := range treenode.GetOpenedEncryptedBoxIDs() {
encBTs := treenode.GetBlockTreesInBox([]string{operation.ParentID, operation.PreviousID, operation.NextID}, encBoxID)
for _, b := range encBTs {
@@ -1510,7 +1510,7 @@ func (tx *Transaction) doUpdate(operation *Operation) (ret *TxErr) {
oldDefIDs := getRefDefIDs(oldNode)
var newDefIDs []string
- // 兜底校验:禁止跨加密边界块引(加密 box ↔ 普通 box,或不同加密 box 之间)
+ // 兜底校验:禁止跨加密边界块引(加密笔记本↔ 普通 box,或不同加密笔记本之间)
degradeCrossBoundaryBlockRefs(subTree.Root, subTree.Box)
var unlinks []*ast.Node
@@ -2057,7 +2057,7 @@ func (tx *Transaction) loadTree(id string) (ret *parse.Tree, err error) {
var rootID, box, p string
bt := treenode.GetBlockTree(id)
if nil == bt {
- // 全局 blocktree 找不到时,遍历已打开的加密 box 查找
+ // 全局 blocktree 找不到时,遍历已打开的加密笔记本查找
for _, encBoxID := range treenode.GetOpenedEncryptedBoxIDs() {
if encBT := treenode.GetBlockTreeInBox(id, encBoxID); nil != encBT {
bt = encBT
diff --git a/kernel/model/tree.go b/kernel/model/tree.go
index fa40a269cc..2732aaf69b 100644
--- a/kernel/model/tree.go
+++ b/kernel/model/tree.go
@@ -168,8 +168,8 @@ func loadTree(localPath string, luteEngine *lute.Lute) (ret *parse.Tree, err err
return
}
- // 加密笔记本的 .sy 是密文,需先解密。从路径反推 boxID,已解锁的加密 box 用 fileKey 解密;
- // 加密 box 未解锁时返回错误(fail-closed);非加密 box 原样 data。
+ // 加密笔记本的 .sy 是密文,需先解密。从路径反推 boxID,已解锁的加密笔记本用 fileKey 解密;
+ // 加密笔记本未解锁时返回错误(fail-closed);非加密笔记本原样 data。
if boxID := extractBoxIDFromPath(localPath); boxID != "" && IsEncryptedBox(boxID) {
dek, dekErr := GetDEKIfUnlocked(boxID)
if dekErr != nil {
@@ -212,7 +212,7 @@ func LoadTreeByBlockIDWithReindexInBox(id, boxID string) (ret *parse.Tree, err e
bt := treenode.GetBlockTreeInBox(id, boxID)
if nil == bt && "" == boxID {
- // boxID 未知时(如通用打开入口),遍历所有已打开的加密 box 查找
+ // boxID 未知时(如通用打开入口),遍历所有已打开的加密笔记本查找
for _, encBoxID := range treenode.GetOpenedEncryptedBoxIDs() {
if encBT := treenode.GetBlockTreeInBox(id, encBoxID); nil != encBT {
bt = encBT
@@ -269,7 +269,7 @@ func loadTreeByBlockIDInBox(id, boxID string) (ret *parse.Tree, err error) {
bt := treenode.GetBlockTreeInBox(id, boxID)
if nil == bt && "" == boxID {
- // boxID 未知时(如通用打开入口),遍历所有已打开的加密 box 查找
+ // boxID 未知时(如通用打开入口),遍历所有已打开的加密笔记本查找
for _, encBoxID := range treenode.GetOpenedEncryptedBoxIDs() {
if encBT := treenode.GetBlockTreeInBox(id, encBoxID); nil != encBT {
bt = encBT
diff --git a/kernel/model/upload.go b/kernel/model/upload.go
index 1451a3e9d7..a6d4f94546 100644
--- a/kernel/model/upload.go
+++ b/kernel/model/upload.go
@@ -131,7 +131,7 @@ func InsertLocalAssets(id string, assetAbsPaths []string, isUpload bool) (succMa
p := "assets/" + fName
succMap[baseName] = p
if !IsEncryptedBox(bt.BoxID) {
- cache.SetAssetHash(hash, p) // 加密 box 不写全局 cache,避免跨边界去重污染
+ cache.SetAssetHash(hash, p) // 加密笔记本不写全局 cache,避免跨边界去重污染
}
}
}
@@ -156,7 +156,7 @@ func Upload(c *gin.Context) {
id := form.Value["id"][0]
bt := treenode.GetBlockTree(id)
if nil == bt {
- // 全局 blocktree 找不到时,遍历已打开的加密 box 查找
+ // 全局 blocktree 找不到时,遍历已打开的加密笔记本查找
for _, encBoxID := range treenode.GetOpenedEncryptedBoxIDs() {
if encBT := treenode.GetBlockTreeInBox(id, encBoxID); nil != encBT {
bt = encBT
@@ -373,7 +373,7 @@ func Upload(c *gin.Context) {
p := strings.TrimPrefix(path.Join(relAssetsDirPath, fName), "/")
succMap[baseName] = p
if uploadBoxID == "" || !IsEncryptedBox(uploadBoxID) {
- cache.SetAssetHash(hash, p) // 加密 box 不写全局 cache
+ cache.SetAssetHash(hash, p) // 加密笔记本不写全局 cache
}
}
}
@@ -404,9 +404,9 @@ func getAssetsDir(boxLocalPath, docDirLocalPath string) (assets string) {
}
// writeAssetFile 把 src 的内容写入 writePath。从 writePath 反查真实 boxID 决定是否加密——
-// 不轻信传入的 boxID(调用方可能未传,或 assetsDirPath 指向加密 box 但 id 为空)。
-// 加密 box 必须已解锁(DEK 在内存)才写入;加密但未解锁返回错误(fail-closed,避免明文落盘)。
-// 非加密 box 按 reader 直接写(走 filelock.WriteFileByReader 原路径,保留锁语义)。
+// 不轻信传入的 boxID(调用方可能未传,或 assetsDirPath 指向加密笔记本但 id 为空)。
+// 加密笔记本必须已解锁(DEK 在内存)才写入;加密但未解锁返回错误(fail-closed,避免明文落盘)。
+// 非加密笔记本按 reader 直接写(走 filelock.WriteFileByReader 原路径,保留锁语义)。
func writeAssetFile(writePath string, src io.Reader, boxID string) (err error) {
// 从 writePath 反查真实 boxID,与传入 boxID 交叉校验
pathBoxID := ExtractBoxIDFromAssetsPath(writePath)
@@ -425,7 +425,7 @@ func writeAssetFile(writePath string, src io.Reader, boxID string) (err error) {
if actualBoxID != "" && IsEncryptedBox(actualBoxID) {
dek, dekErr := GetDEKIfUnlocked(actualBoxID)
if dekErr != nil {
- // 加密 box 未解锁:拒绝写入,避免明文落盘(深度防御,见 issue #18034)
+ // 加密笔记本未解锁:拒绝写入,避免明文落盘(深度防御,见 issue #18034)
return dekErr
}
// 已解锁的加密 box:全读 → 加密 → 落盘
@@ -442,18 +442,18 @@ func writeAssetFile(writePath string, src io.Reader, boxID string) (err error) {
return filelock.WriteFileByReader(writePath, src)
}
-// encryptedAssetName 生成加密 box 专用的无语义资源文件名:uuid-blockID.ext。
+// encryptedAssetName 生成加密笔记本专用的无语义资源文件名:uuid-blockID.ext。
// 原始语义文件名(如"合同.pdf")通过 writeAssetNameMapping 存入加密映射,磁盘上只保留随机名。
func encryptedAssetName(ext, blockID string) string {
return gulu.Rand.String(16) + "-" + blockID + ext
}
-// assetNameMappingPath 返回加密 box 资源名映射文件路径 <boxID>/assets/.names.json。
+// assetNameMappingPath 返回加密笔记本资源名映射文件路径 <boxID>/assets/.names.json。
func assetNameMappingPath(boxID string) string {
return filepath.Join(util.DataDir, boxID, "assets", ".names.json")
}
-// writeAssetNameMapping 把"磁盘文件名 -> 原始文件名"映射写入加密 box 的 .names.json(DEK 加密落盘)。
+// writeAssetNameMapping 把"磁盘文件名 -> 原始文件名"映射写入加密笔记本的 .names.json(DEK 加密落盘)。
func writeAssetNameMapping(boxID, diskName, originalName string) {
if boxID == "" || !IsEncryptedBox(boxID) {
return
@@ -480,7 +480,7 @@ func writeAssetNameMapping(boxID, diskName, originalName string) {
}
}
-// readAssetNameMapping 读取加密 box 的资源名映射(DEK 解密)。未解锁或文件不存在时返回空 map。
+// readAssetNameMapping 读取加密笔记本的资源名映射(DEK 解密)。未解锁或文件不存在时返回空 map。
func readAssetNameMapping(boxID string) map[string]string {
ret := map[string]string{}
if boxID == "" || !IsEncryptedBox(boxID) {
@@ -507,7 +507,7 @@ func readAssetNameMapping(boxID string) map[string]string {
return ret
}
-// LookupAssetOriginalName 查询加密 box 资源的原始文件名(供下载 Content-Disposition 等展示用)。
+// LookupAssetOriginalName 查询加密笔记本资源的原始文件名(供下载 Content-Disposition 等展示用)。
// 未找到时返回空串。
func LookupAssetOriginalName(boxID, diskName string) string {
return readAssetNameMapping(boxID)[diskName]
diff --git a/kernel/sql/block_ref_query.go b/kernel/sql/block_ref_query.go
index c55d5e0ade..452e4cc5fc 100644
--- a/kernel/sql/block_ref_query.go
+++ b/kernel/sql/block_ref_query.go
@@ -158,7 +158,7 @@ func QueryRootBlockRefCount() (ret map[string]int) {
ret[id] = cnt
}
- // 加密 box 的 refs
+ // 加密笔记本的 refs
for _, encBoxID := range GetEncryptedBoxIDs() {
encRows, encErr := queryForBox(encBoxID, "SELECT def_block_root_id, COUNT(DISTINCT block_id) AS ref_cnt FROM refs GROUP BY def_block_root_id")
if encErr != nil {
diff --git a/kernel/sql/database.go b/kernel/sql/database.go
index 0bf25e93a8..8b8f105f18 100644
--- a/kernel/sql/database.go
+++ b/kernel/sql/database.go
@@ -61,7 +61,7 @@ var (
// IsEncryptedBoxFn 由 model 层注入,用于判断 boxID 是否为加密笔记本。
// sql 包不直接 import model(循环依赖),路由函数据此 fail-closed:
- // 加密 box 未解锁时绝不回退全局库,避免加密 box 索引污染全局明文库。
+ // 加密笔记本未解锁时绝不回退全局库,避免加密笔记本索引污染全局明文库。
IsEncryptedBoxFn func(boxID string) bool
)
@@ -1435,8 +1435,8 @@ func query(query string, args ...any) (*sql.Rows, error) {
return db.Query(query, args...)
}
-// queryRowForBox 按 box 路由查询单行。加密 box 用独立 db,否则用全局 db。boxID 为空走全局。
-// 加密 box 未解锁(db 未打开)时返回 nil——绝不回退全局库,避免加密 box 查询命中全局明文库。
+// queryRowForBox 按 box 路由查询单行。加密笔记本用独立 db,否则用全局 db。boxID 为空走全局。
+// 加密笔记本未解锁(db 未打开)时返回 nil——绝不回退全局库,避免加密笔记本查询命中全局明文库。
func queryRowForBox(boxID, query string, args ...any) *sql.Row {
query = strings.TrimSpace(query)
if "" == query {
@@ -1447,7 +1447,7 @@ func queryRowForBox(boxID, query string, args ...any) *sql.Row {
return boxDB.QueryRow(query, args...)
}
if IsEncryptedBoxFn != nil && IsEncryptedBoxFn(boxID) {
- // 加密 box 未解锁:fail-closed,不回退全局库
+ // 加密笔记本未解锁:fail-closed,不回退全局库
return nil
}
if nil == db {
@@ -1456,8 +1456,8 @@ func queryRowForBox(boxID, query string, args ...any) *sql.Row {
return db.QueryRow(query, args...)
}
-// queryForBox 按 box 路由查询多行。加密 box 用独立 db,否则用全局 db。boxID 为空走全局。
-// 加密 box 未解锁时返回错误——绝不回退全局库。
+// queryForBox 按 box 路由查询多行。加密笔记本用独立 db,否则用全局 db。boxID 为空走全局。
+// 加密笔记本未解锁时返回错误——绝不回退全局库。
func queryForBox(boxID, query string, args ...any) (*sql.Rows, error) {
query = strings.TrimSpace(query)
if "" == query {
@@ -1875,7 +1875,7 @@ func CloseEncryptedDB(boxID string) {
}
}
-// GetEncryptedDB 返回加密 box 的 db 句柄;未打开返回 nil。
+// GetEncryptedDB 返回加密笔记本的 db 句柄;未打开返回 nil。
func GetEncryptedDB(boxID string) *sql.DB {
if v, ok := encryptedDBs.Load(boxID); ok {
if boxDB, ok := v.(*sql.DB); ok {
@@ -1915,9 +1915,9 @@ func RemoveAllEncryptedDBFiles() {
}
}
-// beginTxForBox 按 box 选 db 开事务。加密 box 用其独立 db,否则用全局 db。
-// beginTxForBox 按 box 选 db 开事务。加密 box 用其独立 db,否则用全局 db。
-// 加密 box 未解锁时返回错误——绝不回退全局库,避免加密 box 的索引写操作污染全局明文库。
+// beginTxForBox 按 box 选 db 开事务。加密笔记本用其独立 db,否则用全局 db。
+// beginTxForBox 按 box 选 db 开事务。加密笔记本用其独立 db,否则用全局 db。
+// 加密笔记本未解锁时返回错误——绝不回退全局库,避免加密笔记本的索引写操作污染全局明文库。
func beginTxForBox(box string) (tx *sql.Tx, err error) {
if boxDB := GetEncryptedDB(box); boxDB != nil {
if tx, err = boxDB.Begin(); err != nil {
@@ -1927,13 +1927,13 @@ func beginTxForBox(box string) (tx *sql.Tx, err error) {
return
}
if IsEncryptedBoxFn != nil && IsEncryptedBoxFn(box) {
- // 加密 box 未解锁:fail-closed,不回退全局库
+ // 加密笔记本未解锁:fail-closed,不回退全局库
return nil, errors.New("encrypted box db not opened for box " + box)
}
return beginTx()
}
-// initEncryptedDBTables 在加密 box db 上建内容表(幂等)。结构与全局 siyuan.db 的内容表一致,
+// initEncryptedDBTables 在加密笔记本db 上建内容表(幂等)。结构与全局 siyuan.db 的内容表一致,
// 但不含 stat 表(加密 db 不参与版本管理)。首次打开时调用。
func initEncryptedDBTables(boxDB *sql.DB) (err error) {
tables := []string{
diff --git a/kernel/sql/encrypted_query.go b/kernel/sql/encrypted_query.go
index 0f9e53f2ef..43ad61345f 100644
--- a/kernel/sql/encrypted_query.go
+++ b/kernel/sql/encrypted_query.go
@@ -27,7 +27,7 @@ import (
)
// 本文件提供加密笔记本的 box-scoped 读查询。每个函数接收 boxID,路由到加密 db(已打开)或全局 db。
-// 调用方(model 层)在加密 box 上下文里改用这些 InBox 版;全局功能继续用原函数。
+// 调用方(model 层)在加密笔记本上下文里改用这些 InBox 版;全局功能继续用原函数。
// GetBlockInBox 按 id 在指定 box 的 db 里查 block。boxID 为空则查全局 db。
func GetBlockInBox(id, boxID string) (ret *Block) {
@@ -376,7 +376,7 @@ func QueryRefsByDefIDRefIDInBox(defBlockID, refBlockID, boxID string) (ret []*Re
return
}
-// QueryRefsRecentInBox 按 boxID 路由查最近引用,用于加密 box 内的块引搜索。
+// QueryRefsRecentInBox 按 boxID 路由查最近引用,用于加密笔记本内的块引搜索。
func QueryRefsRecentInBox(onlyDoc bool, typeFilter string, ignoreLines []string, boxID string) (ret []*Ref) {
stmt := "SELECT r.* FROM refs AS r, blocks AS b WHERE b.id = r.def_block_id AND b.type IN " + typeFilter
if onlyDoc {
diff --git a/kernel/sql/queue.go b/kernel/sql/queue.go
index 48d92617ca..cf6e38859d 100644
--- a/kernel/sql/queue.go
+++ b/kernel/sql/queue.go
@@ -282,8 +282,8 @@ func execOp(op *dbQueueOperation, tx *sql.Tx, context map[string]any) (err error
}
case "delete_box":
// 清理 box 的内容索引。事务由 beginTxForBox(op.boxID()) 按所属库路由:
- // 普通 box 落到全局 siyuan.db,加密 box 落到其独立 content db,删除均生效。
- // 注意加密 box 关闭时必须清空 content db 数据,否则下次 Mount 的全量 Index
+ // 普通 box 落到全局 siyuan.db,加密笔记本落到其独立 content db,删除均生效。
+ // 注意加密笔记本关闭时必须清空 content db 数据,否则下次 Mount 的全量 Index
// 会用纯 INSERT 在无主键的 blocks 表上叠加重复行,导致搜索结果翻倍。
err = deleteByBoxTx(tx, op.box)
if nil == err {
diff --git a/kernel/treenode/av.go b/kernel/treenode/av.go
index 59dca3dfe2..c52be08fcb 100644
--- a/kernel/treenode/av.go
+++ b/kernel/treenode/av.go
@@ -21,7 +21,7 @@ import (
)
// GetMirrorAttrViewBlockIDs 返回引用了该 AV 的所有块 ID(仅含块树仍存在的)。
-// 通过 av.GetBlockRels 获取镜像索引,已合并全局 + 所有已打开加密 box 的镜像数据(加密感知)。
+// 通过 av.GetBlockRels 获取镜像索引,已合并全局 + 所有已打开加密笔记本的镜像数据(加密感知)。
func GetMirrorAttrViewBlockIDs(avID string) (ret []string) {
ret = []string{}
avBlocks := av.GetBlockRels()
diff --git a/kernel/treenode/blocktree.go b/kernel/treenode/blocktree.go
index c909ee2a04..1c22eb98c1 100644
--- a/kernel/treenode/blocktree.go
+++ b/kernel/treenode/blocktree.go
@@ -168,7 +168,9 @@ func GetBlockTreeByBoxPath(boxID, path string) (ret *BlockTree) {
ret = &BlockTree{}
sqlStmt := "SELECT * FROM blocktrees WHERE box_id = ? AND path = ?"
row := queryRowForBox(boxID, sqlStmt, boxID, path)
- if row == nil { return }
+ if row == nil {
+ return
+ }
err := row.Scan(&ret.ID, &ret.RootID, &ret.ParentID, &ret.BoxID, &ret.Path, &ret.HPath, &ret.Updated, &ret.Type)
if err != nil {
ret = nil
@@ -209,7 +211,9 @@ func GetBlockTreeRootByPath(boxID, path string) (ret *BlockTree) {
ret = &BlockTree{}
sqlStmt := "SELECT * FROM blocktrees WHERE box_id = ? AND path = ? AND type = 'd'"
row := queryRowForBox(boxID, sqlStmt, boxID, path)
- if row == nil { return }
+ if row == nil {
+ return
+ }
err := row.Scan(&ret.ID, &ret.RootID, &ret.ParentID, &ret.BoxID, &ret.Path, &ret.HPath, &ret.Updated, &ret.Type)
if err != nil {
ret = nil
@@ -227,7 +231,9 @@ func GetBlockTreeRootByHPath(boxID, hPath string) (ret *BlockTree) {
hPath = gulu.Str.RemoveInvisible(hPath)
sqlStmt := "SELECT * FROM blocktrees WHERE box_id = ? AND hpath = ? AND type = 'd'"
row := queryRowForBox(boxID, sqlStmt, boxID, hPath)
- if row == nil { return }
+ if row == nil {
+ return
+ }
err := row.Scan(&ret.ID, &ret.RootID, &ret.ParentID, &ret.BoxID, &ret.Path, &ret.HPath, &ret.Updated, &ret.Type)
if err != nil {
ret = nil
@@ -353,7 +359,7 @@ func ExistBlockTrees(ids []string) (ret map[string]bool) {
ret[id] = true
}
- // 全局 blocktree 未命中的 id,遍历已打开的加密 box 查找
+ // 全局 blocktree 未命中的 id,遍历已打开的加密笔记本查找
var missing []string
for id, found := range ret {
if !found {
@@ -416,7 +422,7 @@ func GetBlockTrees(ids []string) (ret map[string]*BlockTree) {
ret[block.ID] = &block
}
- // 全局未命中的 id,遍历已打开的加密 box 查找
+ // 全局未命中的 id,遍历已打开的加密笔记本查找
var missing []string
for _, id := range ids {
if _, ok := ret[id]; !ok {
@@ -454,7 +460,7 @@ func GetBlockTree(id string) (ret *BlockTree) {
if err != nil {
ret = nil
if errors.Is(err, sql.ErrNoRows) {
- // 全局 blocktree 未命中,遍历已打开的加密 box 查找
+ // 全局 blocktree 未命中,遍历已打开的加密笔记本查找
for _, encBoxID := range GetOpenedEncryptedBoxIDs() {
if encBT := GetBlockTreeInBox(id, encBoxID); nil != encBT {
return encBT
@@ -530,7 +536,9 @@ func RemoveBlockTreesByRootID(boxID, rootID string) {
func CountBlockTreesByPathPrefix(boxID, pathPrefix string) (ret int) {
sqlStmt := "SELECT COUNT(*) FROM blocktrees WHERE path LIKE ? AND box_id = ?"
row := queryRowForBox(boxID, sqlStmt, pathPrefix+"%", boxID)
- if row == nil { return }
+ if row == nil {
+ return
+ }
err := row.Scan(&ret)
if err != nil {
if errors.Is(err, sql.ErrNoRows) {
@@ -675,7 +683,7 @@ func IndexBlockTree(tree *parse.Tree) {
indexBlockTreeLock.Lock()
defer indexBlockTreeLock.Unlock()
- // 加密 box 用独立 blocktree db;非加密 box 用全局 db(两者都可能为 nil——重建过程中)
+ // 加密笔记本用独立 blocktree db;非加密笔记本用全局 db(两者都可能为 nil——重建过程中)
if nil == db && getEncryptedBlockTreeDB(tree.Box) == nil {
logging.LogErrorf("database is nil")
return
@@ -879,7 +887,7 @@ var encryptedBlockTreeDBs = &sync.Map{}
// IsEncryptedBoxFn 由 model 层注入,用于判断 boxID 是否为加密笔记本。
// treenode 包不直接 import model(循环依赖),路由函数据此 fail-closed:
-// 加密 box 未解锁时绝不回退全局库,避免加密 box 块树元数据污染全局明文 blocktree.db。
+// 加密笔记本未解锁时绝不回退全局库,避免加密笔记本块树元数据污染全局明文 blocktree.db。
var IsEncryptedBoxFn func(boxID string) bool
// OpenEncryptedBlockTreeDB 打开加密笔记本的独立 SQLCipher blocktree db。
@@ -950,7 +958,7 @@ func RemoveAllEncryptedBlockTreeDBFiles() {
}
}
-// getEncryptedBlockTreeDB 返回加密 box 的 blocktree db 句柄;未打开返回 nil。
+// getEncryptedBlockTreeDB 返回加密笔记本的 blocktree db 句柄;未打开返回 nil。
func getEncryptedBlockTreeDB(boxID string) *sql.DB {
if v, ok := encryptedBlockTreeDBs.Load(boxID); ok {
if boxDB, ok := v.(*sql.DB); ok {
@@ -975,8 +983,8 @@ func initEncryptedBlockTreeTables(boxDB *sql.DB) (err error) {
return
}
-// --- box-scoped wrapper(加密 box 用独立 db,否则用全局 db)---
-// 加密 box 未解锁(db 未打开)时 fail-closed:绝不回退全局库,避免加密 box 块树操作污染全局 blocktree.db。
+// --- box-scoped wrapper(加密笔记本用独立 db,否则用全局 db)---
+// 加密笔记本未解锁(db 未打开)时 fail-closed:绝不回退全局库,避免加密笔记本块树操作污染全局 blocktree.db。
func queryForBox(box, stmt string, args ...any) (*sql.Rows, error) {
if boxDB := getEncryptedBlockTreeDB(box); boxDB != nil {
@@ -1018,7 +1026,7 @@ func beginTxForBox(box string) (tx *sql.Tx, err error) {
return db.Begin()
}
-// --- InBox 读函数(加密 box 内浏览时调用方传 boxID,路由到加密 db) ---
+// --- InBox 读函数(加密笔记本内浏览时调用方传 boxID,路由到加密 db) ---
// GetBlockTreeInBox 按 id 在指定 box 的 db 里查块树。boxID 为空则查全局 db。
func GetBlockTreeInBox(id, boxID string) (ret *BlockTree) {
@@ -1029,7 +1037,7 @@ func GetBlockTreeInBox(id, boxID string) (ret *BlockTree) {
sqlStmt := "SELECT * FROM blocktrees WHERE id = ?"
row := queryRowForBox(boxID, sqlStmt, id)
if row == nil {
- return nil // 加密 box 未解锁,视作不存在
+ return nil // 加密笔记本未解锁,视作不存在
}
err := row.Scan(&ret.ID, &ret.RootID, &ret.ParentID, &ret.BoxID, &ret.Path, &ret.HPath, &ret.Updated, &ret.Type)
if err != nil {
@@ -1075,7 +1083,7 @@ func ExistBlockTreeInBox(id, boxID string) bool {
sqlStmt := "SELECT 1 FROM blocktrees WHERE id = ? LIMIT 1"
row := queryRowForBox(boxID, sqlStmt, id)
if row == nil {
- return false // 加密 box 未解锁,视作不存在
+ return false // 加密笔记本未解锁,视作不存在
}
var tmp any
return row.Scan(&tmp) == nil