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

feat: use self_replace to delete self #180

Merged
merged 1 commit into from
Sep 19, 2024
Merged

feat: use self_replace to delete self #180

merged 1 commit into from
Sep 19, 2024

Conversation

mistydemeo
Copy link
Contributor

This is an attempt at handling axodotdev/cargo-dist#1374 using the self-replace crate. We leave the existing Unix behaviour in place, since it's already safe, but it replaces the previous Windows version with a new one: the Windows EXE is given a specific temporary name and, if the upgrade succeeded, we then set a flag to ensure it's deleted once the process completes.

Appears to be working on Windows but needs more testing.

@mistydemeo mistydemeo force-pushed the self_replace branch 2 times, most recently from 8b83f83 to bb0154f Compare September 16, 2024 22:13
@mistydemeo
Copy link
Contributor Author

@mitsuhiko - I've given self_replace a try here; seems to be working well! Just to double check, I'm not doing something inappropriate here by manually giving it the selfdelete suffix, right?


Some((ourselves, old_path))
let mut new_filename = old_filename.as_os_str().to_os_string();
new_filename.push(OsStr::new(".__selfdelete__.exe"));
Copy link
Contributor

Choose a reason for hiding this comment

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

is this name special..?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, it's mentioned here in the docs: https://docs.rs/self-replace/1.5.0/self_replace/#implementation I'll add a comment.

@mistydemeo mistydemeo merged commit f4c688f into main Sep 19, 2024
13 checks passed
@mistydemeo mistydemeo deleted the self_replace branch September 19, 2024 21:34
@mitsuhiko
Copy link

mitsuhiko commented Sep 23, 2024

You can give it that suffix but it really should not matter. It will move it over to the right name anyways.

I did not check too much but if you are doing something somewhat dodgy that the crate does not directly support, I'm happy to add a better API :)

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.

3 participants