siyuan-note/siyuan · error

create dir for publishAccess.json

Error message

create dir for publishAccess.json [%s] failed: %s

What it means

SetPublishAccess fails with this message when os.MkdirAll on the directory containing <DataDir>/.siyuan/publishAccess.json returns an error. The in-memory access map is updated first, but persistence aborts, so the new publish access will be lost on restart. The formatted message includes the target path and the underlying OS error.

Solutions

  1. Check the kernel log for the full path and OS error, then fix the underlying filesystem problem (permissions, ownership, disk full)
  2. Verify <DataDir>/.siyuan is a directory, not a file; remove/rename the stray file
  3. Ensure the process user can write to the workspace directory (chown/chmod)
  4. Re-run the publish access update after fixing so the change is persisted

Example fix

# before
ls -la <workspace>/.siyuan   # -> file or root-owned dir
# after
rm <workspace>/.siyuan        # if it is a stray file
chown -R siyuan:siyuan <workspace>/.siyuan
Defensive patterns

Strategy: try-catch

Validate before calling

const dir = path.join(dataDir, ".siyuan");
if (!fs.existsSync(dir)) fs.mkdirSync(dir, {recursive: true});
if (!fs.statSync(dir).isDirectory()) throw new Error(dir + " must be a directory");
fs.accessSync(dir, fs.constants.W_OK);

Try / catch

err := model.SetPublishAccess(access)
if err != nil {
    if strings.Contains(err.Error(), "create dir for publishAccess.json") {
        // fix filesystem permissions/mount, then retry
    }
    return err
}

Prevention

When it happens

Trigger: SetPublishAccess when <workspace>/.siyuan cannot be created — e.g. DataDir points at a read-only volume, permission denied on the parent directory, a file named .siyuan exists where the directory should be, or the disk is full.

Common situations: Workspace on a read-only mount or restored from a backup with wrong ownership; Docker volume mounted read-only; an accidental file named .siyuan in the workspace root; running the kernel as a user without write permission to the data directory.

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/84e5a0d5aa54b04d. Report an issue: GitHub.

Appendix: source

Thrown at kernel/model/publish_access.go:126

		return
	}
	ret = publishAccess
	return
}

func SetPublishAccess(inputPublishAccess PublishAccess) (err error) {
	now := time.Now().UnixMilli()
	publishAccessLock.Lock()
	defer publishAccessLock.Unlock()
	publishAccessLastModified = now
	publishAccess = inputPublishAccess

	publishAccessPath := filepath.Join(util.DataDir, ".siyuan", "publishAccess.json")
	err = os.MkdirAll(filepath.Dir(publishAccessPath), 0755)
	if err != nil {
		msg := fmt.Sprintf("create dir for publishAccess.json [%s] failed: %s", publishAccessPath, err)
		logging.LogError(msg)
		err = errors.New(msg)
		return
	}

	data, err := gulu.JSON.MarshalJSON(inputPublishAccess)
	if err != nil {
		logging.LogErrorf("marshal publishAccess.json [%s] failed: %s", publishAccessPath, err)
		return
	}

	err = filelock.WriteFile(publishAccessPath, data)
	if err != nil {
		msg := fmt.Sprintf("write publishAccess.json [%s] failed: %s", publishAccessPath, err)
		logging.LogError(msg)
		err = errors.New(msg)
		return
	}
	return
}

View on GitHub (pinned to 9f775e8a12)