Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions docs/source/changelog.rst
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ Enhancements

Fixes

- Raise ``IsADirectoryError`` when opening a GitHub directory.
- Keep the mode of an existing local file when a transaction commit replaces it,
instead of resetting it to the umask default

Expand Down
2 changes: 2 additions & 0 deletions fsspec/implementations/github.py
Original file line number Diff line number Diff line change
Expand Up @@ -245,6 +245,8 @@ def _open(
raise FileNotFoundError(path)
r.raise_for_status()
content_json = r.json()
if isinstance(content_json, list):
raise IsADirectoryError(path)

# Inline base64 content may be empty for a zero-byte file. Large files
# report encoding="none" and need the download fallback below.
Expand Down
11 changes: 11 additions & 0 deletions fsspec/implementations/tests/test_github_paths.py
Original file line number Diff line number Diff line change
Expand Up @@ -181,3 +181,14 @@ def test_open_download_fallback(
fs.http_fs.open.assert_called_once_with(
"https://example.com/download", mode="rb", block_size=32, cache_options=None
)


@pytest.mark.parametrize("contents", [[], [{"name": "child.txt", "type": "file"}]])
def test_open_directory(github_contents, monkeypatch, contents):
fs, _, _ = github_contents
response = Mock()
response.json.return_value = contents
monkeypatch.setattr(requests, "get", lambda *args, **kwargs: response)

with pytest.raises(IsADirectoryError, match="data"):
fs.open("data", "rb")
Loading