{"record":{"id":"5332e7999b6eaf9b","repo":"siyuan-note/siyuan","slug":"create-import-dir-failed-s-5332e7","errorCode":null,"errorMessage":"create import dir failed: %s","messagePattern":"create import dir failed: (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"kernel/util/webfetch.go","lineNumber":80,"sourceCode":"\n\tcontentType := resp.Header.Get(\"Content-Type\")\n\tmaxReadBytes := int64(maxWebFetchBytes)\n\tif !strings.HasPrefix(contentType, \"text/html\") && !strings.HasPrefix(contentType, \"text/plain\") {\n\t\tmaxReadBytes = maxWebFetchFileBytes\n\t}\n\tif resp.ContentLength > maxReadBytes {\n\t\treturn \"\", errors.New(\"response too large\")\n\t}\n\n\tbody, err := io.ReadAll(io.LimitReader(resp.Body, maxReadBytes))\n\tif err != nil {\n\t\treturn \"\", errors.New(\"read body failed: \" + err.Error())\n\t}\n\n\tif !strings.HasPrefix(contentType, \"text/html\") && !strings.HasPrefix(contentType, \"text/plain\") {\n\t\timportDir := filepath.Join(TempDir, \"import\")\n\t\tif merr := os.MkdirAll(importDir, 0755); merr != nil {\n\t\t\treturn \"\", 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, body, 0644); werr != nil {\n\t\t\treturn \"\", errors.New(\"write file failed: \" + werr.Error())\n\t\t}\n\t\treturn fmt.Sprintf(\"Saved to: %s (%d bytes)\", filePath, len(body)), nil\n\t}\n\n\thtmlStr := string(body)\n\n\tisHTML := strings.HasPrefix(contentType, \"text/html\")\n\tif !isHTML {\n\t\treturn truncateRunes(htmlStr, maxWebFetchChars), nil\n\t}\n\n\tif htmlStr == \"\" {\n\t\treturn \"\", nil","sourceCodeStart":62,"sourceCodeEnd":98,"githubUrl":"https://github.com/siyuan-note/siyuan/blob/9f775e8a12daef8255556097396f9b2739078892/kernel/util/webfetch.go#L62-L98","documentation":"For non-HTML/text content types, WebFetch saves the body as a file under <TempDir>/import. Before writing it calls os.MkdirAll(importDir, 0755); failure (permission denied on the temp dir, path occupied by a regular file, read-only filesystem) is wrapped as 'create import dir failed: <cause>'.","triggerScenarios":"os.MkdirAll cannot create the import directory because a file named 'import' already exists in TempDir, the temp directory's permissions changed, or the disk/filesystem is read-only.","commonSituations":"Running the kernel as a different user after TempDir was created by another account; containerized deployments with read-only tmpfs; a stale file colliding with the 'import' directory name; disk-full or quota conditions surfacing as mkdir errors.","solutions":["Inspect the wrapped cause after 'create import dir failed: ' to distinguish EEXIST-as-file vs EACCES vs EROFS","Check that TempDir exists, is writable by the kernel user, and contains no regular file named 'import'","Fix permissions: chown/chmod the temp directory for the process user","If running in a container, mount a writable volume at the temp path"],"exampleFix":"// before\n// file named 'import' blocks directory creation\n$ rm $TMPDIR/import   # remove the colliding regular file\n\n// after\n$ mkdir -p $TMPDIR/import && chmod u+rwx $TMPDIR/import","handlingStrategy":"try-catch","validationCode":"importDir := filepath.Join(TempDir, \"import\")\nif fi, err := os.Stat(importDir); err == nil && !fi.IsDir() {\n    return errors.New(\"temp 'import' path is occupied by a regular file\")\n}","typeGuard":null,"tryCatchPattern":"_, err := WebFetch(url, format)\nif err != nil && strings.Contains(err.Error(), \"create import dir failed\") {\n    // inspect wrapped errno: EACCES -> fix perms, EROFS -> mount writable tmp, EEXIST-as-file -> remove collision\n}","preventionTips":["Ensure the kernel's temp directory is writable by the running user","Never place a file named 'import' directly under TempDir","In containers, mount a writable volume at the temp path","Watch disk health — read-only remounts surface as mkdir failures"],"tags":["filesystem","permissions","directory"],"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"}