{"record":{"id":"84e5a0d5aa54b04d","repo":"siyuan-note/siyuan","slug":"create-dir-for-publishaccess-json-s-failed-s","errorCode":null,"errorMessage":"create dir for publishAccess.json [%s] failed: %s","messagePattern":"create dir for publishAccess\\.json \\[(.+?)\\] failed: (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"kernel/model/publish_access.go","lineNumber":126,"sourceCode":"\t\treturn\n\t}\n\tret = publishAccess\n\treturn\n}\n\nfunc SetPublishAccess(inputPublishAccess PublishAccess) (err error) {\n\tnow := time.Now().UnixMilli()\n\tpublishAccessLock.Lock()\n\tdefer publishAccessLock.Unlock()\n\tpublishAccessLastModified = now\n\tpublishAccess = inputPublishAccess\n\n\tpublishAccessPath := filepath.Join(util.DataDir, \".siyuan\", \"publishAccess.json\")\n\terr = os.MkdirAll(filepath.Dir(publishAccessPath), 0755)\n\tif err != nil {\n\t\tmsg := fmt.Sprintf(\"create dir for publishAccess.json [%s] failed: %s\", publishAccessPath, err)\n\t\tlogging.LogError(msg)\n\t\terr = errors.New(msg)\n\t\treturn\n\t}\n\n\tdata, err := gulu.JSON.MarshalJSON(inputPublishAccess)\n\tif err != nil {\n\t\tlogging.LogErrorf(\"marshal publishAccess.json [%s] failed: %s\", publishAccessPath, err)\n\t\treturn\n\t}\n\n\terr = filelock.WriteFile(publishAccessPath, data)\n\tif err != nil {\n\t\tmsg := fmt.Sprintf(\"write publishAccess.json [%s] failed: %s\", publishAccessPath, err)\n\t\tlogging.LogError(msg)\n\t\terr = errors.New(msg)\n\t\treturn\n\t}\n\treturn\n}","sourceCodeStart":108,"sourceCodeEnd":144,"githubUrl":"https://github.com/siyuan-note/siyuan/blob/251596fc0de2f9528c00c224252fd073a99973f4/kernel/model/publish_access.go#L108-L144","documentation":"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.","triggerScenarios":"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).","commonSituations":"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.","solutions":["Check filesystem permissions: ensure the SiYuan process user has write access to util.DataDir and its parent.","If running in Docker, verify the volume mount is read-write (rw, not ro).","Remove any file blocking the .siyuan directory creation.","Check available disk space with df -h.","Verify util.DataDir points to a valid, existing, writable location."],"exampleFix":"# before (Docker volume mounted read-only)\ndocker run -v /data/siyuan:/siyuan/workspace:ro ...\n\n# after\ndocker run -v /data/siyuan:/siyuan/workspace:rw ...\n\n# Fix permissions:\n# chown -R <uid>:<gid> /path/to/data\n# chmod 755 /path/to/data/.siyuan","handlingStrategy":"try-catch","validationCode":"// Verify data directory is writable before calling SetPublishAccess\ninfo, err := os.Stat(util.DataDir)\nif err != nil || !info.IsDir() {\n    return errors.New(\"data directory is not accessible\")\n}\nif err := os.WriteFile(filepath.Join(util.DataDir, \".write_test\"), []byte(\"test\"), 0644); err != nil {\n    return errors.New(\"data directory is not writable\")\n}\nos.Remove(filepath.Join(util.DataDir, \".write_test\"))","typeGuard":null,"tryCatchPattern":"err := model.SetPublishAccess(input)\nif err != nil && strings.Contains(err.Error(), \"create dir for publishAccess.json\") {\n    // Filesystem permission or path issue — check data directory writability\n    log.Printf(\"cannot create publishAccess directory; check permissions on %s\", util.DataDir)\n    return\n}","preventionTips":["Ensure the SiYuan process has write permissions on the data directory.","Verify Docker volume mounts are read-write.","Monitor disk health and filesystem errors in system logs."],"tags":["filesystem","publish","permissions","io","config"],"backgroundTag":null,"analyzedSha":"251596fc0de2f9528c00c224252fd073a99973f4","analyzedAt":"2026-08-12T21:18:37.123Z","schemaVersion":2},"datasetVersion":"2026-08-12T23:17:12.415Z"}