Skip to content

fix: prevent overwriting hot repository on init#353

Merged
simonsan merged 2 commits intorustic-rs:mainfrom
gilbsgilbs:fix-hot-repo-overwrite
Nov 18, 2024
Merged

fix: prevent overwriting hot repository on init#353
simonsan merged 2 commits intorustic-rs:mainfrom
gilbsgilbs:fix-hot-repo-overwrite

Conversation

@gilbsgilbs
Copy link
Copy Markdown
Contributor

This commit ensures that the hot repository won't get overwritten during init when the non-hot repository does not exist.


Motivation: During my setup of rustic, I used a bad cold repository reference by mistake. This led rustic to corrupt my hot repository, which I thought it should have prevented. I guess there may be other places we'd want to detect and safeguard against hot/cold inconsistencies, but I've not encountered them and I'm not proficient enough with the codebase yet to go with a broader change confidently.

Old behavior:

$ --repo ./cold --repo-hot ./hot --password 'rustic' init
[INFO] using no config file, none of these exist: /home/myself/.config/rustic/rustic.toml, /etc/rustic/rustic.toml, ./rustic.toml
[INFO] key 70fde4b5 successfully added.
[INFO] repository 7e37c018 successfully created.
[INFO] using cache at /home/myself/.cache/rustic/7e37c0182ecf9122ac29094aba7a2456e2f4fcd8901de5548ba8d1f2cfbf424e

$ sha256sum hot/config
af78a9385084d3734fe4bba280449266c0a151ab6390baf6b684122e09f76c2a  hot/config

$ rustic --repo ./cold2 --repo-hot ./hot --password 'rustic' init
[INFO] using no config file, none of these exist: /home/myself/.config/rustic/rustic.toml, /etc/rustic/rustic.toml, ./rustic.toml
[INFO] key 7455ca1b successfully added.
[INFO] repository f6b5c80d successfully created.
[INFO] using cache at /home/myself/.cache/rustic/f6b5c80d9aea1e279cb76f7f3855d563f277fa43884300738fe957a8051c54ff

$ sha256sum hot/config
28a41dfbc7653c4f2aea443a94bfc5a665d120969bd38ccf663f6f1da505d7a0  hot/config

New behavior:

$ rustic --repo ./cold --repo-hot ./hot --password 'rustic' init
[INFO] using no config file, none of these exist: /home/myself/.config/rustic/rustic.toml, /etc/rustic/rustic.toml, ./rustic.toml
[INFO] key 60190cbb successfully added.
[INFO] repository e5ce7241 successfully created.
[INFO] using cache at /home/myself/.cache/rustic/e5ce7241a24254e7719865d60db0f0a939a5cdc21e1be9176856e5d385d70dfc

$ rustic --repo ./cold2 --repo-hot ./hot --password 'rustic' init
[INFO] using no config file, none of these exist: /home/myself/.config/rustic/rustic.toml, /etc/rustic/rustic.toml, ./rustic.toml
error: Config file already exists. Aborting.

Copy link
Copy Markdown
Contributor

@nardoor nardoor left a comment

Choose a reason for hiding this comment

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

Hello @gilbsgilbs ,

Thanks for using rustic and even more for taking the time to contribute.

Overall the changes look good to me.
But I'd like at least one of @simonsan and @aawsome to comment on this as well as they know this code better.

My only "change request" would be on code-documentation

@gilbsgilbs gilbsgilbs force-pushed the fix-hot-repo-overwrite branch from 846b6aa to 6bbb7a4 Compare November 17, 2024 08:29
@aawsome
Copy link
Copy Markdown
Member

aawsome commented Nov 17, 2024

@gilbsgilbs Thanks a lot for the PR - IMO this error case should be caught by rustic_core.
Only thing is we just merged a new error handling in #321. Can you try to adapt the error handling? We can also help you if you run into problems or have questions with that new error handling.

@gilbsgilbs gilbsgilbs force-pushed the fix-hot-repo-overwrite branch from 6bbb7a4 to 5a8ebaf Compare November 17, 2024 10:52
Copy link
Copy Markdown
Contributor

@simonsan simonsan left a comment

Choose a reason for hiding this comment

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

From a first look

This commit ensures that the hot repository won't get overwritten during
init when the non-hot repository does not exist.
@gilbsgilbs gilbsgilbs force-pushed the fix-hot-repo-overwrite branch from 5a8ebaf to 7be5fc8 Compare November 17, 2024 14:01
@simonsan simonsan added this pull request to the merge queue Nov 17, 2024
Merged via the queue into rustic-rs:main with commit c6741d8 Nov 18, 2024
@rustic-release-plz rustic-release-plz bot mentioned this pull request Nov 18, 2024
simonsan pushed a commit that referenced this pull request Nov 18, 2024
## 🤖 New release
* `rustic_backend`: 0.4.2 -> 0.5.0 (⚠️ API breaking changes)
* `rustic_core`: 0.5.5 -> 0.6.0 (⚠️ API breaking changes)
* `rustic_testing`: 0.2.3 -> 0.3.0 (✓ API compatible changes)

### ⚠️ `rustic_backend` breaking changes

```
--- failure enum_missing: pub enum removed or renamed ---

Description:
A publicly-visible enum cannot be imported by its prior path. A `pub use` may have been removed, or the enum itself may have been renamed or removed entirely.
        ref: https://doc.rust-lang.org/cargo/reference/semver.html#item-remove
       impl: https://github.com/obi1kenobi/cargo-semver-checks/tree/v0.36.0/src/lints/enum_missing.ron

Failed in:
  enum rustic_backend::error::LocalBackendErrorKind, previously in file /tmp/.tmp0sSY8G/rustic_backend/src/error.rs:90
  enum rustic_backend::error::RestErrorKind, previously in file /tmp/.tmp0sSY8G/rustic_backend/src/error.rs:67
  enum rustic_backend::error::BackendAccessErrorKind, previously in file /tmp/.tmp0sSY8G/rustic_backend/src/error.rs:10
  enum rustic_backend::error::RcloneErrorKind, previously in file /tmp/.tmp0sSY8G/rustic_backend/src/error.rs:43

--- failure module_missing: pub module removed or renamed ---

Description:
A publicly-visible module cannot be imported by its prior path. A `pub use` may have been removed, or the module may have been renamed, removed, or made non-public.
        ref: https://doc.rust-lang.org/cargo/reference/semver.html#item-remove
       impl: https://github.com/obi1kenobi/cargo-semver-checks/tree/v0.36.0/src/lints/module_missing.ron

Failed in:
  mod rustic_backend::error, previously in file /tmp/.tmp0sSY8G/rustic_backend/src/error.rs:1
```

### ⚠️ `rustic_core` breaking changes

```
--- failure inherent_method_missing: pub method removed or renamed ---

Description:
A publicly-visible method or associated fn is no longer available under its prior name. It may have been renamed or removed entirely.
        ref: https://doc.rust-lang.org/cargo/reference/semver.html#item-remove
       impl: https://github.com/obi1kenobi/cargo-semver-checks/tree/v0.36.0/src/lints/inherent_method_missing.ron

Failed in:
  LocalDestination::remove_dir, previously in file /tmp/.tmp0sSY8G/rustic_core/src/backend/local_destination.rs:129
  LocalDestination::remove_file, previously in file /tmp/.tmp0sSY8G/rustic_core/src/backend/local_destination.rs:152
  LocalDestination::create_dir, previously in file /tmp/.tmp0sSY8G/rustic_core/src/backend/local_destination.rs:171
  LocalDestination::set_times, previously in file /tmp/.tmp0sSY8G/rustic_core/src/backend/local_destination.rs:189
  LocalDestination::set_user_group, previously in file /tmp/.tmp0sSY8G/rustic_core/src/backend/local_destination.rs:237
  LocalDestination::set_uid_gid, previously in file /tmp/.tmp0sSY8G/rustic_core/src/backend/local_destination.rs:283
  LocalDestination::set_permission, previously in file /tmp/.tmp0sSY8G/rustic_core/src/backend/local_destination.rs:324
  LocalDestination::set_extended_attributes, previously in file /tmp/.tmp0sSY8G/rustic_core/src/backend/local_destination.rs:385
  LocalDestination::set_length, previously in file /tmp/.tmp0sSY8G/rustic_core/src/backend/local_destination.rs:466
  LocalDestination::create_special, previously in file /tmp/.tmp0sSY8G/rustic_core/src/backend/local_destination.rs:521
  LocalDestination::read_at, previously in file /tmp/.tmp0sSY8G/rustic_core/src/backend/local_destination.rs:599
  LocalDestination::write_at, previously in file /tmp/.tmp0sSY8G/rustic_core/src/backend/local_destination.rs:663
  RusticError::into_inner, previously in file /tmp/.tmp0sSY8G/rustic_core/src/error.rs:46
  RusticError::backend_error, previously in file /tmp/.tmp0sSY8G/rustic_core/src/error.rs:61
```

<details><summary><i><b>Changelog</b></i></summary><p>

## `rustic_backend`
<blockquote>

##
[0.5.0](rustic_backend-v0.4.2...rustic_backend-v0.5.0)
- 2024-11-18

### Added

- *(async)* add `async_compatible` methods to identify backend
compatibility
([#355](#355))
- add 'yandex-disk' to enabled opendal services and update opendal to
0.50.2 ([#360](#360))

### Other

- *(error)* enhance error logging and output formatting
([#361](#361))
- *(backend)* simplify code in local backend
([#362](#362))
- *(backend)* migrate from `backoff` to `backon`
([#356](#356))
- *(error)* improve error messages and file handling
([#334](#334))
- *(deps)* lock file maintenance rust dependencies
([#345](#345))
- *(deps)* [**breaking**] upgrade to new conflate version
([#300](#300))
- *(errors)* [**breaking**] Improve error handling, display and clean up
codebase ([#321](#321))
</blockquote>

## `rustic_core`
<blockquote>

##
[0.6.0](rustic_core-v0.5.5...rustic_core-v0.6.0)
- 2024-11-18

### Added

- *(async)* add `async_compatible` methods to identify backend
compatibility
([#355](#355))

### Fixed

- prevent overwriting hot repository on init
([#353](#353))

### Other

- *(error)* enhance error logging and output formatting
([#361](#361))
- *(deps)* remove Derivative and replace with Default impl due to
RUSTSEC-2024-0388
([#359](#359))
- *(error)* improve error messages and file handling
([#334](#334))
- *(deps)* lock file maintenance rust dependencies
([#345](#345))
- *(deps)* remove cdc and switch to rustic_cdc
([#348](#348))
- *(deps)* [**breaking**] upgrade to new conflate version
([#300](#300))
- *(errors)* [**breaking**] Improve error handling, display and clean up
codebase ([#321](#321))
</blockquote>

## `rustic_testing`
<blockquote>

##
[0.3.0](rustic_testing-v0.2.3...rustic_testing-v0.3.0)
- 2024-11-18

### Added

- *(async)* add `async_compatible` methods to identify backend
compatibility
([#355](#355))

### Other

- *(errors)* [**breaking**] Improve error handling, display and clean up
codebase ([#321](#321))
</blockquote>


</p></details>

---
This PR was generated with
[release-plz](https://github.com/MarcoIeni/release-plz/).

Co-authored-by: rustic-release-plz[bot] <182542030+rustic-release-plz[bot]@users.noreply.github.com>
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.

4 participants