{"record":{"id":"5f72fb3cfc1119dc","repo":"siyuan-note/siyuan","slug":"write-publishaccess-json-s-failed-s","errorCode":null,"errorMessage":"write publishAccess.json [%s] failed: %s","messagePattern":"write publishAccess\\.json \\[(.+?)\\] failed: (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"kernel/model/publish_access.go","lineNumber":140,"sourceCode":"\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}\n\nfunc GetInvisiblePublishAccess(inputPublishAccess PublishAccess) (outputPublishAccess PublishAccess) {\n\toutputPublishAccess = filterInvisiblePublishAccess(inputPublishAccess)\n\toutputPublishAccess = appendEncryptedBoxesToPublishAccess(outputPublishAccess)\n\treturn\n}\n\nfunc filterInvisiblePublishAccess(inputPublishAccess PublishAccess) (outputPublishAccess PublishAccess) {\n\toutputPublishAccess = PublishAccess{}\n\tfor _, item := range inputPublishAccess {\n\t\tif !item.Visible {\n\t\t\toutputPublishAccess = append(outputPublishAccess, item)\n\t\t}\n\t}","sourceCodeStart":122,"sourceCodeEnd":158,"githubUrl":"https://github.com/siyuan-note/siyuan/blob/9f775e8a12daef8255556097396f9b2739078892/kernel/model/publish_access.go#L122-L158","documentation":"SetPublishAccess fails with this message when filelock.WriteFile cannot persist publishAccess.json after the directory was created and the JSON marshaled. The in-memory state remains updated, but the on-disk copy stays stale, so publish access settings silently revert after a restart. The message includes the file path and the underlying error.","triggerScenarios":"SetPublishAccess when the .siyuan/publishAccess.json write fails: read-only filesystem, permission denied on the existing file, another process/lock holder, antivirus locking the file, or disk full.","commonSituations":"File owned by a different user after running the kernel as root once; sync/backup tools (or two kernel instances) holding the file lock; Windows Defender or OneDrive temporarily locking the JSON; read-only Docker volume.","solutions":["Read the path and OS error from the kernel log, then fix permissions on <workspace>/.siyuan/publishAccess.json (chown/chmod) or free disk space","Stop other SiYuan instances or sync tools that may hold the filelock, then retry","If the file is corrupt/locked persistently, stop the kernel, remove it (settings are re-savable), and re-apply publish access","Re-run the update after fixing so the in-memory change is persisted to disk"],"exampleFix":"# before\nls -l <workspace>/.siyuan/publishAccess.json  # root-owned, 0644\n# after\nchown siyuan:siyuan <workspace>/.siyuan/publishAccess.json && chmod 600 <workspace>/.siyuan/publishAccess.json","handlingStrategy":"try-catch","validationCode":"const f = path.join(dataDir, \".siyuan\", \"publishAccess.json\");\ntry { fs.accessSync(path.dirname(f), fs.constants.W_OK); } catch { throw new Error(\".siyuan not writable\"); }\nif (fs.existsSync(f)) fs.accessSync(f, fs.constants.W_OK);","typeGuard":null,"tryCatchPattern":"err := model.SetPublishAccess(access)\nif err != nil {\n    if strings.Contains(err.Error(), \"write publishAccess.json\") {\n        // release file locks / fix permissions, then retry once\n    }\n    return err\n}","preventionTips":["Run only one kernel instance per workspace to avoid filelock contention","Exclude the workspace from sync/backup tools that lock JSON files (OneDrive, Dropbox)","Keep publishAccess.json writable by the kernel process user","Re-apply publish access settings after any filesystem repair"],"tags":["filesystem","file-write","publish","persistence"],"backgroundTag":"file-write-failed","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"}