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

Fix temporary file renaming #2242

Merged
merged 3 commits into from
Feb 2, 2023
Merged

Fix temporary file renaming #2242

merged 3 commits into from
Feb 2, 2023

Conversation

jonashaag
Copy link
Contributor

@jonashaag jonashaag commented Jan 22, 2023

Fixes #2239

@jonashaag jonashaag marked this pull request as ready for review January 22, 2023 16:15

namespace mamba_fs
{
// Like std::rename, but works across file systems
Copy link
Member

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?

Copy link
Member

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?

Copy link
Member

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?

Copy link
Contributor Author

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?

Copy link
Member

@Klaim Klaim Jan 25, 2023

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.

Copy link
Contributor Author

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);
Copy link
Member

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.

Copy link
Member

@Klaim Klaim left a comment

Choose a reason for hiding this comment

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

LGTM

@wolfv wolfv merged commit 2eafbbc into mamba-org:main Feb 2, 2023
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.

repodata_use_zst causes Invalid cross-device link error
3 participants