{"record":{"id":"4000de52346a6849","repo":"siyuan-note/siyuan","slug":"create-import-dir-failed","errorCode":null,"errorMessage":"create import dir failed: ","messagePattern":"create import dir failed: ","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"kernel/util/httprequest.go","lineNumber":363,"sourceCode":"\tmaxReadBytes := int64(maxHTTPRequestBytes)\n\tif !isTextContentType(contentType) {\n\t\tmaxReadBytes = maxHTTPRequestFileBytes\n\t}\n\t// ContentLength 为 -1（chunked）时跳过大小预检，交由 LimitReader 兜底截断。\n\tif resp.ContentLength > maxReadBytes {\n\t\treturn statusCode, contentType, \"\", errors.New(\"response too large\")\n\t}\n\n\trespBody, rerr := io.ReadAll(io.LimitReader(resp.Body, maxReadBytes))\n\tif rerr != nil {\n\t\treturn statusCode, contentType, \"\", errors.New(\"read body failed: \" + rerr.Error())\n\t}\n\n\t// 二进制响应落盘，返回文件路径，供智能体按需进一步处理。\n\tif !isTextContentType(contentType) {\n\t\timportDir := filepath.Join(TempDir, \"import\")\n\t\tif merr := os.MkdirAll(importDir, 0755); merr != nil {\n\t\t\treturn statusCode, contentType, \"\", errors.New(\"create import dir failed: \" + merr.Error())\n\t\t}\n\t\tfilename := extractFilename(rawURL, contentType)\n\t\tfilePath := filepath.Join(importDir, filename)\n\t\tif werr := os.WriteFile(filePath, respBody, 0644); werr != nil {\n\t\t\treturn statusCode, contentType, \"\", errors.New(\"write file failed: \" + werr.Error())\n\t\t}\n\t\treturn statusCode, contentType, fmt.Sprintf(\"Saved to: %s (%d bytes)\", filePath, len(respBody)), nil\n\t}\n\n\treturn statusCode, contentType, truncateRunes(string(respBody), maxHTTPRequestChars), nil\n}\n\n// isTextContentType 判断 Content-Type 是否为可直接展示给智能体的文本类响应。\n// 覆盖 text/*、application/json、application/xml、application/*+json 等。\nfunc isTextContentType(contentType string) bool {\n\tct := strings.ToLower(strings.TrimSpace(strings.SplitN(contentType, \";\", 2)[0]))\n\tif ct == \"\" {\n\t\treturn false","sourceCodeStart":345,"sourceCodeEnd":381,"githubUrl":"https://github.com/siyuan-note/siyuan/blob/9f775e8a12daef8255556097396f9b2739078892/kernel/util/httprequest.go#L345-L381","documentation":"For non-text content types, HTTPRequest persists the downloaded bytes to <TempDir>/import/ so the agent can process the file later. This error is returned when os.MkdirAll fails to create that import directory, with the OS error (permission denied, disk full, path is a file, etc.) appended after \"create import dir failed: \".","triggerScenarios":"Calling HTTPRequest with a binary (non-text) response when: the workspace TempDir is on a read-only volume, the parent path exists as a regular file, the process lacks write permission, or the disk is full/out of inodes.","commonSituations":"Running SiYuan from a read-only install or container filesystem; TempDir placed on a mounted/USB volume that is not writable; a stale file named 'import' blocking directory creation; SELinux/AppArmor policies denying writes; disk quota exhaustion.","solutions":["Read the appended OS error (mkdir ...: permission denied / no space left) to identify the concrete cause","Fix permissions on the temp directory so the kernel process can write (chmod/chown)","Free disk space or raise the quota if the volume is full","Remove/rename any regular file occupying the <TempDir>/import path","Relocate the workspace (and thus TempDir) to a writable volume, or adjust container volume mounts to be read-write"],"exampleFix":"// before\ntempdir on read-only mount -> mkdir /temp/import: read-only file system\n// after\nmount --bind -o rw /srv/siyuan-temp /temp   # or move the workspace to a writable volume","handlingStrategy":"validation","validationCode":"if err := os.MkdirAll(filepath.Join(util.TempDir, \"import\"), 0o755); err != nil {\n    return fmt.Errorf(\"temp dir not writable: %w\", err)\n}","typeGuard":null,"tryCatchPattern":"if err != nil && strings.HasPrefix(err.Error(), \"create import dir failed:\") {\n    // check disk space and permissions before retrying\n}","preventionTips":["Ensure TempDir is on a writable volume with free space","Never shadow <TempDir>/import with a regular file","In containers, mount temp paths read-write"],"tags":["filesystem","permissions","go","mkdir"],"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"}