siyuan-note/siyuan · error
stat encrypted notebook history conf
Error message
stat encrypted notebook history conf [%s] failed: %w
What it means
When no notebook-crypto-backup.json exists in a history box, isEncryptedHistoryBoxDir probes .siyuan/conf.json to read the box's Encrypted flag. Not-exist means "not an encrypted box" (returns false, nil); this error is thrown when the stat itself fails with another error (permissions, I/O, ENOTDIR), since the box's status is then unknown and callers must not treat recovery material as absent.
Solutions
- Fix read permissions on <boxDir>/.siyuan/conf.json and its parent directories
- If .siyuan is a file or broken symlink rather than a directory, restore the proper directory from backup
- Release locks from security/backup software and retry the scan
- Restore the box's .siyuan/conf.json from a backup copy, then rerun history detection
Example fix
// before: ignoring the error and assuming the box is plain
enc, err := isEncryptedHistoryBoxDir(dir)
if err != nil { continue }
// after: verify the .siyuan layout before classification
siyuanInfo, sErr := os.Stat(filepath.Join(dir, ".siyuan"))
if sErr != nil || !siyuanInfo.IsDir() {
return fmt.Errorf("box %s: .siyuan missing or not a directory: %w", dir, sErr)
}
enc, err = isEncryptedHistoryBoxDir(dir) Defensive patterns
Strategy: try-catch
Validate before calling
confPath := filepath.Join(boxDir, ".siyuan", "conf.json")
if _, err := os.Stat(confPath); err != nil && !os.IsNotExist(err) {
// stat-level problem — fix before calling history classification
} Type guard
func confReadable(confPath string) bool {
f, err := os.Open(confPath)
if err != nil { return false }
defer f.Close()
return true
} Try / catch
enc, err := isEncryptedHistoryBoxDir(boxDir)
if err != nil {
var perr *fs.PathError
if errors.As(err, &perr) && errors.Is(perr.Err, syscall.EACCES) {
// repair permissions on .siyuan/conf.json, then retry
}
return err
} Prevention
- Ensure .siyuan is always a plain readable directory
- Restore conf.json from backup if the box metadata is damaged
- Stop backup/AV tools from locking workspace files during scans
- Keep conf.json intact when copying or syncing boxes
When it happens
Trigger: Callers (encryptedNotebookHistoryBoxDirs, hasEncryptedNotebookDeleteHistory, IsEncryptedHistoryPath) hitting a box dir where os.Stat on <boxDir>/.siyuan/conf.json fails with EACCES, EIO, ENOTDIR (e.g. .siyuan is a file), or a similar non-ENOENT error.
Common situations: Broken restore leaving .siyuan as a regular file; restrictive permissions after migrating the workspace between users; antivirus or backup locking; disk errors.
Understand the failure class
Background: "failed to read file", EACCES, ENOENT and "could not read <path>" errors: when a program can't read a file from disk — this error's family across 49 libraries.
Related errors
- read encrypted notebook history conf
- stat encrypted notebook history backup
- cannot allocate a replacement history directory
- create history directory
- get history directory failed
AI-assisted analysis of siyuan-note/siyuan@9f775e8a12 (2026-09-19).
Data as JSON: /api/errors/738f3748fde1739f.
Report an issue: GitHub.
Appendix: source
Thrown at kernel/model/crypto.go:946
}
// isEncryptedHistoryBoxDir 判断历史目录中的 boxID 子目录是否属于加密笔记本。
// 优先看 notebook-crypto-backup.json(删除前随 box 目录整体备份,是加密身份的权威标识),
// 再 fallback 到 conf.json 的 Encrypted 标志。
func isEncryptedHistoryBoxDir(boxDir string) (bool, error) {
siyuanDir := filepath.Join(boxDir, ".siyuan")
backupPath := filepath.Join(siyuanDir, "notebook-crypto-backup.json")
if _, err := os.Stat(backupPath); err == nil {
return true, nil
} else if !os.IsNotExist(err) {
return false, fmt.Errorf("stat encrypted notebook history backup [%s] failed: %w", boxDir, err)
}
confPath := filepath.Join(siyuanDir, "conf.json")
if _, err := os.Stat(confPath); err != nil {
if os.IsNotExist(err) {
return false, nil
}
return false, fmt.Errorf("stat encrypted notebook history conf [%s] failed: %w", boxDir, err)
}
data, err := filelock.ReadFile(confPath)
if err != nil {
return false, fmt.Errorf("read encrypted notebook history conf [%s] failed: %w", boxDir, err)
}
var boxConf conf.BoxConf
if err = gulu.JSON.UnmarshalJSON(data, &boxConf); err != nil {
return false, fmt.Errorf("parse encrypted notebook history conf [%s] failed: %w", boxDir, err)
}
return boxConf.Encrypted, nil
}
// cachedDEKs 缓存已解锁加密笔记本的 DEK,按 boxID 索引。
// KEK 不全局缓存("严格每笔记本单独解锁"语义):UnlockBox 临时派生 KEK 解出 DEK 后即丢弃 KEK,
// 仅保留 per-box DEK 供后续读写加解密。
var (
cachedDEKs = map[string][]byte{}
cachedDEKsLock sync.RWMutexView on GitHub (pinned to 9f775e8a12)