go
io_error
ai_generated
true
error: remove /tmp/dir: directory not empty
ID: go/os-dir-not-empty
80%Fix Rate
87%Confidence
0Evidence
2024-04-09First Seen
Version Compatibility
| Version | Status | Introduced | Deprecated | Notes |
|---|---|---|---|---|
| 1.19 | active | — | — | — |
Root Cause
尝试使用 os.Remove 删除非空目录,但该函数只支持删除空目录。
generic中文
os.Remove 不能递归删除,目录中仍有文件或子目录时失败。
Workarounds
-
95% success
使用 os.RemoveAll 并检查返回值
-
90% success
遍历目录并递归删除所有内容
Dead Ends
Common approaches that don't work:
-
60% fail
RemoveAll 可能部分删除,忽略错误导致状态不一致
-
80% fail
子目录递归未处理