Skip to content

Commit a0ce6db

Browse files
Normalize paths in AsyncFileSystemWrapper like the wrapped filesystem (#2159)
Co-authored-by: Martin Durant <[email protected]>
1 parent c5fea6d commit a0ce6db

2 files changed

Lines changed: 17 additions & 0 deletions

File tree

‎fsspec/implementations/asyn_wrapper.py‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,10 @@ def __init__(
7171
else:
7272
self.sync_fs = fsspec.filesystem(target_protocol, **target_options)
7373
self.protocol = self.sync_fs.protocol
74+
# paths must be normalized the way the wrapped filesystem does it
75+
self.root_marker = self.sync_fs.root_marker
76+
self._strip_protocol = self.sync_fs._strip_protocol
77+
self._parent = self.sync_fs._parent
7478
self.semaphore = semaphore
7579
self._wrap_all_sync_methods()
7680

‎fsspec/implementations/tests/test_asyn_wrapper.py‎

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -247,6 +247,19 @@ def test_get_does_not_write_above_destination(tmp_path):
247247
assert not outside.exists(), f"async copy wrote {outside}, above {dest}"
248248

249249

250+
def test_paths_normalized_like_wrapped_fs():
251+
fs = fsspec.filesystem("memory")
252+
fs.pipe({"/norm/a": b"a", "/norm/sub/b": b"b"})
253+
async_fs = AsyncFileSystemWrapper(fs, asynchronous=False)
254+
255+
assert async_fs._strip_protocol("memory://norm/a") == "/norm/a"
256+
assert async_fs._parent("memory://norm/a") == "/norm"
257+
258+
dirfs = fsspec.filesystem("dir", path="memory://norm", fs=async_fs)
259+
assert dirfs.ls("", detail=False) == ["a", "sub"]
260+
assert dirfs.find("") == ["a", "sub/b"]
261+
262+
250263
@pytest.mark.asyncio
251264
async def test_walk():
252265
fs = fsspec.filesystem("memory")

0 commit comments

Comments
 (0)