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 ()) + (('--tar-filter', tar_filter) if tar_filter else ())
+ (('--strip-components', str(strip_components)) if strip_components else ()) + (('--strip-components', str(strip_components)) if strip_components else ())
+ flags.make_repository_archive_flags( + 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, archive,
local_borg_version, local_borg_version,
) )

View file

@ -100,7 +100,11 @@ def extract_archive(
+ (('--progress',) if progress else ()) + (('--progress',) if progress else ())
+ (('--stdout',) if extract_to_stdout else ()) + (('--stdout',) if extract_to_stdout else ())
+ flags.make_repository_archive_flags( + 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, archive,
local_borg_version, local_borg_version,
) )

View file

@ -1,4 +1,5 @@
import logging import logging
import os
def normalize(config_filename, config): def normalize(config_filename, config):
@ -68,20 +69,23 @@ def normalize(config_filename, config):
) )
) )
) )
if ':' in repository and not repository.startswith('ssh://'): if ':' in repository:
rewritten_repository = ( if repository.startswith('file://'):
f"ssh://{repository.replace(':~', '/~').replace(':/', '/').replace(':', '/./')}" config['location']['repositories'].append(os.path.abspath(repository[7:]))
) elif repository.startswith('ssh://'):
logs.append( config['location']['repositories'].append(repository)
logging.makeLogRecord( else:
dict( rewritten_repository = f"ssh://{repository.replace(':~', '/~').replace(':/', '/').replace(':', '/./')}"
levelno=logging.WARNING, logs.append(
levelname='WARNING', logging.makeLogRecord(
msg=f'{config_filename}: Remote repository paths without ssh:// syntax are deprecated. Interpreting "{repository}" as "{rewritten_repository}"', 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: else:
config['location']['repositories'].append(repository) 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). 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. # A colon in the repository could mean that it's either a file:// URL or a remote repository.
if ':' in 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 repository
return os.path.abspath(repository)
def repositories_match(first, second): def repositories_match(first, second):
''' '''