Skip to content

spec: implement lexists() #757

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Sep 15, 2021
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
3 changes: 3 additions & 0 deletions fsspec/implementations/local.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,9 @@ def info(self, path, **kwargs):
result["size"] = 0
return result

def lexists(self, path, **kwargs):
return osp.lexists(path)

def cp_file(self, path1, path2, **kwargs):
path1 = self._strip_protocol(path1).rstrip("/")
path2 = self._strip_protocol(path2).rstrip("/")
Expand Down
29 changes: 29 additions & 0 deletions fsspec/implementations/tests/test_local.py
Original file line number Diff line number Diff line change
Expand Up @@ -527,6 +527,35 @@ def test_linked_files(tmpdir):
assert f.read() == data


def test_linked_files_exists(tmpdir):
origin = tmpdir / "original"
copy_file = tmpdir / "copy"

fs = LocalFileSystem()
fs.touch(origin)

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

assert fs.exists(copy_file)
assert fs.lexists(copy_file)

os.unlink(origin)

assert not fs.exists(copy_file)
assert fs.lexists(copy_file)

os.unlink(copy_file)

assert not fs.exists(copy_file)
assert not fs.lexists(copy_file)


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

Expand Down
5 changes: 5 additions & 0 deletions fsspec/spec.py
Original file line number Diff line number Diff line change
Expand Up @@ -579,6 +579,11 @@ def exists(self, path, **kwargs):
# any exception allowed bar FileNotFoundError?
return False

def lexists(self, path, **kwargs):
"""If there is a file at the given path (including
broken links)"""
return self.exists(path)

def info(self, path, **kwargs):
"""Give details of entry at path

Expand Down