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

old exe not deleted on Windows #1

Open
bgentry opened this issue Sep 19, 2013 · 7 comments · Fixed by #3
Open

old exe not deleted on Windows #1

bgentry opened this issue Sep 19, 2013 · 7 comments · Fixed by #3

Comments

@bgentry
Copy link

bgentry commented Sep 19, 2013

I think you mentioned that this was still a problem for you. We've got the same problem in hk at the moment since we can't delete a running executable on Windows.

Just curious how you were planning on solving this one (and if this is the right place for it, or if you consider that ngrok's problem to solve).

@inconshreveable
Copy link
Owner

Thanks for opening this. I think it's definitely go-update's problem to solve, and I don't have a clean solution beyond simply running os.Remove(oldBinaryPath) and ignoring "file does not exist" errors before the update happens. This will clean it out on the next update run, which is sub-optimal but I can't think of a better solution. I'm open to suggestions though.

@bgentry
Copy link
Author

bgentry commented Sep 19, 2013

That was my first thought as well.

There are some really ugly ways that Windows devs accomplish this: http://www.catch22.net/tuts/self-deleting-executables

One other possibility might be to move the old executable to a temp or trash dir instead of moving it to the same dir.

That being said, unless you're running your exe from somewhere highly visible like the Desktop, it's unlikely that most users would notice / care if the old one was left around. I think the simple approach you mentioned is probably good enough for now.

@inconshreveable
Copy link
Owner

Wow, that's quite a list. I agree with you about the options, and I'll add one more suggestion. Windows has an API for making files hidden (via SetFileAttributes). Making the old executable a hidden file means it wouldn't show up somewhere noticeable and you could delete it at the time of next update.

@inconshreveable
Copy link
Owner

Alright, I just pushed a fix that makes sure the file it tries to rename to is always deleted before attempting the move. I'm leaving this issue open though because it would be nice to make the removal cleaner or at least less noticeable (via hidden file).

@inconshreveable
Copy link
Owner

Urgh, didn't want github to auto-close this. The hidden file mechanism is implemented now, which is a little less onerous, but I want to leave this open until such point as a real solution is implemented with one of the mechanisms described in the article.

@ericrange
Copy link

why cant you just name the "old" file like that: .prog-04-04-2018-13-56.old
so there is always a "new" old file and you dont have trouble with renaming and so on.

@ericrange
Copy link

i solved the problem with:

now := time.Now()
err = update.Apply(resp.Body, update.Options{
	OldSavePath: exPath + "/" + now.Format("20060102150405") + ".old"})

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 a pull request may close this issue.

3 participants