Fix new "repositories:" sub-options ("append_only", "make_parent_directories", etc.) (#303).

This commit is contained in:
Dan Helfman
2025-03-31 15:26:24 -07:00
parent 10fb02c40a
commit f166111b9b
6 changed files with 61 additions and 20 deletions
+3 -3
View File
@@ -52,9 +52,9 @@ def run_repo_create(
else repo_create_arguments.storage_quota
),
(
repository.get('make_parent_dirs')
if repo_create_arguments.make_parent_dirs is None
else repo_create_arguments.make_parent_dirs
repository.get('make_parent_directories')
if repo_create_arguments.make_parent_directories is None
else repo_create_arguments.make_parent_directories
),
local_path=local_path,
remote_path=remote_path,
+2 -2
View File
@@ -24,7 +24,7 @@ def create_repository(
copy_crypt_key=False,
append_only=None,
storage_quota=None,
make_parent_dirs=False,
make_parent_directories=False,
local_path='borg',
remote_path=None,
):
@@ -79,7 +79,7 @@ def create_repository(
+ (('--copy-crypt-key',) if copy_crypt_key else ())
+ (('--append-only',) if append_only else ())
+ (('--storage-quota', storage_quota) if storage_quota else ())
+ (('--make-parent-dirs',) if make_parent_dirs else ())
+ (('--make-parent-dirs',) if make_parent_directories else ())
+ (('--info',) if logger.getEffectiveLevel() == logging.INFO else ())
+ (('--debug',) if logger.isEnabledFor(logging.DEBUG) else ())
+ (('--log-json',) if global_arguments.log_json else ())
+3
View File
@@ -666,6 +666,7 @@ def make_parsers(schema, unparsed_arguments):
)
repo_create_group.add_argument(
'--append-only',
default=None,
action='store_true',
help='Create an append-only repository',
)
@@ -675,6 +676,8 @@ def make_parsers(schema, unparsed_arguments):
)
repo_create_group.add_argument(
'--make-parent-dirs',
dest='make_parent_directories',
default=None,
action='store_true',
help='Create any missing parent directories of the repository directory',
)
+17 -1
View File
@@ -33,6 +33,7 @@ properties:
type: object
required:
- path
additionalProperties: false
properties:
path:
type: string
@@ -67,7 +68,7 @@ properties:
only used for the repo-create action. Defaults to no
quota.
example: 5G
make_parent_dirs:
make_parent_directories:
type: boolean
description: |
Whether any missing parent directories of the repository
@@ -1187,6 +1188,7 @@ properties:
run: [echo Backing up.]
bootstrap:
type: object
additionalProperties: false
properties:
store_config_files:
type: boolean
@@ -1918,6 +1920,7 @@ properties:
example: tk_AgQdq7mVBoFD37zQVN29RhuMzNIz2
start:
type: object
additionalProperties: false
properties:
title:
type: string
@@ -1941,6 +1944,7 @@ properties:
example: incoming_envelope
finish:
type: object
additionalProperties: false
properties:
title:
type: string
@@ -1964,6 +1968,7 @@ properties:
example: incoming_envelope
fail:
type: object
additionalProperties: false
properties:
title:
type: string
@@ -2022,6 +2027,7 @@ properties:
example: hwRwoWsXMBWwgrSecfa9EfPey55WSN
start:
type: object
additionalProperties: false
properties:
message:
type: string
@@ -2097,6 +2103,7 @@ properties:
example: Pushover Link
finish:
type: object
additionalProperties: false
properties:
message:
type: string
@@ -2172,6 +2179,7 @@ properties:
example: Pushover Link
fail:
type: object
additionalProperties: false
properties:
message:
type: string
@@ -2311,6 +2319,7 @@ properties:
example: fakekey
start:
type: object
additionalProperties: false
properties:
value:
type: ["integer", "string"]
@@ -2319,6 +2328,7 @@ properties:
example: STARTED
finish:
type: object
additionalProperties: false
properties:
value:
type: ["integer", "string"]
@@ -2327,6 +2337,7 @@ properties:
example: FINISH
fail:
type: object
additionalProperties: false
properties:
value:
type: ["integer", "string"]
@@ -2358,6 +2369,7 @@ properties:
type: array
items:
type: object
additionalProperties: false
required:
- url
- label
@@ -2399,6 +2411,7 @@ properties:
start:
type: object
required: ['body']
additionalProperties: false
properties:
title:
type: string
@@ -2414,6 +2427,7 @@ properties:
finish:
type: object
required: ['body']
additionalProperties: false
properties:
title:
type: string
@@ -2429,6 +2443,7 @@ properties:
fail:
type: object
required: ['body']
additionalProperties: false
properties:
title:
type: string
@@ -2444,6 +2459,7 @@ properties:
log:
type: object
required: ['body']
additionalProperties: false
properties:
title:
type: string
+10 -10
View File
@@ -15,7 +15,7 @@ def test_run_repo_create_with_encryption_mode_argument_does_not_raise():
copy_crypt_key=flexmock(),
append_only=flexmock(),
storage_quota=flexmock(),
make_parent_dirs=flexmock(),
make_parent_directories=flexmock(),
)
module.run_repo_create(
@@ -40,7 +40,7 @@ def test_run_repo_create_with_encryption_mode_option_does_not_raise():
copy_crypt_key=flexmock(),
append_only=flexmock(),
storage_quota=flexmock(),
make_parent_dirs=flexmock(),
make_parent_directories=flexmock(),
)
module.run_repo_create(
@@ -65,7 +65,7 @@ def test_run_repo_create_without_encryption_mode_raises():
copy_crypt_key=flexmock(),
append_only=flexmock(),
storage_quota=flexmock(),
make_parent_dirs=flexmock(),
make_parent_directories=flexmock(),
)
with pytest.raises(ValueError):
@@ -93,7 +93,7 @@ def test_run_repo_create_bails_if_repository_does_not_match():
copy_crypt_key=flexmock(),
append_only=flexmock(),
storage_quota=flexmock(),
make_parent_dirs=flexmock(),
make_parent_directories=flexmock(),
)
module.run_repo_create(
@@ -121,7 +121,7 @@ def test_run_repo_create_favors_flags_over_config():
object,
append_only=False,
storage_quota=0,
make_parent_dirs=False,
make_parent_directories=False,
local_path=object,
remote_path=object,
).once()
@@ -132,7 +132,7 @@ def test_run_repo_create_favors_flags_over_config():
copy_crypt_key=flexmock(),
append_only=False,
storage_quota=0,
make_parent_dirs=False,
make_parent_directories=False,
)
module.run_repo_create(
@@ -140,7 +140,7 @@ def test_run_repo_create_favors_flags_over_config():
'path': 'repo',
'append_only': True,
'storage_quota': '10G',
'make_parent_dirs': True,
'make_parent_directories': True,
},
config={},
local_borg_version=None,
@@ -165,7 +165,7 @@ def test_run_repo_create_defaults_to_config():
object,
append_only=True,
storage_quota='10G',
make_parent_dirs=True,
make_parent_directories=True,
local_path=object,
remote_path=object,
).once()
@@ -176,7 +176,7 @@ def test_run_repo_create_defaults_to_config():
copy_crypt_key=flexmock(),
append_only=None,
storage_quota=None,
make_parent_dirs=None,
make_parent_directories=None,
)
module.run_repo_create(
@@ -184,7 +184,7 @@ def test_run_repo_create_defaults_to_config():
'path': 'repo',
'append_only': True,
'storage_quota': '10G',
'make_parent_dirs': True,
'make_parent_directories': True,
},
config={},
local_borg_version=None,
+26 -4
View File
@@ -228,7 +228,29 @@ def test_create_repository_with_append_only_calls_borg_with_append_only_flag():
module.create_repository(
dry_run=False,
repository_path='repo',
config={},
config={'append_only': True},
local_borg_version='2.3.4',
global_arguments=flexmock(log_json=False),
encryption_mode='repokey',
append_only=True,
)
def test_create_repository_with_append_only_config_calls_borg_with_append_only_flag():
insert_repo_info_command_not_found_mock()
insert_repo_create_command_mock(REPO_CREATE_COMMAND + ('--append-only', '--repo', 'repo'))
flexmock(module.feature).should_receive('available').and_return(True)
flexmock(module.flags).should_receive('make_repository_flags').and_return(
(
'--repo',
'repo',
)
)
module.create_repository(
dry_run=False,
repository_path='repo',
config={'append_only': True},
local_borg_version='2.3.4',
global_arguments=flexmock(log_json=False),
encryption_mode='repokey',
@@ -252,7 +274,7 @@ def test_create_repository_with_storage_quota_calls_borg_with_storage_quota_flag
module.create_repository(
dry_run=False,
repository_path='repo',
config={},
config={'storage_quota': '5G'},
local_borg_version='2.3.4',
global_arguments=flexmock(log_json=False),
encryption_mode='repokey',
@@ -274,11 +296,11 @@ def test_create_repository_with_make_parent_dirs_calls_borg_with_make_parent_dir
module.create_repository(
dry_run=False,
repository_path='repo',
config={},
config={'make_parent_directories': True},
local_borg_version='2.3.4',
global_arguments=flexmock(log_json=False),
encryption_mode='repokey',
make_parent_dirs=True,
make_parent_directories=True,
)