mirror of
https://github.com/Stone-Red-Code/dvc.git
synced 2026-11-02 07:18:25 +01:00
tests: ssh hardlink optimization
This commit is contained in:
+1
-1
@@ -7,7 +7,7 @@ import posixpath
|
||||
from funcy import cached_property
|
||||
|
||||
from dvc.utils.compat import str, builtin_str, basestring, is_py2
|
||||
from dvc.utils.compat import pathlib, urlparse
|
||||
from dvc.utils.compat import pathlib, urlparse, urljoin
|
||||
|
||||
|
||||
# On Python 2.7/Windows sys.getfilesystemencoding() is set to mbcs,
|
||||
|
||||
@@ -193,7 +193,9 @@ class RemoteSSH(RemoteBASE):
|
||||
|
||||
# See dvc/remote/local/__init__.py - hardlink()
|
||||
if self.getsize(from_info) == 0:
|
||||
self.open(to_info, "w").close()
|
||||
|
||||
with self.ssh(to_info) as ssh:
|
||||
ssh.sftp.open(to_info.path, "w").close()
|
||||
|
||||
logger.debug(
|
||||
"Created empty file: {src} -> {dest}".format(
|
||||
|
||||
@@ -177,3 +177,13 @@ def _close_pools():
|
||||
|
||||
yield
|
||||
close_pools()
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def chdir_tmp(tmp_path):
|
||||
cwd = os.getcwd()
|
||||
try:
|
||||
os.chdir(tmp_path)
|
||||
yield
|
||||
finally:
|
||||
os.chdir(cwd)
|
||||
|
||||
@@ -9,15 +9,6 @@ import filecmp
|
||||
from dvc.system import System
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def chdir_tmp(tmp_path):
|
||||
cwd = os.getcwd()
|
||||
try:
|
||||
os.chdir(tmp_path)
|
||||
yield
|
||||
finally:
|
||||
os.chdir(cwd)
|
||||
|
||||
@pytest.fixture
|
||||
def foo():
|
||||
with open("foo", "w") as fobj:
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
import getpass
|
||||
import os
|
||||
import sys
|
||||
import posixpath
|
||||
|
||||
from unittest import TestCase
|
||||
|
||||
@@ -8,6 +9,8 @@ from mock import patch, mock_open
|
||||
import pytest
|
||||
|
||||
from dvc.remote.ssh import RemoteSSH
|
||||
from dvc.path_info import URLInfo
|
||||
from dvc.system import System
|
||||
|
||||
|
||||
class TestRemoteSSH(TestCase):
|
||||
@@ -182,3 +185,23 @@ def test_ssh_gss_auth(mock_file, mock_exists, config, expected_gss_auth):
|
||||
mock_exists.assert_called_with(RemoteSSH.ssh_config_filename())
|
||||
mock_file.assert_called_with(RemoteSSH.ssh_config_filename())
|
||||
assert remote.gss_auth == expected_gss_auth
|
||||
|
||||
def test_hardlink_optimization(chdir_tmp, ssh_server):
|
||||
config = {
|
||||
"url": "ssh://localhost",
|
||||
"hostname": ssh_server.test_creds["host"],
|
||||
"port": ssh_server.test_creds["port"],
|
||||
"user": ssh_server.test_creds["username"],
|
||||
"keyfile": ssh_server.test_creds["key_filename"],
|
||||
}
|
||||
remote = RemoteSSH(None, config)
|
||||
|
||||
open("empty", "w").close()
|
||||
|
||||
def urlpath(path):
|
||||
netloc = remote.path_info.netloc
|
||||
path = posixpath.abspath(path)
|
||||
return URLInfo("ssh://{}/{}".format(netloc, path))
|
||||
|
||||
remote.hardlink(urlpath("empty"), urlpath("bar"))
|
||||
assert not System.is_hardlink("bar")
|
||||
|
||||
Reference in New Issue
Block a user