Skip to content

Commit

Permalink
localfs: add link/symlink/islink methods (#1059)
Browse files Browse the repository at this point in the history
  • Loading branch information
skshetry committed Oct 3, 2022
1 parent 07303ea commit 2034706
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 0 deletions.
13 changes: 13 additions & 0 deletions fsspec/implementations/local.py
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,19 @@ def mv_file(self, path1, path2, **kwargs):
path2 = self._strip_protocol(path2).rstrip("/")
shutil.move(path1, path2)

def link(self, src, dst, **kwargs):
src = self._strip_protocol(src)
dst = self._strip_protocol(dst)
os.link(src, dst, **kwargs)

def symlink(self, src, dst, **kwargs):
src = self._strip_protocol(src)
dst = self._strip_protocol(dst)
os.symlink(src, dst, **kwargs)

def islink(self, path) -> bool:
return os.path.islink(self._strip_protocol(path))

def rm_file(self, path):
os.remove(path)

Expand Down
22 changes: 22 additions & 0 deletions fsspec/implementations/tests/test_local.py
Original file line number Diff line number Diff line change
Expand Up @@ -785,3 +785,25 @@ def test_numpy_fromfile(tmpdir):
arr = np.arange(10, dtype=dt)
arr.tofile(fn)
assert np.array_equal(np.fromfile(fn, dtype=dt), arr)


def test_link(tmpdir):
target = os.path.join(tmpdir, "target")
link = os.path.join(tmpdir, "link")

fs = LocalFileSystem()
fs.touch(target)

fs.link(target, link)
assert fs.info(link)["nlink"] > 1


def test_symlink(tmpdir):
target = os.path.join(tmpdir, "target")
link = os.path.join(tmpdir, "link")

fs = LocalFileSystem()
fs.touch(target)

fs.symlink(target, link)
assert fs.islink(link)

0 comments on commit 2034706

Please sign in to comment.