{"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/9f775e8a12daef8255556097396f9b2739078892/kernel/model/publish_access.go#L108-L144","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["Check the kernel log for the full path and OS error, then fix the underlying filesystem problem (permissions, ownership, disk full)","Verify <DataDir>/.siyuan is a directory, not a file; remove/rename the stray file","Ensure the process user can write to the workspace directory (chown/chmod)","Re-run the publish access update after fixing so the change is persisted"],"exampleFix":"# before\nls -la <workspace>/.siyuan   # -> file or root-owned dir\n# after\nrm <workspace>/.siyuan        # if it is a stray file\nchown -R siyuan:siyuan <workspace>/.siyuan","handlingStrategy":"try-catch","validationCode":"const dir = path.join(dataDir, \".siyuan\");\nif (!fs.existsSync(dir)) fs.mkdirSync(dir, {recursive: true});\nif (!fs.statSync(dir).isDirectory()) throw new Error(dir + \" must be a directory\");\nfs.accessSync(dir, fs.constants.W_OK);","typeGuard":null,"tryCatchPattern":"err := model.SetPublishAccess(access)\nif err != nil {\n    if strings.Contains(err.Error(), \"create dir for publishAccess.json\") {\n        // fix filesystem permissions/mount, then retry\n    }\n    return err\n}","preventionTips":["Ensure the workspace volume is writable and not mounted read-only","Never create a file named .siyuan in the workspace root","Run the kernel under a user with write access to the data directory","Monitor disk space on the workspace volume"],"tags":["filesystem","mkdir","publish","persistence"],"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"}