jaemk / self_update

Self updates for rust executables
MIT License
796 stars 69 forks source link

Fix issues updating Windows binaries on non-C: drives. #69

Closed t-mw closed 3 years ago

t-mw commented 3 years ago

Fixes https://github.com/jaemk/self_update/issues/67.

I'm not sure why TEMP is required on Windows, but it might've been to force the temp file to be cleaned up by the OS. The tempfile crate should have been doing this even outside the TEMP directory, but couldn't because the running executable was still referencing the temp file at the time that tempfile::TempDir was dropped. I've tested on Windows and this PR seems to fix those issues, and fs::rename(self.source, dest); still works when overwriting the file of the running executable.

jaemk commented 3 years ago

@t-mw after this change, running the example on my windows machine is giving me a permissions error

cargo run --example github --features "archive-tar archive-zip compression-flate2 compression-zip-deflate"

... snip ...

Do you want to continue? [Y/n] Y
Downloading...
[00:00:00] [========================================] 1.09MB/1.09MB (0s) Done
Extracting archive... Done
Replacing binary file... [ERROR] IoError: Access is denied. (os error 5)
error: process didn't exit successfully: target\debug\examples\github.exe (exit code: 1)

Any ideas?

jaemk commented 3 years ago

Looks like it's failing on the fs::rename(temp, dest)?; for some reason

jaemk commented 3 years ago

interestingly, it works if I revert only the first copy back to a rename

jaemk commented 3 years ago

seems like the removal of env::var_os("TEMP") was the real fix, so I'm going to revert rename->copy change before I do a release

t-mw commented 3 years ago

Sorry, I see the same error and thought I'd fixed it after testing with my own project. Reverting to rename is fine, but it prevents the temporary file from being cleaned up. I think TEMP was being used as a workaround, but that creates the issues with not being able to update on non-C: drives.

jaemk commented 3 years ago

released in 0.25.0

t-mw commented 3 years ago

Thanks. Not ideal that those temp folders build up on Windows now. Reading around it seems like the only way to avoid that is to delete them when the updated executable runs. I could work on that if that sounds ok.