Skip to content

Conversation

@S0obi
Copy link
Contributor

@S0obi S0obi commented Oct 3, 2024

Contributing process

What type of PR is this? (check all applicable)

  • Feature

Description

This PR will actually support multiple exclude patterns for the restore operation. Before, only one exclude pattern can be provided, now, similarly to the rewrite API, multiple exclude patterns can be provided as a list.

Did you update the API documentation?

  • Yes

Have you added or updated tests?

  • Yes, I added unit tests

@S0obi S0obi force-pushed the feature/support-multiple-exclude-for-restore branch from 5aaa8d0 to ce74181 Compare October 3, 2024 18:42
Copy link
Owner

@mtlynch mtlynch left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for adding this and filling in the missing docs!

I just have a small note about protecting clients who depended on the old behavior.


if exclude:
cmd.extend(['--exclude', exclude])
for exclude_path in exclude:
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There's a bit of a dangerous gotcha here for clients that depended on the previous semantics.

Can we add a check here for if exclude is a string and then throw an Exception in that case?

Because otherwise, if a consuming app was calling restic.restore(exclude='/foo/bar'), we're going to turn it into --exclude / --exclude f --exclude o...

We could theoretically check if it's a string vs. a list and handle both, but I'd rather just fail hard on strings to reduce complexity.

Copy link
Contributor Author

@S0obi S0obi Oct 4, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch, I thought about it while writing this as I am actually using the lib in this configuration but was unsure about how to address it.

Your proposal is fair and I implemented it in a separated commit. Thanks !

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for those edits!

I made a few small changes:

  • I added a more specific error for this case, as I generally prefer module-level exceptions for things that are scoped to a particular module.
  • I got rid of the mock execute in the test, since it doesn't actually get called and I'd rather keep it simple.
  • I added back the test for a single exclude path using the new semantics

])

@mock.patch.object(restore.command_executor, 'execute')
def test_restore_specific_snapshot_id_and_exclude(self, mock_execute):
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Following from the other comment, can we leave this test's call as-is but change the assertion to be that it throws the right exception?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done, I am unsure about how to use mock_execute so I just set it to empty string (to avoid unused variable warning).

@S0obi S0obi requested a review from mtlynch October 4, 2024 21:19
@mtlynch mtlynch enabled auto-merge (squash) October 5, 2024 00:35
@mtlynch mtlynch merged commit 1e50920 into mtlynch:master Oct 5, 2024
@mtlynch
Copy link
Owner

mtlynch commented Oct 5, 2024

@S0obi - Thanks for adding this! This is now released in 1.2.0:

https://github.com/mtlynch/resticpy/releases/tag/1.2.0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants