feat: file:// URLs support

This commit is contained in:
Divyansh Singh 2023-03-20 02:43:23 +05:30
parent a7c055264d
commit 58c95d8015
4 changed files with 33 additions and 18 deletions

View File

@ -47,7 +47,11 @@ def export_tar_archive(
+ (('--tar-filter', tar_filter) if tar_filter else ())
+ (('--strip-components', str(strip_components)) if strip_components else ())
+ flags.make_repository_archive_flags(
repository if ':' in repository else os.path.abspath(repository),
os.path.abspath(repository)
if ':' not in repository
else os.path.abspath(repository[7:])
if repository.startswith('file://')
else repository,
archive,
local_borg_version,
)

View File

@ -100,7 +100,11 @@ def extract_archive(
+ (('--progress',) if progress else ())
+ (('--stdout',) if extract_to_stdout else ())
+ flags.make_repository_archive_flags(
repository if ':' in repository else os.path.abspath(repository),
os.path.abspath(repository)
if ':' not in repository
else os.path.abspath(repository[7:])
if repository.startswith('file://')
else repository,
archive,
local_borg_version,
)

View File

@ -1,4 +1,5 @@
import logging
import os
def normalize(config_filename, config):
@ -68,20 +69,23 @@ def normalize(config_filename, config):
)
)
)
if ':' in repository and not repository.startswith('ssh://'):
rewritten_repository = (
f"ssh://{repository.replace(':~', '/~').replace(':/', '/').replace(':', '/./')}"
)
logs.append(
logging.makeLogRecord(
dict(
levelno=logging.WARNING,
levelname='WARNING',
msg=f'{config_filename}: Remote repository paths without ssh:// syntax are deprecated. Interpreting "{repository}" as "{rewritten_repository}"',
if ':' in repository:
if repository.startswith('file://'):
config['location']['repositories'].append(os.path.abspath(repository[7:]))
elif repository.startswith('ssh://'):
config['location']['repositories'].append(repository)
else:
rewritten_repository = f"ssh://{repository.replace(':~', '/~').replace(':/', '/').replace(':', '/./')}"
logs.append(
logging.makeLogRecord(
dict(
levelno=logging.WARNING,
levelname='WARNING',
msg=f'{config_filename}: Remote repository paths without ssh:// syntax are deprecated. Interpreting "{repository}" as "{rewritten_repository}"',
)
)
)
)
config['location']['repositories'].append(rewritten_repository)
config['location']['repositories'].append(rewritten_repository)
else:
config['location']['repositories'].append(repository)

View File

@ -126,12 +126,15 @@ def normalize_repository_path(repository):
'''
Given a repository path, return the absolute path of it (for local repositories).
'''
# A colon in the repository indicates it's a remote repository. Bail.
if ':' in repository:
# A colon in the repository could mean that it's either a file:// URL or a remote repository.
# If it's a remote repository, we don't want to normalize it. If it's a file:// URL, we do.
if ':' not in repository:
return os.path.abspath(repository)
elif repository.startswith('file://'):
return os.path.abspath(repository[7:])
else:
return repository
return os.path.abspath(repository)
def repositories_match(first, second):
'''