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

Report if Realm::delete_files() actually deleted the Realm file #4771

Merged
merged 2 commits into from
Jul 28, 2021

Conversation

tgoyne
Copy link
Member

@tgoyne tgoyne commented Jun 18, 2021

Our objective-c API for removing files returns true if the Realm file was deleted, and sets an error out parameter if any errors occurred. This means that even if an exception is thrown when trying to delete one of the auxiliary files we still need to know if the main file was deleted, and that awkwardly requires an out parameter.

This also refactors things to eliminate the unordered_map of auxiliary files because none of the things using it actually needed a map, and consolidates the two places where we deleted all the files into one.

@tgoyne tgoyne self-assigned this Jun 18, 2021
@tgoyne tgoyne changed the title v1Tg/report if files were deleted Report if Realm::delete_files() actually deleted the Realm file Jun 18, 2021
util::File::try_remove(file_path); // Throws
}
}
void Realm::delete_files(const std::string& realm_file_path, bool* did_delete_realm)
Copy link
Member

Choose a reason for hiding this comment

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

Why do we need an out parameter vs just returning true/false? Is it because it'll be less obvious to a caller what the return value signifies?

Copy link
Member Author

Choose a reason for hiding this comment

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

The function can't return a value if it throws an exception, but the obj-c API does return a value even if it reports an error.

Copy link
Member

Choose a reason for hiding this comment

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

Ah, I understand - I guess I didn't think through the PR description, but it does make sense!

Base automatically changed from v11 to master July 2, 2021 11:45
@tgoyne tgoyne force-pushed the tg/report-if-files-were-deleted branch 2 times, most recently from 8a3f67d to f7ee79e Compare July 22, 2021 22:15
Our objective-c API for removing files returns true if the Realm file was
deleted, and sets an error out parameter if any errors occurred. This means
that even if an exception is thrown when trying to delete one of the auxiliary
files we still need to know if the main file was deleted, and that awkwardly
requires an out parameter.

This also refactors things to eliminate the unordered_map of auxiliary files
because none of the things using it actually needed a map, and consolidates the
two places where we deleted all the files into one.
@tgoyne tgoyne force-pushed the tg/report-if-files-were-deleted branch from f7ee79e to 427affa Compare July 27, 2021 19:14
@tgoyne tgoyne requested a review from ironage July 27, 2021 22:00
Copy link
Contributor

@ironage ironage left a comment

Choose a reason for hiding this comment

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

The code reads nicer with these changes too 👍

@tgoyne tgoyne merged commit e1a6e38 into master Jul 28, 2021
@tgoyne tgoyne deleted the tg/report-if-files-were-deleted branch July 28, 2021 15:49
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Mar 22, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants