{"record":{"id":"344f26dba31cdf7d","repo":"siyuan-note/siyuan","slug":"create-history-directory-s-failed-w","errorCode":null,"errorMessage":"create history directory [%s] failed: %w","messagePattern":"create history directory \\[(.+?)\\] failed: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"kernel/model/history.go","lineNumber":949,"sourceCode":"\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}\n\t}\n\n\tindexHistoryDir(filepath.Base(historyDir), util.NewLute())\n\treturn\n}\n\nfunc (box *Box) generateDocHistory0() {\n\tfiles := box.recentModifiedDocs()\n\tif 1 > len(files) {\n\t\treturn","sourceCodeStart":931,"sourceCodeEnd":967,"githubUrl":"https://github.com/siyuan-note/siyuan/blob/9f775e8a12daef8255556097396f9b2739078892/kernel/model/history.go#L931-L967","documentation":"Before copying each asset into the history snapshot, createAssetsHistory creates the destination directory history/<stamp>/assets/<rel-dir>. If os.MkdirAll fails, the error is wrapped with the target directory path and returned, aborting the snapshot.","triggerScenarios":"MkdirAll failing on the history assets dir: read-only volume, full disk, name collision with an existing file, or path-length limits (long asset names on Windows).","commonSituations":"History directory made read-only by backup tooling; assets with deep nesting hitting MAX_PATH on Windows; a regular file existing where the directory should be created.","solutions":["Read the wrapped cause and the [%s] directory in the message to locate the failure.","Remove any file colliding with the intended history directory path.","Fix volume writability or shorten paths, then re-run the snapshot."],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":"// ensure no file collides with the target history dir\nif (fs.existsSync(targetDir) && !fs.statSync(targetDir).isDirectory()) {\n  throw new Error(\"file blocks history dir: \" + targetDir);\n}","typeGuard":null,"tryCatchPattern":"try {\n  await createAssetHistory(p);\n} catch (e) {\n  if (String(e).includes(\"create history directory\")) {\n    // parse [%s] dir, clear collision / fix permissions, retry\n  }\n}","preventionTips":["Keep history dir free of stray files.","Avoid deep asset nesting to stay under Windows MAX_PATH.","Watch disk space and volume health."],"tags":["filesystem","io","mkdir","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"}