{"record":{"id":"37a6b30b9ede90e0","repo":"siyuan-note/siyuan","slug":"mkdir-notebook-crypt-backup-dir-failed-w","errorCode":null,"errorMessage":"mkdir notebook crypt backup dir failed: %w","messagePattern":"mkdir notebook crypt backup dir failed: %w","errorType":"error_code","errorClass":null,"httpStatus":null,"severity":"error","filePath":"kernel/model/crypto.go","lineNumber":2529,"sourceCode":"// 全局备份存 MasterSalt/KEKVerifier，per-notebook 备份存 WrappedDEK/WrapNonce。\nconst notebookCryptoBackupFilename = \"notebook-crypto-backup.json\"\n\nfunc notebookCryptoBackupPath(boxID string) string {\n\treturn filepath.Join(util.DataDir, boxID, \".siyuan\", notebookCryptoBackupFilename)\n}\n\n// writeNotebookCryptBackup 写入加密笔记本的 BoxCrypt 备份。\n// 仅在 Encrypted=true 的笔记本上调用，配合 CreateEncryptedBox / ChangeMasterPassword 写入。\nfunc writeNotebookCryptBackup(boxID string, crypt *conf.BoxEncryption) error {\n\tif !ast.IsNodeIDPattern(boxID) {\n\t\treturn errors.New(\"invalid notebook ID\")\n\t}\n\tif err := validateBoxEncryption(crypt); err != nil {\n\t\treturn err\n\t}\n\tbackupPath := notebookCryptoBackupPath(boxID)\n\tif err := os.MkdirAll(filepath.Dir(backupPath), 0755); err != nil {\n\t\treturn fmt.Errorf(\"mkdir notebook crypt backup dir failed: %w\", err)\n\t}\n\tdata, err := gulu.JSON.MarshalIndentJSON(crypt, \"\", \"  \")\n\tif err != nil {\n\t\treturn fmt.Errorf(\"marshal notebook crypt backup failed: %w\", err)\n\t}\n\tif err := filelock.WriteFile(backupPath, data); err != nil {\n\t\treturn fmt.Errorf(\"write notebook crypt backup failed: %w\", err)\n\t}\n\treturn nil\n}\n\n// readNotebookCryptBackup 读取加密笔记本的 BoxCrypt 备份。\n// 备份文件不存在时返回 (nil, nil)，调用方据此区分\"非加密笔记本\"和\"备份不存在\"。\nfunc readNotebookCryptBackup(boxID string) (*conf.BoxEncryption, error) {\n\tif !ast.IsNodeIDPattern(boxID) {\n\t\treturn nil, errors.New(\"invalid notebook ID\")\n\t}\n\tbackupPath := notebookCryptoBackupPath(boxID)","sourceCodeStart":2511,"sourceCodeEnd":2547,"githubUrl":"https://github.com/siyuan-note/siyuan/blob/9f775e8a12daef8255556097396f9b2739078892/kernel/model/crypto.go#L2511-L2547","documentation":"writeNotebookCryptBackup wraps the os.MkdirAll error for <DataDir>/<boxID>/.siyuan/ with this message. Creating the backup directory failed at the OS level — the underlying cause (permission, read-only filesystem, ENOSPC, path is a file) is in the wrapped error.","triggerScenarios":"CreateEncryptedBox or ChangeMasterPassword on a notebook whose .siyuan directory cannot be created: read-only data directory, disk full, a file named .siyuan exists, or insufficient permissions (e.g. running as another user, Docker volume owned by root).","commonSituations":"Docker/Kubernetes volumes with wrong ownership; SiYuan installed under a system-protected path; antivirus locking the directory on Windows; read-only mount after a crash; workspace moved to a new disk without permissions.","solutions":["Check the wrapped %w error for the exact errno and fix it: chown/chmod the workspace data dir so the kernel user can write","Verify <DataDir>/<boxID>/.siyuan is a directory and not a regular file; remove/rename the offending file","Free disk space if ENOSPC, and remount the volume read-write","After fixing, retry ChangeMasterPassword/encrypt so the backup is written before relying on the notebook"],"exampleFix":"# inspect\nls -la <DataDir>/<boxID>/.siyuan\n# fix ownership (Docker case)\ndocker exec siyuan chown -R siyuan:siyuan /siyuan/workspace\n# or remount rw\nmount -o remount,rw /path/to/workspace","handlingStrategy":"try-catch","validationCode":"siyuanDir := filepath.Join(util.DataDir, boxID, \".siyuan\")\nif info, err := os.Stat(filepath.Dir(siyuanDir)); err != nil || !info.IsDir() {\n    return fmt.Errorf(\"notebook dir not writable: %v\", err)\n}","typeGuard":null,"tryCatchPattern":"if err := model.WriteNotebookCryptBackup(boxID, crypt); err != nil {\n    var pe *fs.PathError\n    if errors.As(err, &pe) && strings.Contains(err.Error(), \"mkdir\") {\n        // check perms/disk space/readonly mount, then retry once\n        fixPermissions(pe.Path)\n        return model.WriteNotebookCryptBackup(boxID, crypt)\n    }\n    return err\n}","preventionTips":["Ensure the kernel user owns the workspace Data directory (chown in Docker images)","Mount the workspace read-write; never place Data on read-only media","Confirm disk free space before encrypting notebooks","Check that .siyuan inside each notebook is a directory, not a file"],"tags":["filesystem","permissions","crypto"],"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"}