siyuan-note/siyuan · error

mkdir master password migration dir failed

Error message

mkdir master password migration dir failed: %w

What it means

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.

Solutions

  1. Grant the kernel process write permission on the workspace data directory (chown/chmod)
  2. Remove or rename any regular file that occupies the migration directory path
  3. Free disk space and remount the filesystem read-write if necessary
  4. Verify the workspace path configuration points at the intended, writable location

Example fix

// diagnose
ls -ld <workspace>/data
// fix
sudo chown -R <user> <workspace>/data
// retry the master password change/migration
Defensive patterns

Strategy: try-catch

Validate before calling

dir := filepath.Dir(masterPasswordMigrationPath())
if st, err := os.Stat(dir); err == nil && !st.IsDir() {
    return errors.New("migration record path is occupied by a non-directory")
}
if err := os.WriteFile(filepath.Join(dir, ".write-test"), nil, 0600); err != nil {
    return fmt.Errorf("data dir not writable: %w", err)
}

Try / catch

if err := writeMasterPasswordMigration(m); err != nil {
    var pe *fs.PathError
    if errors.As(err, &pe) && errors.Is(pe.Err, fs.ErrPermission) {
        return fmt.Errorf("fix data dir permissions and retry the password migration: %w", err)
    }
    return err
}

Prevention

When it happens

Trigger: 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.

Common situations: 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.

Understand the failure class

Background: mkdir permission denied (EACCES): failed to create directory errors explained — this error's family across 32 libraries.

Related errors


AI-assisted analysis of siyuan-note/siyuan@9f775e8a12 (2026-09-19). Data as JSON: /api/errors/c24a9171cd1a7cf9. Report an issue: GitHub.

Appendix: source

Thrown at kernel/model/crypto.go:540

	NewWrappedDEK []byte `json:"newWrappedDEK"`
	NewWrapNonce  []byte `json:"newWrapNonce"`
	Metadata      []byte `json:"metadata"`
}

func masterPasswordMigrationPath() string {
	return filepath.Join(util.DataDir, ".siyuan", "master-password-migration.json")
}

func writeMasterPasswordMigration(m *masterPasswordMigration) error {
	masterPasswordMigrationMu.Lock()
	defer masterPasswordMigrationMu.Unlock()
	return writeMasterPasswordMigrationUnlocked(m)
}

func writeMasterPasswordMigrationUnlocked(m *masterPasswordMigration) error {
	p := masterPasswordMigrationPath()
	if err := os.MkdirAll(filepath.Dir(p), 0755); err != nil {
		return fmt.Errorf("mkdir master password migration dir failed: %w", err)
	}
	data, err := gulu.JSON.MarshalIndentJSON(m, "", "  ")
	if err != nil {
		return fmt.Errorf("marshal master password migration failed: %w", err)
	}
	return filelock.WriteFile(p, data)
}

func readMasterPasswordMigration() (*masterPasswordMigration, error) {
	masterPasswordMigrationMu.Lock()
	defer masterPasswordMigrationMu.Unlock()
	return readMasterPasswordMigrationUnlocked()
}

func readMasterPasswordMigrationUnlocked() (*masterPasswordMigration, error) {
	p := masterPasswordMigrationPath()
	if !filelock.IsExist(p) {
		return nil, nil

View on GitHub (pinned to 9f775e8a12)