siyuan-note/siyuan · error

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

Error message

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

What it means

Thrown by SetPublishAccess() when os.MkdirAll fails to create the parent directory of publishAccess.json (located at <DataDir>/.siyuan/). This is a filesystem-level error: the kernel cannot create the directory tree needed to persist publish access settings. The error message includes the full path and the underlying OS error for diagnostics.

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 251596fc0d)

Solutions

  1. Check filesystem permissions: ensure the SiYuan process user has write access to util.DataDir and its parent.
  2. If running in Docker, verify the volume mount is read-write (rw, not ro).
  3. Remove any file blocking the .siyuan directory creation.
  4. Check available disk space with df -h.
  5. Verify util.DataDir points to a valid, existing, writable location.

Example fix

# before (Docker volume mounted read-only)
docker run -v /data/siyuan:/siyuan/workspace:ro ...

# after
docker run -v /data/siyuan:/siyuan/workspace:rw ...

# Fix permissions:
# chown -R <uid>:<gid> /path/to/data
# chmod 755 /path/to/data/.siyuan
Defensive patterns

Strategy: try-catch

Validate before calling

// Verify data directory is writable before calling SetPublishAccess
info, err := os.Stat(util.DataDir)
if err != nil || !info.IsDir() {
    return errors.New("data directory is not accessible")
}
if err := os.WriteFile(filepath.Join(util.DataDir, ".write_test"), []byte("test"), 0644); err != nil {
    return errors.New("data directory is not writable")
}
os.Remove(filepath.Join(util.DataDir, ".write_test"))

Try / catch

err := model.SetPublishAccess(input)
if err != nil && strings.Contains(err.Error(), "create dir for publishAccess.json") {
    // Filesystem permission or path issue — check data directory writability
    log.Printf("cannot create publishAccess directory; check permissions on %s", util.DataDir)
    return
}

Prevention

When it happens

Trigger: Calling SetPublishAccess() when the data directory or .siyuan subdirectory cannot be created due to permission denied, disk full, read-only filesystem, or path conflicts (e.g., a file exists where a directory is expected).

Common situations: The SiYuan data directory is on a read-only filesystem (e.g., a misconfigured Docker volume mounted read-only). The process lacks write permissions on the data directory (wrong UID/GID in a container). A file named '.siyuan' exists where a directory is expected. The disk is full. The data directory was moved or symlinked to a broken path.

Related errors


AI-assisted analysis of siyuan-note/siyuan@251596fc0d (2026-08-12). Data as JSON: /api/errors/84e5a0d5aa54b04d. Report an issue: GitHub.