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

feature: Install binaries atomically #195

Merged
merged 7 commits into from
Jul 5, 2022
Merged

feature: Install binaries atomically #195

merged 7 commits into from
Jul 5, 2022

Conversation

NobodyXu
Copy link
Member

@NobodyXu NobodyXu commented Jun 23, 2022

This PR added a new function helpers::atomic_install and used it in bins::BinFile::install_bin.

helpers::atomic_install first attempts to use rename to atomically install the file.
When rename fails, it will switch to the fallback, which uses tempfile::NamedTempFile to create a named temporary file at the parent of dst, std::io::copy the src into the tempfile, then persist the named tempfile to dst atomically.

It also added a new function helpers::atomic_symlink_file and used it in bins::BinFile::install_link.

It creates a tempfile::TempPath, create a symlink with the TempPath as the linkname, then persist it to link.

Signed-off-by: Jiahao XU [email protected]

@NobodyXu NobodyXu marked this pull request as ready for review June 23, 2022 13:44
@passcod
Copy link
Member

passcod commented Jun 27, 2022

Not pulling this into release just yet.

As a side note, just to have it documented somewhere in the project, I've recently learned that symlinks on Windows only "work" when developer mode is enabled at an OS level, which explains the mysterious issue with them not working for one person earlier this year, but being fine in CI and when trying locally. Something to keep in mind when touching this...

@NobodyXu
Copy link
Member Author

I've recently learned that symlinks on Windows only "work" when developer mode is enabled at an OS level

Oh my god... Looks like it is better to disable symlink on windows by default and simply copy the binaries over.

@passcod passcod merged commit 7518993 into cargo-bins:main Jul 5, 2022
@NobodyXu NobodyXu deleted the feature/atomic-install branch July 5, 2022 10:00
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.

2 participants