gopass icon indicating copy to clipboard operation
gopass copied to clipboard

Have a working updater on Windows

Open AnomalRoil opened this issue 2 years ago • 1 comments

We thought we had fixed it already, but as per the discussion in #1724 this is still not working.

There are 2 issues:

  1. We are still exiting the updater early on Windows because of this codepath: https://github.com/gopasspw/gopass/blob/b494532de7a887d29d1c9076838f5243f9a508ec/internal/action/update.go#L25-L27
  2. Once this is removed, the update still fails because: Failed to update gopass: unable to remove destination file: "remove C:\\dev\\gopass\\gopass.exe: Access is denied."

This doesn't seem related to the admin privilege as per #1724, but rather to the fact that an executable cannot replace itself while running on Windows. See also: https://stackoverflow.com/a/459860

This is close to the more complex solution proposed in this comment:

No, it's not an issue with privileges (I tested it), it's rather that the file to be removed is being executed and therefore locked. I made a self-updater (in c#) on windows like this:

Get new version of file x, save it under different name y
run y from x (which is then terminated), copy the file y to x
run x (the new version) and optionally/finally remove y
???
Absolute madness.

So the idea would be instead:

  1. Rename ourselves into gopass.exe.bak
  2. Download the new gopass.exe
  3. Check its integrity and signature, revert the name change from .bak in case of an error
  4. Exit
  5. Upon launch (either of gopass or of the update process) check for gopass.exe.bak and delete it if found, then go back to 1.

This will require some testing, but seems feasible.

AnomalRoil avatar Oct 14 '21 11:10 AnomalRoil

Thank you for pursuing this. The solution sounds good, except that "renaming" (i.e. moving) the running gopass exe won't work, but you can as well copy it, so this is just a terminology thing :) Added, the download and hence, replacement of the old gopass.exe will only work if the updater is actually executed from the gopass.exe.bak (that I'd rather call gopass.old.exe, so Windows still understands it's executable...weird OS actually)

I'll be happy to test and report my findings!

d-buchmann avatar Oct 20 '21 11:10 d-buchmann