-
Notifications
You must be signed in to change notification settings - Fork 494
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
fix: Don't use replace-executable
for WinGet installations
#2757
Conversation
47833cd
to
693907b
Compare
This looks very reasonable. What are the remaining steps needed to make this ready to merge? |
At a minimum, I think we need to wait for go1.21 (expected August) for the necessary fix to be released. I'd also like to figure out a nicer way to test, as I was doing everything manually when writing the code. |
Some general thoughts on how this can be improved: WinGet has configurable root directories for portable apps, for both user and machine scopes:
These paths can be set in WinGet's
The absolute executable path reported by chezmoi is likely to be a symlink when installed via WinGet ( A more robust solution would employ an approach like this:
The current solution in this PR only really handles the default path(s), which is probably acceptable for a first pass. That said, one could run I think I'm right at my limit when it comes to Go, so if it gets any more complicated than this, I might not be able to work on it without some more learning. Footnotes
|
693907b
to
9ceccb2
Compare
784ec9a is my current snapshot. It's super rough and definitely needs more refinement, but the inability to test properly without go1.21 makes it rather tedious at the moment. |
Thanks very much for the updates. Happy to wait for Go 1.21 for this. |
Just FYI, if/when anyone feels like it, I'd absolutely welcome a review on the file unmarshalling, logic, flow, and error handling, as I'm not particularly well versed in these at the moment. I attempted to map it out as:
I'm reasonably confident that the command invocation works, or at least it did when I built go from source to test it a few months ago. I think treating WinGet errors as chezmoi errors should be fine for now. We can absolutely handle them in a follow up PR if needed. |
784ec9a
to
7cb7ee0
Compare
7cb7ee0
to
b7e9fdd
Compare
Preface: In my working copy I have split the Windows-specific upgrade behavior into I don't think this is possible. Firstly, this is just awful to test. I'm open to any ideas anyone might have to make it less painful. I created a build from my branch with version ❯ chezmoi upgrade
Found chezmoi [twpayne.chezmoi] Version 2.38.0
This application is licensed to you by its owner.
Microsoft is not responsible for, nor does it grant any licenses to, third-party packages.
Successfully verified installer hash
Extracting archive...
Successfully extracted archive
Starting package uninstall...
Unable to remove Portable package as it has been modified; to override this check use --force
chezmoi: exit status 0x8a150057 After learning this, I created two more chezmoi builds (as Here is ❯ chezmoi-local doctor
RESULT CHECK MESSAGE
ok version v2.37.100, commit 5682362fb54c388a58ee7af9384dd8f19983a355-dirty, built at 2023-08-23T12:49:15Z
warning latest-version v2.38.0
ok os-arch windows/amd64
ok systeminfo Microsoft Windows 10 Pro (10.0.19045 N/A Build 19045)
ok go-version go1.21.0 (gc)
ok executable ~/AppData/Local/Microsoft/WinGet/Links/chezmoi-local.exe
ok upgrade-method winget-upgrade
... And here is ❯ chezmoi-local upgrade
Found chezmoilocal [bradenhilton.chezmoilocal] Version 2.38.0
This application is licensed to you by its owner.
Microsoft is not responsible for, nor does it grant any licenses to, third-party packages.
Downloading https://<dropbox-url>
██████████████████████████████ 20.0 MB / 20.0 MB
Successfully verified installer hash
Extracting archive...
Successfully extracted archive
Starting package uninstall...
An unexpected error occurred while executing the command:
remove: unknown error: "~\AppData\Local\Microsoft\WinGet\Packages\bradenhilton.chezmoilocal__DefaultSource\chezmoi-local.exe"
Uninstall failed with exit code: 0x8a150003 : Executing command failed I'm not certain, but I believe this error is given because chezmoi is running at the time of upgrade/uninstall. |
acead27
to
ef07e2f
Compare
Thank you very much for working on this!
Previously I've worked around this by renaming (but not deleting) the current executable. See #1605 (comment). |
I don't know how to incorporate this into the upgrade flow for WinGet. I haven't checked yet, but I'm pretty sure |
Thanks again for all your work here. It might well be the case that this self-upgrade through winget functionality is simply not possible to achieve on Windows. Feel free to close this and #2736 if needed. |
I'm inclined to agree, but I still think we need to do something, as chezmoi currently thinks it can use Should I change I'm thinking the commit message can be changed to We could also consider releasing new Windows binaries specifically for use with package managers which are built with |
Yes, this sounds perfect.
Agreed that this would be excessive at the moment. |
ef07e2f
to
56c7b18
Compare
replace-executable
for WinGet installations
FYI, if we aren't invoking If we needed to invoke |
OK. We can go with this as the "official" versions of chezmoi are built with Go 1.21. Anyone building chezmoi with Go 1.20 will not need the upgrade command. I'll merge this now and just do a little tidy-up to reduce the code duplication between |
Fixes #2736
Very basic, not ready for merge yet.