1
0
mirror of https://github.com/mail-in-a-box/mailinabox.git synced 2025-06-09 19:10:54 +00:00

Fixed issue with relative path for rsync relative names

Actually using the parsed URL `path` part, instead of doing a lousy split().
Renamed the `p` variable into something more sensible (`target`).

Fixes: #1019
This commit is contained in:
Bernard `Guyzmo` Pratz 2016-12-09 12:09:34 +01:00
parent 99d0afd650
commit 925d0f6417

View File

@ -382,21 +382,21 @@ def run_duplicity_restore(args):
def list_target_files(config): def list_target_files(config):
import urllib.parse import urllib.parse
try: try:
p = urllib.parse.urlparse(config["target"]) target = urllib.parse.urlparse(config["target"])
except ValueError: except ValueError:
return "invalid target" return "invalid target"
if p.scheme == "file": if target.scheme == "file":
return [(fn, os.path.getsize(os.path.join(p.path, fn))) for fn in os.listdir(p.path)] return [(fn, os.path.getsize(os.path.join(target.path, fn))) for fn in os.listdir(target.path)]
elif p.scheme == "rsync": elif target.scheme == "rsync":
rsync_fn_size_re = re.compile(r'.* ([^ ]*) [^ ]* [^ ]* (.*)') rsync_fn_size_re = re.compile(r'.* ([^ ]*) [^ ]* [^ ]* (.*)')
rsync_target = '{host}:{path}' rsync_target = '{host}:{path}'
_, target_host, target_path = config['target'].split('//') if not target.path.endswith('/'):
target_path = '/' + target_path target_path = target.path + '/'
if not target_path.endswith('/'): if target.path.startswith('/'):
target_path += '/' target_path = target.path[1:]
rsync_command = [ 'rsync', rsync_command = [ 'rsync',
'-e', '-e',
@ -404,7 +404,7 @@ def list_target_files(config):
'--list-only', '--list-only',
'-r', '-r',
rsync_target.format( rsync_target.format(
host=target_host, host=target.netloc,
path=target_path) path=target_path)
] ]
@ -419,19 +419,19 @@ def list_target_files(config):
else: else:
raise ValueError("Connection to rsync host failed") raise ValueError("Connection to rsync host failed")
elif p.scheme == "s3": elif target.scheme == "s3":
# match to a Region # match to a Region
fix_boto() # must call prior to importing boto fix_boto() # must call prior to importing boto
import boto.s3 import boto.s3
from boto.exception import BotoServerError from boto.exception import BotoServerError
for region in boto.s3.regions(): for region in boto.s3.regions():
if region.endpoint == p.hostname: if region.endpoint == target.hostname:
break break
else: else:
raise ValueError("Invalid S3 region/host.") raise ValueError("Invalid S3 region/host.")
bucket = p.path[1:].split('/')[0] bucket = target.path[1:].split('/')[0]
path = '/'.join(p.path[1:].split('/')[1:]) + '/' path = '/'.join(target.path[1:].split('/')[1:]) + '/'
# If no prefix is specified, set the path to '', otherwise boto won't list the files # If no prefix is specified, set the path to '', otherwise boto won't list the files
if path == '/': if path == '/':