From f53a2dc8e5f7a7fe9fc3408e09802a9c9acc6b23 Mon Sep 17 00:00:00 2001 From: skshetry Date: Thu, 20 Oct 2022 07:58:48 +0545 Subject: [PATCH] use fsspec's link/islink/symlink methods (#161) --- src/dvc_objects/fs/base.py | 16 ++++++++++------ src/dvc_objects/fs/local.py | 9 ++++----- 2 files changed, 14 insertions(+), 11 deletions(-) diff --git a/src/dvc_objects/fs/base.py b/src/dvc_objects/fs/base.py index f13e11c..6b10474 100644 --- a/src/dvc_objects/fs/base.py +++ b/src/dvc_objects/fs/base.py @@ -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) diff --git a/src/dvc_objects/fs/local.py b/src/dvc_objects/fs/local.py index 892ea74..5010d14 100644 --- a/src/dvc_objects/fs/local.py +++ b/src/dvc_objects/fs/local.py @@ -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`