{"record":{"id":"745ec3feafecc433","repo":"siyuan-note/siyuan","slug":"get-history-directory-failed-w","errorCode":null,"errorMessage":"get history directory failed: %w","messagePattern":"get history directory failed: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"kernel/model/history.go","lineNumber":939,"sourceCode":"\tassetAbsPath := filepath.Join(util.DataDir, filepath.FromSlash(assetPath))\n\tassetsDir := filepath.Join(util.DataDir, \"assets\")\n\tif !gulu.File.IsSubPath(assetsDir, assetAbsPath) {\n\t\treturn errors.New(\"asset path must be under assets\")\n\t}\n\tinfo, statErr := os.Stat(assetAbsPath)\n\tif statErr != nil {\n\t\treturn statErr\n\t}\n\tif info.IsDir() {\n\t\treturn errors.New(\"asset path must be a file\")\n\t}\n\treturn createAssetsHistory([]string{assetAbsPath})\n}\n\nfunc createAssetsHistory(assets []string) (err error) {\n\thistoryDir, err := getHistoryDir(HistoryOpUpdate)\n\tif err != nil {\n\t\treturn fmt.Errorf(\"get history directory failed: %w\", err)\n\t}\n\n\tfor _, file := range assets {\n\t\tassetRelPath, relErr := filepath.Rel(filepath.Join(util.DataDir, \"assets\"), file)\n\t\tif relErr != nil || assetRelPath == \".\" || strings.HasPrefix(assetRelPath, \"..\"+string(filepath.Separator)) {\n\t\t\treturn errors.New(\"asset path must be under assets\")\n\t\t}\n\t\thistoryPath := filepath.Join(historyDir, \"assets\", assetRelPath)\n\t\tif err = os.MkdirAll(filepath.Dir(historyPath), 0755); err != nil {\n\t\t\treturn fmt.Errorf(\"create history directory [%s] failed: %w\", filepath.Dir(historyPath), err)\n\t\t}\n\n\t\tif copyErr := filelock.Copy(file, historyPath); copyErr != nil {\n\t\t\tif os.IsNotExist(copyErr) {\n\t\t\t\tcontinue\n\t\t\t}\n\t\t\treturn fmt.Errorf(\"copy asset [%s] to [%s] failed: %w\", file, historyPath, copyErr)\n\t\t}","sourceCodeStart":921,"sourceCodeEnd":957,"githubUrl":"https://github.com/siyuan-note/siyuan/blob/9f775e8a12daef8255556097396f9b2739078892/kernel/model/history.go#L921-L957","documentation":"createAssetsHistory begins by obtaining the timestamped history directory via getHistoryDir(HistoryOpUpdate). If that internal step fails (I/O or permission problems creating dirs under history/), the error is wrapped with this prefix and returned, preserving the cause via %w.","triggerScenarios":"Any createAssetsHistory call (directly or through CreateAssetHistory / generateAssetsHistory) when the history directory cannot be created: read-only data dir, full disk, permission problems, or history dir occupied by a file.","commonSituations":"Workspace on a read-only or quota-exceeded volume; restrictive umask/permissions after restoring data with wrong ownership; antivirus locking the history directory.","solutions":["Check the wrapped cause (%w) to identify the underlying fs error.","Ensure <workspace>/history/ is writable by the kernel process.","Free disk space / fix volume permissions, then retry."],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":"// pre-check writability\nfs.accessSync(path.join(workspace, \"history\"), fs.constants.W_OK);","typeGuard":null,"tryCatchPattern":"try {\n  await createAssetHistory(p);\n} catch (e) {\n  if (String(e).includes(\"get history directory failed\")) {\n    // inspect wrapped cause, fix volume/permission, retry\n  }\n}","preventionTips":["Keep <workspace>/history writable and on a healthy volume.","Monitor disk space on the workspace volume.","Avoid running backup tools that lock or chmod the history dir."],"tags":["filesystem","io","history"],"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"}