From f4563bdd85cd598284de5bd896d2f0864f51cc53 Mon Sep 17 00:00:00 2001 From: "Mr. Outis" Date: Fri, 23 Aug 2019 21:20:50 -0500 Subject: [PATCH] ssh: support reflinks and hardlinks --- dvc/remote/ssh/__init__.py | 11 +++++++---- dvc/remote/ssh/connection.py | 8 ++++++++ 2 files changed, 15 insertions(+), 4 deletions(-) diff --git a/dvc/remote/ssh/__init__.py b/dvc/remote/ssh/__init__.py index f19e1df80..3ff2ae546 100644 --- a/dvc/remote/ssh/__init__.py +++ b/dvc/remote/ssh/__init__.py @@ -50,9 +50,7 @@ class RemoteSSH(RemoteBASE): # We use conservative setting of 4 instead to not exhaust max sessions. CHECKSUM_JOBS = 4 - # XXX: Friendly reminder to add "reflink" to the default types - # after is implemented - DEFAULT_CACHE_TYPES = ["symlink", "copy"] + DEFAULT_CACHE_TYPES = ["reflink, copy"] def __init__(self, repo, config): super(RemoteSSH, self).__init__(repo, config) @@ -323,7 +321,12 @@ class RemoteSSH(RemoteBASE): @classmethod def _get_link_method(cls, link_type, ssh): - CACHE_TYPE_MAP = {"copy": ssh.cp, "symlink": ssh.symlink} + CACHE_TYPE_MAP = { + "copy": ssh.cp, + "symlink": ssh.symlink, + "reflink": ssh.reflink, + "hardlink": ssh.hardlink, + } try: return CACHE_TYPE_MAP[link_type] diff --git a/dvc/remote/ssh/connection.py b/dvc/remote/ssh/connection.py index 423ce6604..6e49132b6 100644 --- a/dvc/remote/ssh/connection.py +++ b/dvc/remote/ssh/connection.py @@ -294,3 +294,11 @@ class SSHConnection: def symlink(self, *args, **kwargs): return self.sftp.symlink(*args, **kwargs) + + def reflink(self, src, dest): + self.makedirs(posixpath.dirname(dest)) + self.execute("cp --reflink {} {}".format(src, dest)) + + def hardlink(self, src, dest): + self.makedirs(posixpath.dirname(dest)) + self.execute("ln {} {}".format(src, dest))