mirror of https://github.com/borgbackup/borg.git
use _host to store host/ipv4/ipv6
for ipv6, it includes the outer square brackets. the host property strips any outer square brackets.
This commit is contained in:
parent
d99aff1276
commit
0d406e7baf
|
@ -769,7 +769,7 @@ def bin_to_hex(binary):
|
||||||
class Location:
|
class Location:
|
||||||
"""Object representing a repository / archive location
|
"""Object representing a repository / archive location
|
||||||
"""
|
"""
|
||||||
proto = user = host = port = path = archive = None
|
proto = user = _host = port = path = archive = None
|
||||||
|
|
||||||
# user must not contain "@", ":" or "/".
|
# user must not contain "@", ":" or "/".
|
||||||
# Quoting adduser error message:
|
# Quoting adduser error message:
|
||||||
|
@ -871,9 +871,7 @@ class Location:
|
||||||
if m:
|
if m:
|
||||||
self.proto = m.group('proto')
|
self.proto = m.group('proto')
|
||||||
self.user = m.group('user')
|
self.user = m.group('user')
|
||||||
self.host = m.group('host')
|
self._host = m.group('host')
|
||||||
if self.host is not None:
|
|
||||||
self.host = self.host.lstrip('[').rstrip(']')
|
|
||||||
self.port = m.group('port') and int(m.group('port')) or None
|
self.port = m.group('port') and int(m.group('port')) or None
|
||||||
self.path = normpath_special(m.group('path'))
|
self.path = normpath_special(m.group('path'))
|
||||||
self.archive = m.group('archive')
|
self.archive = m.group('archive')
|
||||||
|
@ -887,12 +885,10 @@ class Location:
|
||||||
m = self.scp_re.match(text)
|
m = self.scp_re.match(text)
|
||||||
if m:
|
if m:
|
||||||
self.user = m.group('user')
|
self.user = m.group('user')
|
||||||
self.host = m.group('host')
|
self._host = m.group('host')
|
||||||
if isinstance(self.host, str):
|
|
||||||
self.host = self.host.lstrip('[').rstrip(']')
|
|
||||||
self.path = normpath_special(m.group('path'))
|
self.path = normpath_special(m.group('path'))
|
||||||
self.archive = m.group('archive')
|
self.archive = m.group('archive')
|
||||||
self.proto = self.host and 'ssh' or 'file'
|
self.proto = self._host and 'ssh' or 'file'
|
||||||
return True
|
return True
|
||||||
return False
|
return False
|
||||||
|
|
||||||
|
@ -916,6 +912,12 @@ class Location:
|
||||||
def __repr__(self):
|
def __repr__(self):
|
||||||
return "Location(%s)" % self
|
return "Location(%s)" % self
|
||||||
|
|
||||||
|
@property
|
||||||
|
def host(self):
|
||||||
|
# strip square brackets used for IPv6 addrs
|
||||||
|
if self._host is not None:
|
||||||
|
return self._host.lstrip('[').rstrip(']')
|
||||||
|
|
||||||
def canonical_path(self):
|
def canonical_path(self):
|
||||||
if self.proto == 'file':
|
if self.proto == 'file':
|
||||||
return self.path
|
return self.path
|
||||||
|
@ -927,7 +929,7 @@ class Location:
|
||||||
else:
|
else:
|
||||||
path = self.path
|
path = self.path
|
||||||
return 'ssh://{}{}{}{}'.format('{}@'.format(self.user) if self.user else '',
|
return 'ssh://{}{}{}{}'.format('{}@'.format(self.user) if self.user else '',
|
||||||
self.host,
|
self._host, # needed for ipv6 addrs
|
||||||
':{}'.format(self.port) if self.port else '',
|
':{}'.format(self.port) if self.port else '',
|
||||||
path)
|
path)
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue