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
common: fix privatefile create. #9270
base: master
Are you sure you want to change the base?
common: fix privatefile create. #9270
Conversation
@0xFFFC0000 please also open against release branch |
src/common/util.cpp
Outdated
@@ -123,6 +123,14 @@ namespace tools | |||
|
|||
private_file private_file::create(std::string name) | |||
{ | |||
if (epee::file_io_utils::is_file_exist(name)) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This change seems structurally and semantically quite dubious:
- Create tends to be a one-way operation, very different from drop and recreate. If you want to support a "replace" operation, you'd be better off making a new function which wraps the existing and allow the caller here to optionally request O_EXCL.
- The existing usage of this function that I see in wallet_rpc_server seems well aware it doesn't remove the existing file; what caller does this help, or contract (documented in the comments or implied by usage) does it honor?
Relevant wallet_rpc_server code:
rpc_login_file = tools::private_file::create(temp);
if (!rpc_login_file.handle())
{
LOG_ERROR(tr("Failed to create file ") << temp << tr(". Check permissions or remove file"));
return false;
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for your comment @iamamyth
Few points:
- Apologies for the late reply, I have been extremely busy the past few weeks.
- I thought about your comment. And your criticism makes sense to me.
In the new push, I am addressing those issues you have raised.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good; thanks for spotting and fixing the bug.
When creating a private file we need to delete the file if exist.
2966d83
to
267e31f
Compare
When creating a private file we need to delete the file if exists.