Skip to content
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
42 changes: 21 additions & 21 deletions dvc/fs/ssh/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -119,16 +119,16 @@ def ensure_credentials(self):
if self.ask_password and self.password is None:
self.password = ask_password(self.host, self.user, self.port)

def ssh(self, path_info):
def ssh(self):
Copy link
Contributor Author

@efiop efiop Jun 30, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One issue that arises here is that move() in ObjectDB.add() will no longer work for advanced cases where a user has external-outputs with external cache that is not located on the same filesystem. This very rare though and has been a common problem for other filesystems too in external-output scenario anyway, so I woundn't fix it right now, as that is a hack already that we are keeping https://github.com/iterative/dvc/blob/master/dvc/objects/db/base.py#L78 for regular non-extrnal dvc add and such. We will be adjusting that in save/transfer unification anyway.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also, now that this doesn't take any arguments, we could adjust the way it looks and works, but again I would just wait for sshfs migration, since it will simply throw away this code anyway, so doesn't seem like it is worth wasting time refactoring this now.

self.ensure_credentials()

from .connection import SSHConnection

return get_connection(
SSHConnection,
path_info.host,
username=path_info.user,
port=path_info.port,
self.host,
username=self.user,
port=self.port,
key_filename=self.keyfile,
timeout=self.timeout,
password=self.password,
Expand All @@ -141,7 +141,7 @@ def ssh(self, path_info):
def open(self, path_info, mode="r", encoding=None, **kwargs):
assert mode in {"r", "rt", "rb", "wb"}

with self.ssh(path_info) as ssh, closing(
with self.ssh() as ssh, closing(
ssh.sftp.open(path_info.path, mode)
) as fd:
if "b" in mode:
Expand All @@ -150,52 +150,52 @@ def open(self, path_info, mode="r", encoding=None, **kwargs):
yield io.TextIOWrapper(fd, encoding=encoding)

def exists(self, path_info) -> bool:
with self.ssh(path_info) as ssh:
with self.ssh() as ssh:
return ssh.exists(path_info.path)

def isdir(self, path_info):
with self.ssh(path_info) as ssh:
with self.ssh() as ssh:
return ssh.isdir(path_info.path)

def isfile(self, path_info):
with self.ssh(path_info) as ssh:
with self.ssh() as ssh:
return ssh.isfile(path_info.path)

def walk_files(self, path_info, **kwargs):
with self.ssh(path_info) as ssh:
with self.ssh() as ssh:
for fname in ssh.walk_files(path_info.path):
yield path_info.replace(path=fname)

def remove(self, path_info):
if path_info.scheme != self.scheme:
raise NotImplementedError

with self.ssh(path_info) as ssh:
with self.ssh() as ssh:
ssh.remove(path_info.path)

def makedirs(self, path_info):
with self.ssh(path_info) as ssh:
with self.ssh() as ssh:
ssh.makedirs(path_info.path)

def move(self, from_info, to_info):
if from_info.scheme != self.scheme or to_info.scheme != self.scheme:
raise NotImplementedError

with self.ssh(from_info) as ssh:
with self.ssh() as ssh:
ssh.move(from_info.path, to_info.path)

def copy(self, from_info, to_info):
if not from_info.scheme == to_info.scheme == self.scheme:
raise NotImplementedError

with self.ssh(from_info) as ssh:
with self.ssh() as ssh:
ssh.atomic_copy(from_info.path, to_info.path)

def symlink(self, from_info, to_info):
if not from_info.scheme == to_info.scheme == self.scheme:
raise NotImplementedError

with self.ssh(from_info) as ssh:
with self.ssh() as ssh:
ssh.symlink(from_info.path, to_info.path)

def hardlink(self, from_info, to_info):
Expand All @@ -205,7 +205,7 @@ def hardlink(self, from_info, to_info):
# See dvc/remote/local/__init__.py - hardlink()
if self.getsize(from_info) == 0:

with self.ssh(to_info) as ssh:
with self.ssh() as ssh:
ssh.sftp.open(to_info.path, "w").close()

logger.debug(
Expand All @@ -215,26 +215,26 @@ def hardlink(self, from_info, to_info):
)
return

with self.ssh(from_info) as ssh:
with self.ssh() as ssh:
ssh.hardlink(from_info.path, to_info.path)

def reflink(self, from_info, to_info):
if from_info.scheme != self.scheme or to_info.scheme != self.scheme:
raise NotImplementedError

with self.ssh(from_info) as ssh:
with self.ssh() as ssh:
ssh.reflink(from_info.path, to_info.path)

def md5(self, path_info):
with self.ssh(path_info) as ssh:
with self.ssh() as ssh:
return HashInfo(
"md5",
ssh.md5(path_info.path),
size=ssh.getsize(path_info.path),
)

def info(self, path_info):
with self.ssh(path_info) as ssh:
with self.ssh() as ssh:
return ssh.info(path_info.path)

def _upload_fobj(self, fobj, to_info, **kwargs):
Expand All @@ -243,7 +243,7 @@ def _upload_fobj(self, fobj, to_info, **kwargs):
shutil.copyfileobj(fobj, fdest)

def _download(self, from_info, to_file, name=None, no_progress_bar=False):
with self.ssh(from_info) as ssh:
with self.ssh() as ssh:
ssh.download(
from_info.path,
to_file,
Expand All @@ -254,7 +254,7 @@ def _download(self, from_info, to_file, name=None, no_progress_bar=False):
def _upload(
self, from_file, to_info, name=None, no_progress_bar=False, **_kwargs
):
with self.ssh(to_info) as ssh:
with self.ssh() as ssh:
ssh.upload(
from_file,
to_info.path,
Expand Down
4 changes: 2 additions & 2 deletions dvc/objects/db/ssh.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ def _exists(chunk_and_channel):
callback(path)
return ret

with self.fs.ssh(path_infos[0]) as ssh:
with self.fs.ssh() as ssh:
channels = ssh.open_max_sftp_channels()
max_workers = len(channels)

Expand Down Expand Up @@ -78,7 +78,7 @@ def _list_paths(self, prefix=None, progress_callback=None):
root = posixpath.join(self.path_info.path, prefix[:2])
else:
root = self.path_info.path
with self.fs.ssh(self.path_info) as ssh:
with self.fs.ssh() as ssh:
if prefix and not ssh.exists(root):
return
# If we simply return an iterator then with above closes instantly
Expand Down