remote: fix ssh dir outputs

This commit is contained in:
Alexander Schepanovski
2019-07-02 18:49:19 +07:00
parent 30304c3454
commit 835a04a186
2 changed files with 17 additions and 5 deletions
+10
View File
@@ -192,6 +192,16 @@ class URLInfo(object):
scheme=self.scheme, netloc=self.netloc, path=self._path.parent
)
def relative_to(self, other):
if isinstance(other, str):
other_str = other
other = URLInfo(other)
if self.scheme != other.scheme or self.netloc != other.netloc:
raise ValueError(
"'{}' does not start with '{}'".format(self, other_str)
)
return self._path.relative_to(other._path)
def isin(self, other):
if isinstance(other, basestring):
other = self.__class__(other)
+7 -5
View File
@@ -137,17 +137,19 @@ class RemoteBASE(object):
dir_info = []
for root, dirs, files in self.walk(path_info):
root_info = path_info / root
if len(files) > LARGE_DIR_SIZE:
msg = (
"Computing md5 for a large directory {}. "
"This is only done once."
)
title = str(self.path_cls(root))
title = str(root_info)
logger.info(msg.format(title))
files = progress(files, name=title)
for fname in files:
file_info = self.path_cls(root) / fname
file_info = root_info / fname
relative_path = file_info.relative_to(path_info)
dir_info.append(
{
@@ -207,7 +209,7 @@ class RemoteBASE(object):
fobj = tempfile.NamedTemporaryFile(delete=False)
path = fobj.name
to_info = self.path_cls(path)
to_info = PathInfo(path)
self.cache.download([path_info], [to_info], no_progress_bar=True)
try:
@@ -226,7 +228,7 @@ class RemoteBASE(object):
for info in d:
# NOTE: here is a BUG, see comment to .as_posix() below
relative_path = self.path_cls.from_posix(info[self.PARAM_RELPATH])
relative_path = PathInfo.from_posix(info[self.PARAM_RELPATH])
info[self.PARAM_RELPATH] = relative_path.fspath
return d
@@ -720,7 +722,7 @@ class RemoteBASE(object):
def _remove_redundant_files(self, path_info, dir_info, force):
existing_files = set(
self.path_cls(root) / fname
path_info / root / fname
for root, _, files in self.walk(path_info)
for fname in files
)