{"record":{"id":"269a91560fd0a463","repo":"siyuan-note/siyuan","slug":"mkdir-notebook-crypto-backup-dir-failed-w","errorCode":null,"errorMessage":"mkdir notebook crypto backup dir failed: %w","messagePattern":"mkdir notebook crypto backup dir failed: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"kernel/model/crypto.go","lineNumber":400,"sourceCode":"\t\treturn errors.New(\"cannot generate notebook crypto backup without KEK\")\n\t}\n\tConf.m.Lock()\n\tnc := *Conf.NotebookCrypto // 值拷贝\n\tprepareBackupForWrite(&nc)\n\tnc.KEKMAC = computeKEKMAC(&nc, kek)\n\tif !notebookCryptoConfigurationComplete(&nc) {\n\t\tConf.m.Unlock()\n\t\treturn errors.New(\"cannot save incomplete notebook crypto configuration\")\n\t}\n\tConf.NotebookCrypto.Spec = nc.Spec\n\tConf.NotebookCrypto.BackupID = nc.BackupID\n\tConf.NotebookCrypto.CreatedAt = nc.CreatedAt\n\tConf.NotebookCrypto.Checksum = nc.Checksum\n\tConf.NotebookCrypto.KEKMAC = nc.KEKMAC // 保持 Conf 与备份文件的 KEKMAC 一致\n\tConf.m.Unlock()\n\tbackupPath := dataCryptoBackupPath()\n\tif err := os.MkdirAll(filepath.Dir(backupPath), 0755); err != nil {\n\t\treturn fmt.Errorf(\"mkdir notebook crypto backup dir failed: %w\", err)\n\t}\n\tdata, err := json.Marshal(nc)\n\tif err != nil {\n\t\treturn fmt.Errorf(\"marshal notebook crypto backup failed: %w\", err)\n\t}\n\tif err := atomicWriteFile(backupPath, data); err != nil {\n\t\treturn fmt.Errorf(\"write notebook crypto backup failed: %w\", err)\n\t}\n\treturn nil\n}\n\n// writeNotebookCryptoBackupData 将指定的 NotebookCrypto 写入备份文件（不依赖 Conf.NotebookCrypto）。\n// kek 必须非 nil：在 Checksum 定型后计算 KEKMAC，保证落盘 MAC 与落盘内容一致。\nfunc writeNotebookCryptoBackupData(nc *conf.NotebookCrypto, kek []byte) error {\n\tif kek == nil {\n\t\treturn errors.New(\"cannot generate notebook crypto backup without KEK\")\n\t}\n\tprepareBackupForWrite(nc)","sourceCodeStart":382,"sourceCodeEnd":418,"githubUrl":"https://github.com/siyuan-note/siyuan/blob/9f775e8a12daef8255556097396f9b2739078892/kernel/model/crypto.go#L382-L418","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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)"],"exampleFix":"# before\n$ ls -ld <DataDir>  # read-only or wrong owner\n# after\n$ sudo chown -R siyuan:siyuan <DataDir>\n$ chmod u+w <DataDir>","handlingStrategy":"try-catch","validationCode":"dir := filepath.Dir(dataCryptoBackupPath())\nif fi, err := os.Stat(dir); err == nil && !fi.IsDir() {\n    return errors.New(dir + \" exists as a file; remove it first\")\n}\nif err := unix.Access(filepath.Dir(dir), unix.W_OK); err != nil {\n    return errors.New(\"no write permission on data dir\")\n}","typeGuard":"null","tryCatchPattern":"if err := saveNotebookCryptoBackup(kek); err != nil {\n    var msg string\n    if _, perr := fmt.Sscanf(err.Error(), \"mkdir notebook crypto backup dir failed: %s\", &msg); perr == nil {\n        // fix OS-level cause (permissions/RO fs/path) then retry\n    }\n}","preventionTips":["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"],"tags":["filesystem","mkdir","permissions","backup"],"backgroundTag":"mkdir-permission-denied","analyzedSha":"9f775e8a12daef8255556097396f9b2739078892","analyzedAt":"2026-09-19T03:17:15.984Z","contentChangedAt":"2026-09-19T03:17:15.984Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}