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
18 changes: 10 additions & 8 deletions fsspec/implementations/local.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,21 +59,23 @@ def glob(self, path, **kwargs):
def info(self, path, **kwargs):
path = self._strip_protocol(path)
out = os.stat(path, follow_symlinks=False)
dest = False
if os.path.islink(path):
t = "link"
dest = os.readlink(path)
elif os.path.isdir(path):
if os.path.isdir(path):
t = "directory"
elif os.path.isfile(path):
t = "file"
else:
t = "other"
result = {"name": path, "size": out.st_size, "type": t, "created": out.st_ctime}
result = {
"name": path,
"size": out.st_size,
"type": t,
"created": out.st_ctime,
"islink": os.path.islink(path),
}
for field in ["mode", "uid", "gid", "mtime"]:
result[field] = getattr(out, "st_" + field)
if dest:
result["destination"] = dest
if result["islink"]:
result["destination"] = os.readlink(path)
try:
out2 = os.stat(path, follow_symlinks=True)
result["size"] = out2.st_size
Expand Down
38 changes: 35 additions & 3 deletions fsspec/implementations/tests/test_local.py
Original file line number Diff line number Diff line change
Expand Up @@ -450,7 +450,7 @@ def test_make_path_posix():
assert "/" in make_path_posix("rel\\path", sep="\\")


def test_links(tmpdir):
def test_linked_files(tmpdir):
tmpdir = str(tmpdir)
fn0 = os.path.join(tmpdir, "target")
fn1 = os.path.join(tmpdir, "link1")
Expand All @@ -469,8 +469,12 @@ def test_links(tmpdir):

fs = LocalFileSystem()
assert fs.info(fn0)["type"] == "file"
assert fs.info(fn1)["type"] == "link"
assert fs.info(fn2)["type"] == "link"
assert fs.info(fn1)["type"] == "file"
assert fs.info(fn2)["type"] == "file"

assert not fs.info(fn0)["islink"]
assert fs.info(fn1)["islink"]
assert fs.info(fn2)["islink"]

assert fs.info(fn0)["size"] == len(data)
assert fs.info(fn1)["size"] == len(data)
Expand All @@ -485,6 +489,34 @@ def test_links(tmpdir):
assert f.read() == data


def test_linked_directories(tmpdir):
tmpdir = str(tmpdir)

subdir0 = os.path.join(tmpdir, "target")
subdir1 = os.path.join(tmpdir, "link1")
subdir2 = os.path.join(tmpdir, "link2")

os.makedirs(subdir0)

try:
os.symlink(subdir0, subdir1)
os.symlink(subdir0, subdir2)
except OSError:
if WIN:
pytest.xfail("Ran on win without admin permissions")
else:
raise

fs = LocalFileSystem()
assert fs.info(subdir0)["type"] == "directory"
assert fs.info(subdir1)["type"] == "directory"
assert fs.info(subdir2)["type"] == "directory"

assert not fs.info(subdir0)["islink"]
assert fs.info(subdir1)["islink"]
assert fs.info(subdir2)["islink"]


def test_isfilestore():
fs = LocalFileSystem(auto_mkdir=False)
assert fs._isfilestore()
Expand Down