Skip to content

fix: skip files that conflict with existing directories in FileStore.push#1356

Open
octo-patch wants to merge 1 commit intoAntonOsika:mainfrom
octo-patch:fix/issue-1199-is-a-directory-error
Open

fix: skip files that conflict with existing directories in FileStore.push#1356
octo-patch wants to merge 1 commit intoAntonOsika:mainfrom
octo-patch:fix/issue-1199-is-a-directory-error

Conversation

@octo-patch
Copy link
Copy Markdown

Fixes #1199

Problem

When the LLM generates a files dict that contains both a bare name (e.g. 'api_project') and files under a directory with the same name (e.g. 'api_project/settings.py'), the FileStore.push() method crashes with IsADirectoryError.

Root cause: when writing api_project/settings.py, path.parent.mkdir() creates the api_project/ directory. Later, when writing the file named api_project, open(path, 'w') fails because the path is now a directory.

Solution

Add a path.is_dir() check before opening the file. If the resolved path is already a directory, log a warning and skip that entry instead of raising an unhandled exception. This keeps the rest of the generated files intact and surfaces a clear diagnostic message.

Testing

The fix can be reproduced with:

from gpt_engineer.core.default.file_store import FileStore
from gpt_engineer.core.files_dict import FilesDict

store = FileStore()
# 'api_project' is both a "file" key and a directory prefix — this used to crash
files = FilesDict({
    "api_project/settings.py": "DEBUG = True",
    "api_project": "some content",
})
store.push(files)  # now skips 'api_project' with a warning instead of raising

…push (fixes AntonOsika#1199)

When the LLM generates both a file named 'foo' and files under a 'foo/'
directory, the push() method would fail with IsADirectoryError because
mkdir() creates 'foo/' as a directory first, then open('foo', 'w') fails.

Add a path.is_dir() check to skip such conflicting entries with a warning
instead of crashing.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

IsADirectoryError: [Errno 21] Is a directory

1 participant