siyuan-note/siyuan · error
create import dir failed:
Error message
create import dir failed:
What it means
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: ".
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
Example fix
// before tempdir on read-only mount -> mkdir /temp/import: read-only file system // after mount --bind -o rw /srv/siyuan-temp /temp # or move the workspace to a writable volume
Defensive patterns
Strategy: validation
Validate before calling
if err := os.MkdirAll(filepath.Join(util.TempDir, "import"), 0o755); err != nil {
return fmt.Errorf("temp dir not writable: %w", err)
} Try / catch
if err != nil && strings.HasPrefix(err.Error(), "create import dir failed:") {
// check disk space and permissions before retrying
} Prevention
- 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
When it happens
Trigger: 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.
Common situations: 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.
Understand the failure class
Background: mkdir permission denied (EACCES): failed to create directory errors explained — this error's family across 32 libraries.
Related errors
- mkdir box conf dir failed
- mkdir master password migration dir failed
- create AI editor actions directory failed
- create conf dir failed
- create plugin dir [ ] failed
AI-assisted analysis of siyuan-note/siyuan@9f775e8a12 (2026-09-19).
Data as JSON: /api/errors/4000de52346a6849.
Report an issue: GitHub.
Appendix: source
Thrown at kernel/util/httprequest.go:363
maxReadBytes := int64(maxHTTPRequestBytes)
if !isTextContentType(contentType) {
maxReadBytes = maxHTTPRequestFileBytes
}
// ContentLength 为 -1(chunked)时跳过大小预检,交由 LimitReader 兜底截断。
if resp.ContentLength > maxReadBytes {
return statusCode, contentType, "", errors.New("response too large")
}
respBody, rerr := io.ReadAll(io.LimitReader(resp.Body, maxReadBytes))
if rerr != nil {
return statusCode, contentType, "", errors.New("read body failed: " + rerr.Error())
}
// 二进制响应落盘,返回文件路径,供智能体按需进一步处理。
if !isTextContentType(contentType) {
importDir := filepath.Join(TempDir, "import")
if merr := os.MkdirAll(importDir, 0755); merr != nil {
return statusCode, contentType, "", errors.New("create import dir failed: " + merr.Error())
}
filename := extractFilename(rawURL, contentType)
filePath := filepath.Join(importDir, filename)
if werr := os.WriteFile(filePath, respBody, 0644); werr != nil {
return statusCode, contentType, "", errors.New("write file failed: " + werr.Error())
}
return statusCode, contentType, fmt.Sprintf("Saved to: %s (%d bytes)", filePath, len(respBody)), nil
}
return statusCode, contentType, truncateRunes(string(respBody), maxHTTPRequestChars), nil
}
// isTextContentType 判断 Content-Type 是否为可直接展示给智能体的文本类响应。
// 覆盖 text/*、application/json、application/xml、application/*+json 等。
func isTextContentType(contentType string) bool {
ct := strings.ToLower(strings.TrimSpace(strings.SplitN(contentType, ";", 2)[0]))
if ct == "" {
return falseView on GitHub (pinned to 9f775e8a12)