Skip to content

Commit df042b1

Browse files
authored
FTPFileSystem: ls() fix for root / path with dircache (#1635) (#1643)
1 parent 127a78a commit df042b1

File tree

2 files changed

+18
-3
lines changed

2 files changed

+18
-3
lines changed

fsspec/implementations/ftp.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -107,9 +107,9 @@ def ls(self, path, detail=True, **kwargs):
107107
except error_perm:
108108
out = _mlsd2(self.ftp, path) # Not platform independent
109109
for fn, details in out:
110-
if path == "/":
111-
path = "" # just for forming the names, below
112-
details["name"] = "/".join([path, fn.lstrip("/")])
110+
details["name"] = "/".join(
111+
["" if path == "/" else path, fn.lstrip("/")]
112+
)
113113
if details["type"] == "file":
114114
details["size"] = int(details["size"])
115115
else:

fsspec/implementations/tests/test_ftp.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,21 @@ def test_not_cached(ftp):
4444
assert fs is not fs2
4545

4646

47+
def test_ls_root_dircache(ftp):
48+
host, port = ftp
49+
fs = FTPFileSystem(host, port)
50+
51+
files = fs.ls("/", detail=False)
52+
53+
assert "/" in fs.dircache
54+
55+
fs.ftp = None # Ensure no ftp action will be done after
56+
57+
files2 = fs.ls("/", detail=False)
58+
59+
assert files == files2
60+
61+
4762
@pytest.mark.parametrize("cache_type", ["bytes", "mmap"])
4863
def test_complex(ftp_writable, cache_type):
4964
from fsspec.core import BytesCache

0 commit comments

Comments
 (0)