Skip to content

Commit 1dd7de5

Browse files
authored
Merge pull request #757 from isidentical/lexists
spec: implement lexists()
2 parents 0589358 + 315c343 commit 1dd7de5

File tree

3 files changed

+37
-0
lines changed

3 files changed

+37
-0
lines changed

fsspec/implementations/local.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,9 @@ def info(self, path, **kwargs):
105105
result["size"] = 0
106106
return result
107107

108+
def lexists(self, path, **kwargs):
109+
return osp.lexists(path)
110+
108111
def cp_file(self, path1, path2, **kwargs):
109112
path1 = self._strip_protocol(path1).rstrip("/")
110113
path2 = self._strip_protocol(path2).rstrip("/")

fsspec/implementations/tests/test_local.py

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -527,6 +527,35 @@ def test_linked_files(tmpdir):
527527
assert f.read() == data
528528

529529

530+
def test_linked_files_exists(tmpdir):
531+
origin = tmpdir / "original"
532+
copy_file = tmpdir / "copy"
533+
534+
fs = LocalFileSystem()
535+
fs.touch(origin)
536+
537+
try:
538+
os.symlink(origin, copy_file)
539+
except OSError:
540+
if WIN:
541+
pytest.xfail("Ran on win without admin permissions")
542+
else:
543+
raise
544+
545+
assert fs.exists(copy_file)
546+
assert fs.lexists(copy_file)
547+
548+
os.unlink(origin)
549+
550+
assert not fs.exists(copy_file)
551+
assert fs.lexists(copy_file)
552+
553+
os.unlink(copy_file)
554+
555+
assert not fs.exists(copy_file)
556+
assert not fs.lexists(copy_file)
557+
558+
530559
def test_linked_directories(tmpdir):
531560
tmpdir = str(tmpdir)
532561

fsspec/spec.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -579,6 +579,11 @@ def exists(self, path, **kwargs):
579579
# any exception allowed bar FileNotFoundError?
580580
return False
581581

582+
def lexists(self, path, **kwargs):
583+
"""If there is a file at the given path (including
584+
broken links)"""
585+
return self.exists(path)
586+
582587
def info(self, path, **kwargs):
583588
"""Give details of entry at path
584589

0 commit comments

Comments
 (0)