Skip to content

fix(local): add IsDir checks to Read/Write/Edit to prevent directory-as-file errors - #932

Open
luchun19921229 wants to merge 1 commit into
cloudwego:mainfrom
luchun19921229:fix/add-isDir-checks
Open

fix(local): add IsDir checks to Read/Write/Edit to prevent directory-as-file errors#932
luchun19921229 wants to merge 1 commit into
cloudwego:mainfrom
luchun19921229:fix/add-isDir-checks

Conversation

@luchun19921229

Copy link
Copy Markdown

Problem

When a user passes a directory path to Local.Read(), Local.Write(), or Local.Edit(), the methods attempt to use the path as a file — opening, reading, or writing it — which produces confusing low-level errors (e.g. is a directory from the OS) or silent failures instead of a clear explanation.

Changes

Added a guard check in each of the three methods that returns a clear error message when the target path is a directory rather than a file:

Read()

  • Calls file.Stat() before info.Size() == 0 check
  • Returns "path is a directory, not a file: <path>"

Write()

  • Calls os.Stat(path) before MkdirAll/OpenFile
  • Returns "path is a directory, not a file: <path>"

Edit()

  • Calls os.Stat(path) before os.ReadFile(path)
  • Returns "path is a directory, not a file: <path>"

Testing

  • Run existing test suite to confirm no regressions
  • Verify each method returns the directory error when given a directory path

…a loss

Three methods accepted directory paths without returning an error:

- Read(): file.Stat() checked Size()==0 but not IsDir(), returning empty
  FileContent{} for directories (silent data loss).
- Write(): os.OpenFile(dir, O_WRONLY|O_CREATE|O_TRUNC) returns EISDIR on
  Unix with a confusing error message. Added explicit Stat+IsDir check.
- Edit(): os.ReadFile(dir) returns empty content, then strings.Count()
  reports "string not found" — misleading error. Added explicit Stat+IsDir
  check before ReadFile.

readAllBytes() already has the info.IsDir() guard, so MultiModalRead is
already protected. This aligns Read/Write/Edit with that pattern.
@CLAassistant

CLAassistant commented Jul 23, 2026

Copy link
Copy Markdown

CLA assistant check
All committers have signed the CLA.

@luchun19921229

Copy link
Copy Markdown
Author

@cloudwego/eino-maintainers 请 review 这个 PR。CI 全绿,改动很简单:在 adk/backend/local/local.goRead/Write/Edit 三个方法里加了 IsDir() 守卫,防止目录被误当成文件操作,给出清晰错误信息。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

2 participants