{"record":{"id":"a8e13b48d211e35e","repo":"flipped-aurora/gin-vue-admin","slug":"s-w-a8e13b","errorCode":null,"errorMessage":"创建目标目录 %s 失败: %w","messagePattern":"创建目标目录 (.+?) 失败: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"server/service/system/auto_code_task.go","lineNumber":206,"sourceCode":"}\n\nfunc publishPreparedAutoCodeFile(file *autoCodeTaskFile) (bool, error) {\n\tcurrentHash, exists, err := hashAutoCodeTarget(file.TargetPath)\n\tif err != nil {\n\t\treturn false, err\n\t}\n\tif exists && currentHash == file.AfterHash {\n\t\tif removeErr := os.Remove(file.StagedPath); removeErr != nil && !errors.Is(removeErr, fs.ErrNotExist) {\n\t\t\treturn false, fmt.Errorf(\"清理重复 staging 文件失败: %w\", removeErr)\n\t\t}\n\t\tfile.StagedPath = \"\"\n\t\treturn false, nil\n\t}\n\tif exists != file.Existed || (file.Existed && currentHash != file.BeforeHash) {\n\t\treturn false, fmt.Errorf(\"%w: %s\", errAutoCodeFileConflict, file.TargetPath)\n\t}\n\tif err = os.MkdirAll(filepath.Dir(file.TargetPath), 0o755); err != nil {\n\t\treturn false, fmt.Errorf(\"创建目标目录 %s 失败: %w\", filepath.Dir(file.TargetPath), err)\n\t}\n\tif err = os.Rename(file.StagedPath, file.TargetPath); err != nil {\n\t\treturn false, fmt.Errorf(\"原子发布 %s 失败: %w\", file.TargetPath, err)\n\t}\n\tfile.StagedPath = \"\"\n\treturn true, nil\n}\n\nfunc (task *autoCodeFileTask) rollback(applied []int) error {\n\tfor i := len(applied) - 1; i >= 0; i-- {\n\t\tindex := applied[i]\n\t\tif index < 0 || index >= len(task.files) {\n\t\t\treturn fmt.Errorf(\"自动代码回滚索引无效: %d\", index)\n\t\t}\n\t\tfile := &task.files[index]\n\t\tcurrentHash, exists, err := hashAutoCodeTarget(file.TargetPath)\n\t\tif err != nil {\n\t\t\treturn err","sourceCodeStart":188,"sourceCodeEnd":224,"githubUrl":"https://github.com/flipped-aurora/gin-vue-admin/blob/3136500ef380842b0eb6c4daa87c3f8a47fcf9e0/server/service/system/auto_code_task.go#L188-L224","documentation":"Raised when creating the parent directory of a publish target with os.MkdirAll(dir, 0o755) fails. The task creates missing target directories just-in-time before the atomic rename so that new generated files nested in new packages/views can be placed; any MkdirAll error (other than the directory already existing, which MkdirAll tolerates) aborts the file publish.","triggerScenarios":"publishPreparedAutoCodeFile publishing a file whose target directory does not exist yet, and MkdirAll fails because a parent path component is not a directory, permissions deny creation, the filesystem is read-only/full, or the target path is invalid on the OS.","commonSituations":"Server runs without write permission on server/ or web/ trees (e.g. containerized deployment with read-only code volume); a file exists where a directory is needed; ENOSPC on disk; SELinux/AppArmor blocking writes in the project root.","solutions":["Check that the parent path of the reported directory is writable by the server process (permissions, ownership)","Ensure no regular file exists at a path component that must be a directory (remove/rename it)","If deployed in a container, mount the server/ and web/ trees read-write","Check disk space (df -h) and mandatory access control logs (SELinux/AppArmor) if errors persist"],"exampleFix":"// before: read-only code mount in container\nvolumes:\n  - ./web:/app/web:ro\n\n// after: make writable\nvolumes:\n  - ./web:/app/web:rw","handlingStrategy":"validation","validationCode":"func ensureTargetDirsWritable(targets []string) error {\n\tseen := map[string]bool{}\n\tfor _, t := range targets {\n\t\tdir := filepath.Dir(t)\n\t\tif seen[dir] {\n\t\t\tcontinue\n\t\t}\n\t\tseen[dir] = true\n\t\tif info, err := os.Stat(dir); err == nil && !info.IsDir() {\n\t\t\treturn fmt.Errorf(\"%s is a file, not a directory\", dir)\n\t\t}\n\t\t// walk up to the first existing ancestor and test writability\n\t\tfor d := dir; ; d = filepath.Dir(d) {\n\t\t\tif _, err := os.Stat(d); err == nil {\n\t\t\t\tif probe, perr := os.CreateTemp(d, \".w\"); perr != nil {\n\t\t\t\t\treturn fmt.Errorf(\"%s not writable: %w\", d, perr)\n\t\t\t\t} else {\n\t\t\t\t\tprobe.Close()\n\t\t\t\t\tos.Remove(probe.Name())\n\t\t\t\t}\n\t\t\t\tbreak\n\t\t\t}\n\t\t}\n\t}\n\treturn nil\n}","typeGuard":null,"tryCatchPattern":"if err := commitAutoCodeFileTask(task, publishPreparedAutoCodeFile, persist); err != nil {\n\tvar mkErr *fmt.WrapError // match on message prefix instead\n\tif strings.Contains(err.Error(), \"创建目标目录\") {\n\t\tlog.Printf(\"cannot create target dir (check perms/disk/mounts): %v\", err)\n\t}\n}","preventionTips":["Verify server/ and web/ trees are read-write for the service account before enabling auto-code generation","In containers, mount code volumes :rw","Keep enough free disk space and check df before large generation runs","Audit SELinux/AppArmor denials if mkdir fails with permission denied despite correct ownership"],"tags":["filesystem","mkdir","permissions","autocode","file-publish"],"backgroundTag":"mkdir-failed","analyzedSha":"3136500ef380842b0eb6c4daa87c3f8a47fcf9e0","analyzedAt":"2026-08-31T13:50:02.721Z","schemaVersion":2},"datasetVersion":"2026-08-31T19:17:28.585Z"}