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

Fails to rename on Windows #14

Closed
abourget opened this issue Jan 20, 2015 · 10 comments
Closed

Fails to rename on Windows #14

abourget opened this issue Jan 20, 2015 · 10 comments

Comments

@abourget
Copy link

I get this error:

rename C:\Users\PB\Desktop\bazooka.exe C:\Users\PB\Desktop\.bazooka.exe.old: The process cannot access the file because it is being used by another process.

which seems to be produced at this line: https://github.com/inconshreveable/go-update/blob/master/update.go#L374

The process is under Windows, running as administrator. Any clues ?

@abourget
Copy link
Author

This document: http://www.catch22.net/tuts/self-deleting-executables lists MoveFileEx as the solution to rename a running file, with the MOVEFILE_DELAY_UNTIL_REBOOT flag.. we're using os.Rename.. are we sure this is what is called underneath ?

@abourget
Copy link
Author

that MOVEFILE_DELAY_UNTIL_REBOOT isn't the solution.. as the file stays there until a reboot is performed.. we need to zap it out right away.

The only solution I see is to write a .bat file that will delete the executable, and rename the .new one, and restart the process.. and then kill the current process, after forking the cmd for the .bat file...

All that seems a bit hairy, but I don't understand how it works on your machines.. it seems to me that Windows can not delete or move or rename a running file.

@inconshreveable
Copy link
Owner

So, as far as i understand it, windows can't delete the executable file of a running process. Windows can rename the executable file of a running process. See: https://superuser.com/questions/488127/why-can-i-rename-a-running-executable-but-not-delete-it

go-update is cognizant of this. On nix systems, go-update deletes the old executable but on Windows we just hide it because of that problem.

If you're encountering an issue where go-update is failing to rename the running executable, it's very likely that your program (or another program) has an open file handle to the executable file.

@abourget
Copy link
Author

Right.. I think my process does indeed open itself because of go-rice... so I'll close this.. I'll find another way.

@inconshreveable
Copy link
Owner

ahhh, that makes a lot of sense. you might try the option where generate the source code files to be included in the binary instead of having them appended as a zipfile. it looks like go-rice supports that. for ngrok I use go-bindata which has been very effective

@abourget
Copy link
Author

I've got a PR over there to fix the issue. GeertJohan/go.rice#39

thanks :)

@inconshreveable
Copy link
Owner

awesome! thanks for tracking this down!

@abourget
Copy link
Author

yeah, go.rice supports http.Filesystem, so you can navigate through files and not have to list all the files up front (say you add a new .html file after), I recall go-bindata requires you to run some more stuff to pick up the new files..

@adamgoose
Copy link

@abourget I'm still experiencing this issue. As soon as I comment out any reference to go.rice, renaming the exe works fine. However, when I have go.rice in the app, I get the "in use" error.

My app is a CLI that has a single command to generate an example config file (from the rice box). I try to update inside of another command. It seems strange to me that rice opens the exe even when it's not being utilized.

I trust your PR fixed it back in 2015? Any ideas as to why it's no longer working?

@adamgoose
Copy link

I've ended up using https://github.com/mjibson/esc instead of rice.

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

No branches or pull requests

3 participants