Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Prevent data-loss on rename if writing new file fails #3581

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

Osndok
Copy link

@Osndok Osndok commented Dec 2, 2024

Description

As it currently stands, bruno relies upon itself holding data in memory during rename. If a write operation fails for any reason, we have a very good chance of losing user data. If we do the delete operation after the write, then we instead only risk duplication of data (if the unlink fails), which seems axiomatically correct.

Contribution Checklist:

  • The pull request only addresses one issue or adds one feature.
  • The pull request does not introduce any breaking changes
  • I have added screenshots or gifs to help explain the change if applicable.
  • I have read the contribution guidelines.
  • Create an issue and link to the pull request.

Note: Keeping the PR small and focused helps make it easier to review and merge. If you have multiple changes you want to make, please consider submitting them as separate pull requests.

Publishing to New Package Managers

Please see here for more information.

@Osndok
Copy link
Author

Osndok commented Dec 2, 2024

Related to #3454, #3274

@Pragadesh44-Bruno
Copy link
Collaborator

Hey @Osndok,

Thanks for raising a PR addressing this. I agree with your point that it is generally best to call unlink after a successful rewrite to minimize the risk of data loss.

However, the specific block you're referring to is written to handle a unique issue on Windows. Due to the file system's case insensitivity, filenames like Abc.bru and abc.bru are considered the same. In such cases, attempting a direct rename can fail or produce unexpected behavior. To address this, the implementation unlinks the file first, followed by writing the new file.

Additionally, there are scenarios where atomic renames cannot be performed, such as when dealing with case-insensitive file systems or cross-device operations. This implementation ensures compatibility with these edge cases.

@helloanoop
Copy link
Contributor

@Osndok

There are some edge cases we need to handle as Pragadesh mentioned. We are discussing internally this and will get back to you.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants