Support file:// paths for repositories (#576).
Merge pull request #54 from diivi/feat/file-urls-support
This commit is contained in:
commit
c83fae5e5b
6 changed files with 39 additions and 26 deletions
|
@ -46,11 +46,7 @@ def export_tar_archive(
|
||||||
+ (('--dry-run',) if dry_run else ())
|
+ (('--dry-run',) if dry_run else ())
|
||||||
+ (('--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, archive, local_borg_version,)
|
||||||
repository if ':' in repository else os.path.abspath(repository),
|
|
||||||
archive,
|
|
||||||
local_borg_version,
|
|
||||||
)
|
|
||||||
+ (destination_path,)
|
+ (destination_path,)
|
||||||
+ (tuple(paths) if paths else ())
|
+ (tuple(paths) if paths else ())
|
||||||
)
|
)
|
||||||
|
|
|
@ -106,11 +106,7 @@ def extract_archive(
|
||||||
+ (('--strip-components', str(strip_components)) if strip_components else ())
|
+ (('--strip-components', str(strip_components)) if strip_components else ())
|
||||||
+ (('--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, archive, local_borg_version,)
|
||||||
repository if ':' in repository else os.path.abspath(repository),
|
|
||||||
archive,
|
|
||||||
local_borg_version,
|
|
||||||
)
|
|
||||||
+ (tuple(paths) if paths else ())
|
+ (tuple(paths) if paths else ())
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
import logging
|
import logging
|
||||||
|
import os
|
||||||
|
|
||||||
|
|
||||||
def normalize(config_filename, config):
|
def normalize(config_filename, config):
|
||||||
|
@ -68,10 +69,15 @@ 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.partition('file://')[-1])
|
||||||
)
|
)
|
||||||
|
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(
|
||||||
|
|
|
@ -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.partition('file://')[-1])
|
||||||
|
else:
|
||||||
|
return repository
|
||||||
|
|
||||||
|
|
||||||
def repositories_match(first, second):
|
def repositories_match(first, second):
|
||||||
|
|
|
@ -87,6 +87,11 @@ from borgmatic.config import normalize as module
|
||||||
{'location': {'repositories': ['ssh://foo@bar:1234/repo']}},
|
{'location': {'repositories': ['ssh://foo@bar:1234/repo']}},
|
||||||
False,
|
False,
|
||||||
),
|
),
|
||||||
|
(
|
||||||
|
{'location': {'repositories': ['file:///repo']}},
|
||||||
|
{'location': {'repositories': ['/repo']}},
|
||||||
|
False,
|
||||||
|
),
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
def test_normalize_applies_hard_coded_normalization_to_config(
|
def test_normalize_applies_hard_coded_normalization_to_config(
|
||||||
|
|
|
@ -83,6 +83,13 @@ def test_normalize_repository_path_passes_through_remote_repository():
|
||||||
module.normalize_repository_path(repository) == repository
|
module.normalize_repository_path(repository) == repository
|
||||||
|
|
||||||
|
|
||||||
|
def test_normalize_repository_path_passes_through_file_repository():
|
||||||
|
repository = 'file:///foo/bar/test.borg'
|
||||||
|
flexmock(module.os.path).should_receive('abspath').and_return('/foo/bar/test.borg')
|
||||||
|
|
||||||
|
module.normalize_repository_path(repository) == '/foo/bar/test.borg'
|
||||||
|
|
||||||
|
|
||||||
def test_normalize_repository_path_passes_through_absolute_repository():
|
def test_normalize_repository_path_passes_through_absolute_repository():
|
||||||
repository = '/foo/bar/test.borg'
|
repository = '/foo/bar/test.borg'
|
||||||
flexmock(module.os.path).should_receive('abspath').and_return(repository)
|
flexmock(module.os.path).should_receive('abspath').and_return(repository)
|
||||||
|
|
Loading…
Reference in a new issue