Skip to content

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

:art: Close encrypted notebooks via unmount0 on exit, skip unnecessary Unindex https://github.com/siyuan-note/siyuan/issues/18034

Daniel531fe70882de
diff --git a/kernel/model/conf.go b/kernel/model/conf.go
index a0949ba6fd..2de0e871bc 100644
--- a/kernel/model/conf.go
+++ b/kernel/model/conf.go
@@ -894,6 +894,13 @@ func Close(force, setCurrentWorkspace bool, execInstallPkg int) (exitCode int) {
}
Conf.Close()
+ // 退出前关闭已打开的加密笔记本(走 unmount0:落盘 + 生成历史 + 锁定),
+ // 确保编辑历史不丢失、DEK 不残留内存
+ for _, box := range Conf.GetOpenedBoxes() {
+ if IsEncryptedBox(box.ID) {
+ unmount0(box.ID)
+ }
+ }
sql.CloseDatabase()
closePushQueue()
util.SaveAssetsTexts()
diff --git a/kernel/model/mount.go b/kernel/model/mount.go
index 414e3d9ab2..73de8274c7 100644
--- a/kernel/model/mount.go
+++ b/kernel/model/mount.go
@@ -233,18 +233,18 @@ func unmount0(boxID string) {
boxConf := box.GetConf()
boxConf.Closed = true
box.SaveConf(boxConf)
- box.Unindex()
if boxConf.Encrypted {
- // 加密笔记本关闭:先等待事务队列和 SQL 索引队列落盘(确保 pending 写入已持久化到加密 .sy),
- // 再 ClearDEK(=LockBox)清除 DEK 并删除加密 db 文件。加密索引可由 box.Index() 全量重建,
- // 关闭即删文件避免残留旧索引数据导致下次解锁叠加重复行。
+ // 加密笔记本关闭:跳过 Unindex(索引 db 马上要删,逐条删是白费),
+ // 先等待事务队列和 SQL 索引队列落盘(确保 pending 写入已持久化到加密 .sy),
+ // 生成文件历史,再 ClearDEK(=LockBox)清除 DEK 并删除加密 db 文件。
+ // 加密索引可由 box.Index() 全量重建,关闭即删文件避免残留旧索引数据导致下次解锁叠加重复行。
FlushTxQueue()
sql.FlushQueue()
// 关闭前生成一次文件历史:锁定后定时器无法为加密笔记本生成历史(不在 GetOpenedBoxes 里)
- if box := Conf.Box(boxID); nil != box {
- GenerateFileHistoryForBox(box)
- }
+ GenerateFileHistoryForBox(box)
ClearDEK(boxID)
+ } else {
+ box.Unindex()
}
}