siyuan-note/siyuan · error
mkdir notebook crypto backup dir failed
Error message
mkdir notebook crypto backup dir failed: %w
What it means
saveNotebookCryptoBackup wraps an os.MkdirAll failure for the directory containing the backup file (<DataDir>/.siyuan/) as "mkdir notebook crypto backup dir failed: %w". The backup cannot be written until its parent directory exists; this error surfaces OS-level problems (permissions, read-only filesystem, path issues) verbatim through %w.
Solutions
- Check/fix permissions on the workspace data directory so the process user can create subdirectories
- Verify the volume is writable and has free space
- If <DataDir>/.siyuan exists as a file, remove or rename it so MkdirAll can create the directory
- Inspect the wrapped OS error in the message (%w) for the exact cause (EACCES vs EROFS vs ENOSPC)
Example fix
# before $ ls -ld <DataDir> # read-only or wrong owner # after $ sudo chown -R siyuan:siyuan <DataDir> $ chmod u+w <DataDir>
Defensive patterns
Strategy: try-catch
Validate before calling
dir := filepath.Dir(dataCryptoBackupPath())
if fi, err := os.Stat(dir); err == nil && !fi.IsDir() {
return errors.New(dir + " exists as a file; remove it first")
}
if err := unix.Access(filepath.Dir(dir), unix.W_OK); err != nil {
return errors.New("no write permission on data dir")
} Type guard
null
Try / catch
if err := saveNotebookCryptoBackup(kek); err != nil {
var msg string
if _, perr := fmt.Sscanf(err.Error(), "mkdir notebook crypto backup dir failed: %s", &msg); perr == nil {
// fix OS-level cause (permissions/RO fs/path) then retry
}
} Prevention
- Provision the data directory with correct ownership before first kernel start
- Never mount the workspace volume read-only for normal operation
- Keep .siyuan as a directory — never let a file occupy that path
- Check disk space and mount flags in deployment health checks
When it happens
Trigger: Any call into saveNotebookCryptoBackup (or the equivalent mkdir inside writeNotebookCryptoBackupData) where the data directory is missing and cannot be created — permission-denied on <DataDir>, read-only volume, disk full, or a path occupied by a regular file.
Common situations: Workspace moved to a read-only mount; data directory owned by another user after restoring from backup; <DataDir>/.siyuan exists as a file instead of a directory; running the kernel under a service account without write access.
Understand the failure class
Background: mkdir permission denied (EACCES): failed to create directory errors explained — this error's family across 32 libraries.
Related errors
- create AI editor actions directory failed
- create conf dir failed
- create import dir failed:
- create plugin dir [ ] failed
- failed to make directory
AI-assisted analysis of siyuan-note/siyuan@9f775e8a12 (2026-09-19).
Data as JSON: /api/errors/269a91560fd0a463.
Report an issue: GitHub.
Appendix: source
Thrown at kernel/model/crypto.go:400
return errors.New("cannot generate notebook crypto backup without KEK")
}
Conf.m.Lock()
nc := *Conf.NotebookCrypto // 值拷贝
prepareBackupForWrite(&nc)
nc.KEKMAC = computeKEKMAC(&nc, kek)
if !notebookCryptoConfigurationComplete(&nc) {
Conf.m.Unlock()
return errors.New("cannot save incomplete notebook crypto configuration")
}
Conf.NotebookCrypto.Spec = nc.Spec
Conf.NotebookCrypto.BackupID = nc.BackupID
Conf.NotebookCrypto.CreatedAt = nc.CreatedAt
Conf.NotebookCrypto.Checksum = nc.Checksum
Conf.NotebookCrypto.KEKMAC = nc.KEKMAC // 保持 Conf 与备份文件的 KEKMAC 一致
Conf.m.Unlock()
backupPath := dataCryptoBackupPath()
if err := os.MkdirAll(filepath.Dir(backupPath), 0755); err != nil {
return fmt.Errorf("mkdir notebook crypto backup dir failed: %w", err)
}
data, err := json.Marshal(nc)
if err != nil {
return fmt.Errorf("marshal notebook crypto backup failed: %w", err)
}
if err := atomicWriteFile(backupPath, data); err != nil {
return fmt.Errorf("write notebook crypto backup failed: %w", err)
}
return nil
}
// writeNotebookCryptoBackupData 将指定的 NotebookCrypto 写入备份文件(不依赖 Conf.NotebookCrypto)。
// kek 必须非 nil:在 Checksum 定型后计算 KEKMAC,保证落盘 MAC 与落盘内容一致。
func writeNotebookCryptoBackupData(nc *conf.NotebookCrypto, kek []byte) error {
if kek == nil {
return errors.New("cannot generate notebook crypto backup without KEK")
}
prepareBackupForWrite(nc)View on GitHub (pinned to 9f775e8a12)