Skip to content

Commit

Permalink
use fsspec's link/islink/symlink methods (#161)
Browse files Browse the repository at this point in the history
  • Loading branch information
skshetry authored Oct 20, 2022
1 parent afdc955 commit f53a2dc
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 11 deletions.
16 changes: 10 additions & 6 deletions src/dvc_objects/fs/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -316,24 +316,28 @@ def symlink(self, from_info: AnyFSPath, to_info: AnyFSPath) -> None:
except AttributeError:
raise LinkError("symlink", self, from_info)

def hardlink(self, from_info: AnyFSPath, to_info: AnyFSPath) -> None:
def link(self, from_info: AnyFSPath, to_info: AnyFSPath) -> None:
try:
return self.fs.hardlink(from_info, to_info)
return self.fs.link(from_info, to_info)
except AttributeError:
raise LinkError("symlink", self, from_info)
raise LinkError("hardlink", self, from_info)

hardlink = link

def reflink(self, from_info: AnyFSPath, to_info: AnyFSPath) -> None:
try:
return self.fs.reflink(from_info, to_info)
except AttributeError:
raise LinkError("symlink", self, from_info)
raise LinkError("reflink", self, from_info)

def is_symlink(self, path: AnyFSPath) -> bool:
def islink(self, path: AnyFSPath) -> bool:
try:
return self.fs.is_symlink(path)
return self.fs.islink(path)
except AttributeError:
return False

is_symlink = islink

def is_hardlink(self, path: AnyFSPath) -> bool:
try:
return self.fs.is_hardlink(path)
Expand Down
9 changes: 4 additions & 5 deletions src/dvc_objects/fs/local.py
Original file line number Diff line number Diff line change
Expand Up @@ -136,17 +136,16 @@ def open(self, path, mode="r", encoding=None, **kwargs):
return open(path, mode=mode, encoding=encoding)

def symlink(self, path1, path2):
return system.symlink(path1, path2)
return self.fs.symlink(path1, path2)

@staticmethod
def is_symlink(path):
return system.is_symlink(path)
def islink(self, path):
return self.fs.islink(path)

@staticmethod
def is_hardlink(path):
return system.is_hardlink(path)

def hardlink(self, path1, path2):
def link(self, path1, path2):
# If there are a lot of empty files (which happens a lot in datasets),
# and the cache type is `hardlink`, we might reach link limits and
# will get something like: `too many links error`
Expand Down

0 comments on commit f53a2dc

Please sign in to comment.