Skip to content

Commit 2dd9355

Browse files
authored
Fix missing folders http glob (#1516)
1 parent 518984d commit 2dd9355

File tree

3 files changed

+32
-10
lines changed

3 files changed

+32
-10
lines changed

fsspec/implementations/http.py

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -451,7 +451,7 @@ async def _glob(self, path, maxdepth=None, **kwargs):
451451

452452
ends_with_slash = path.endswith("/") # _strip_protocol strips trailing slash
453453
path = self._strip_protocol(path)
454-
append_slash_to_dirname = ends_with_slash or path.endswith("/**")
454+
append_slash_to_dirname = ends_with_slash or path.endswith(("/**", "/*"))
455455
idx_star = path.find("*") if path.find("*") >= 0 else len(path)
456456
idx_brace = path.find("[") if path.find("[") >= 0 else len(path)
457457

@@ -494,15 +494,15 @@ async def _glob(self, path, maxdepth=None, **kwargs):
494494
pattern = re.compile(pattern)
495495

496496
out = {
497-
p: info
497+
(
498+
p.rstrip("/")
499+
if not append_slash_to_dirname
500+
and info["type"] == "directory"
501+
and p.endswith("/")
502+
else p
503+
): info
498504
for p, info in sorted(allpaths.items())
499-
if pattern.match(
500-
(
501-
p + "/"
502-
if append_slash_to_dirname and info["type"] == "directory"
503-
else p
504-
)
505-
)
505+
if pattern.match(p.rstrip("/"))
506506
}
507507

508508
if detail:

fsspec/implementations/tests/test_http.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,15 @@ def test_list_cache_with_skip_instance_cache(server):
129129
assert out == [server + "/index/realfile"]
130130

131131

132+
def test_glob_return_subfolders(server):
133+
h = fsspec.filesystem("http")
134+
out = h.glob(server + "/simple/*")
135+
assert set(out) == {
136+
server + "/simple/dir/",
137+
server + "/simple/file",
138+
}
139+
140+
132141
def test_isdir(server):
133142
h = fsspec.filesystem("http")
134143
assert h.isdir(server + "/index/")

fsspec/tests/conftest.py

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,13 @@
1919
win = os.name == "nt"
2020

2121

22+
def _make_listing(*paths):
23+
return "\n".join(
24+
f'<a href="http://127.0.0.1:{port}{f}">Link_{i}</a>'
25+
for i, f in enumerate(paths)
26+
).encode()
27+
28+
2229
@pytest.fixture
2330
def reset_files():
2431
yield
@@ -34,6 +41,10 @@ class HTTPTestHandler(BaseHTTPRequestHandler):
3441
"/index/otherfile": data,
3542
"/index": index,
3643
"/data/20020401": listing,
44+
"/simple/": _make_listing("/simple/file", "/simple/dir/"),
45+
"/simple/file": data,
46+
"/simple/dir/": _make_listing("/simple/dir/file"),
47+
"/simple/dir/file": data,
3748
}
3849
dynamic_files = {}
3950

@@ -53,7 +64,9 @@ def _respond(self, code=200, headers=None, data=b""):
5364
self.wfile.write(data)
5465

5566
def do_GET(self):
56-
file_path = self.path.rstrip("/")
67+
file_path = self.path
68+
if file_path.endswith("/") and file_path.rstrip("/") in self.files:
69+
file_path = file_path.rstrip("/")
5770
file_data = self.files.get(file_path)
5871
if "give_path" in self.headers:
5972
return self._respond(200, data=json.dumps({"path": self.path}).encode())

0 commit comments

Comments
 (0)