ERROR:
The process cannot access the file because it is being used by another process. (os error 32)
I'm creating a program in rust and I'm currently working on an 'auto updater'.
I'm trying to have the program write over itself if an update was found and then launch the newer version of itself before exiting memory (Permanently replaced by the newer version). Of course if there is not a newer version then it would continue to function as normal.
My current work around is by having the updater in a "launcher" that does the checks and updates before launching the program. This way it is able to write over the main program since its not currently open in memory. However, it would be a LOT nicer to only have one executable.
Some code:
// Installs the update - writing over the currently installed version.
fs::write(env::current_dir().unwrap().join("program.exe"), program).unwrap();
CodePudding user response:
A safer way to do this is to have your main app be a symlink to your executable rather than the executable itself. Then you download the new version to a parallel location, switch the link over to the new version, then delete the old version.