-
Notifications
You must be signed in to change notification settings - Fork 363
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
Fix temporary file renaming #2242
Conversation
|
||
namespace mamba_fs | ||
{ | ||
// Like std::rename, but works across file systems |
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.
What does "across file systems" means here?
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.
Or did you mean that this is more like a move
?
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.
I think the issue is that sometimes tmp
is on a different filesystem partition and then the rename
doesn't work as one needs to copy the file. Maybe there is something builtin to do rename_or_move
?
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.
I'm aware of two ways to "move" files from path A to path B:
- Within the same file system, changing some inodes. Posix guarantees that this is atomic and that's what
std::rename
uses IIUC. - Creating a copy and removing the old file, this is what's implemented here as I didn't find a std implementation.
Are there other ways to move files?
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.
Other ways would be to get into platform-specific apis, so I think it's fine here. Although indeed the name is not clear to me and some clarification on when/why it should be used in the comments would help.
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.
Agreed, will add!
@@ -826,7 +826,16 @@ namespace mamba | |||
{ | |||
fs::u8path state_file = json_file; | |||
state_file.replace_extension(".state.json"); | |||
fs::rename(m_temp_file->path(), json_file); |
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.
hmm, now we don't have rename
at all? I think we should first try to do the rename, then the move. I'll update your PR.
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.
LGTM
Fixes #2239