{"record":{"id":"c24a9171cd1a7cf9","repo":"siyuan-note/siyuan","slug":"mkdir-master-password-migration-dir-failed-w","errorCode":null,"errorMessage":"mkdir master password migration dir failed: %w","messagePattern":"mkdir master password migration dir failed: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"kernel/model/crypto.go","lineNumber":540,"sourceCode":"\tNewWrappedDEK []byte `json:\"newWrappedDEK\"`\n\tNewWrapNonce  []byte `json:\"newWrapNonce\"`\n\tMetadata      []byte `json:\"metadata\"`\n}\n\nfunc masterPasswordMigrationPath() string {\n\treturn filepath.Join(util.DataDir, \".siyuan\", \"master-password-migration.json\")\n}\n\nfunc writeMasterPasswordMigration(m *masterPasswordMigration) error {\n\tmasterPasswordMigrationMu.Lock()\n\tdefer masterPasswordMigrationMu.Unlock()\n\treturn writeMasterPasswordMigrationUnlocked(m)\n}\n\nfunc writeMasterPasswordMigrationUnlocked(m *masterPasswordMigration) error {\n\tp := masterPasswordMigrationPath()\n\tif err := os.MkdirAll(filepath.Dir(p), 0755); err != nil {\n\t\treturn fmt.Errorf(\"mkdir master password migration dir failed: %w\", err)\n\t}\n\tdata, err := gulu.JSON.MarshalIndentJSON(m, \"\", \"  \")\n\tif err != nil {\n\t\treturn fmt.Errorf(\"marshal master password migration failed: %w\", err)\n\t}\n\treturn filelock.WriteFile(p, data)\n}\n\nfunc readMasterPasswordMigration() (*masterPasswordMigration, error) {\n\tmasterPasswordMigrationMu.Lock()\n\tdefer masterPasswordMigrationMu.Unlock()\n\treturn readMasterPasswordMigrationUnlocked()\n}\n\nfunc readMasterPasswordMigrationUnlocked() (*masterPasswordMigration, error) {\n\tp := masterPasswordMigrationPath()\n\tif !filelock.IsExist(p) {\n\t\treturn nil, nil","sourceCodeStart":522,"sourceCodeEnd":558,"githubUrl":"https://github.com/siyuan-note/siyuan/blob/9f775e8a12daef8255556097396f9b2739078892/kernel/model/crypto.go#L522-L558","documentation":"writeMasterPasswordMigrationUnlocked persists the master-password migration record (containing wrapped keys for the migration) to its file under the data directory. It first creates the parent directory with os.MkdirAll; if that fails, the error is wrapped as 'mkdir master password migration dir failed'. Losing this file would jeopardize master-password migration recovery, so the failure is surfaced instead of ignored.","triggerScenarios":"os.MkdirAll(filepath.Dir(masterPasswordMigrationPath()), 0755) fails during writeMasterPasswordMigration or removeMasterPasswordMigrationBox: data directory missing and uncreatable, permission denied, read-only filesystem, path component occupied by a regular file, or disk full.","commonSituations":"Workspace data directory owned by root after running with sudo once; read-only volume remount after a crash; sandboxed environment blocking writes; the migration record path colliding with an existing file; cloud-sync client making the directory unavailable.","solutions":["Grant the kernel process write permission on the workspace data directory (chown/chmod)","Remove or rename any regular file that occupies the migration directory path","Free disk space and remount the filesystem read-write if necessary","Verify the workspace path configuration points at the intended, writable location"],"exampleFix":"// diagnose\nls -ld <workspace>/data\n// fix\nsudo chown -R <user> <workspace>/data\n// retry the master password change/migration","handlingStrategy":"try-catch","validationCode":"dir := filepath.Dir(masterPasswordMigrationPath())\nif st, err := os.Stat(dir); err == nil && !st.IsDir() {\n    return errors.New(\"migration record path is occupied by a non-directory\")\n}\nif err := os.WriteFile(filepath.Join(dir, \".write-test\"), nil, 0600); err != nil {\n    return fmt.Errorf(\"data dir not writable: %w\", err)\n}","typeGuard":null,"tryCatchPattern":"if err := writeMasterPasswordMigration(m); err != nil {\n    var pe *fs.PathError\n    if errors.As(err, &pe) && errors.Is(pe.Err, fs.ErrPermission) {\n        return fmt.Errorf(\"fix data dir permissions and retry the password migration: %w\", err)\n    }\n    return err\n}","preventionTips":["Keep the workspace data directory owned and writable by the kernel's run user","Avoid running the kernel with sudo (leaves root-owned artifacts that block later writes)","Check volume mount status (read-only remounts) after crashes before retrying migrations"],"tags":["go","filesystem","mkdir","migration","permissions"],"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"}