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,10 +69,13 @@ 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://'):
config['location']['repositories'].append(repository)
else:
rewritten_repository = f"ssh://{repository.replace(':~', '/~').replace(':/', '/').replace(':', '/./')}"
logs.append( logs.append(
logging.makeLogRecord( logging.makeLogRecord(
dict( dict(

View file

@ -126,11 +126,14 @@ 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.
return repository if ':' not in repository:
return os.path.abspath(repository) return os.path.abspath(repository)
elif repository.startswith('file://'):
return os.path.abspath(repository[7:])
else:
return repository
def repositories_match(first, second): def repositories_match(first, second):