library: an rtk.exe in winget's folder that winget doesn't list is upgraded from rtk's release (netube99 on X)
RTK upgrade failed with "winget failed (exit code 0x8A150014): winget finds no rtk-ai.rtk package". rtkUpgrader took any rtk under a \WinGet\ folder for winget's and ran winget upgrade, though winget had no record of it. Now, when the exe sits inside winget's folders and winget says it did not install it (wingetDisowns: records elsewhere, or winget list exit 0x8A150014), the upgrader is the existing Windows-release action (zip checked against checksums.txt), applied to the file a WinGet\Links link points to. A link to an exe outside winget's folders (--location) and an rtk winget does list still go to winget; winget that can't answer is not taken over, as before. Run: wsl-run go test ./internal/library (full package, ok), go vet linux and GOOS=windows ok, gofmt clean. New TestRTKWingetFolderWithoutRecord is red on the old rtk_upgrader (stash-tested). On xiaomi-gpu (win-run) a real rtk 1.1.0 in a fake WinGet\Packages\rtk-ai.rtk_fake folder went to 1.2.0 through UpgradeRTK. Not tried: netube99's actual machine, so why winget lost its record is unknown; GUI (no page change).
This commit is contained in:
File diff suppressed because one or more lines are too long
@@ -350,6 +350,18 @@ func rtkUpgrader(bin string) []string {
|
||||
// winget's own folders: its package, or the link it puts in
|
||||
// WinGet\Links to one installed with --location (#1527)
|
||||
case rtkOnWindows && (strings.Contains(strings.ToLower(slash), "/winget/") || strings.Contains(strings.ToLower(filepath.ToSlash(bin)), "/winget/")):
|
||||
// winget says it has no rtk-ai.rtk installed (0x8A150014, netube99 on
|
||||
// X): the exe was put in its folder, or left there, by something
|
||||
// else, and winget upgrade would fail. rtk's own release is put over
|
||||
// it instead, over the file a WinGet\Links link points to.
|
||||
// A link in WinGet\Links to an exe outside winget's folders was made
|
||||
// by winget (--location, #1527); only the exe inside them is asked.
|
||||
if have("winget") && strings.Contains(strings.ToLower(slash), "/winget/") && wingetDisowns(bin, real) {
|
||||
if rtkArch == "amd64" {
|
||||
return []string{rtkWindowsRelease, real}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
if have("winget") {
|
||||
return wingetUp
|
||||
}
|
||||
@@ -753,7 +765,7 @@ func UpgradeRTK() (*RTKView, error) {
|
||||
if version == "" {
|
||||
return nil, fmt.Errorf("magpie can't tell which RTK release to install for %s — check the network and try again", bin)
|
||||
}
|
||||
if err := installRTKWindowsRelease(version, bin); err != nil {
|
||||
if err := installRTKWindowsRelease(version, c[1]); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
} else {
|
||||
|
||||
@@ -286,3 +286,50 @@ func TestRTKWindowsReleaseUpgradeRunsTheInstall(t *testing.T) {
|
||||
t.Fatalf("the rtk changed to %q", got)
|
||||
}
|
||||
}
|
||||
|
||||
// netube99 on X: an rtk.exe in winget's own folder (…\WinGet\Packages\
|
||||
// rtk-ai.rtk_…, or its link in WinGet\Links) that winget has no record of
|
||||
// got `winget upgrade`, which failed with 0x8A150014 "winget finds no
|
||||
// rtk-ai.rtk package". It is upgraded from rtk's own release now, over the
|
||||
// file the link points to; one winget does list still goes to winget.
|
||||
func TestRTKWingetFolderWithoutRecord(t *testing.T) {
|
||||
if runtime.GOOS == "windows" {
|
||||
t.Skip("the fakes are shell scripts")
|
||||
}
|
||||
h := sandbox(t)
|
||||
arch, base := rtkArch, rtkDownloadBase
|
||||
rtkArch = "amd64"
|
||||
t.Cleanup(func() { rtkArch, rtkDownloadBase = arch, base })
|
||||
latestServer(t, "v0.51.0")
|
||||
pkg := filepath.Join(h, "AppData", "Local", "Microsoft", "WinGet", "Packages", "rtk-ai.rtk_x")
|
||||
real := filepath.Join(pkg, "rtk")
|
||||
ver := filepath.Join(pkg, "VERSION")
|
||||
testenv.Program(t, real, strings.ReplaceAll(versionedRTK, "VERSION", ver))
|
||||
write(t, ver, "0.50.0")
|
||||
links := filepath.Join(h, "AppData", "Local", "Microsoft", "WinGet", "Links")
|
||||
os.MkdirAll(links, 0o755)
|
||||
link := filepath.Join(links, "rtk")
|
||||
if err := os.Symlink(real, link); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
t.Setenv("PATH", links+string(os.PathListSeparator)+filepath.Join(h, "tools"))
|
||||
newRTK := strings.ReplaceAll(versionedRTK, `"VERSION"`, `"`+ver+`"`)
|
||||
newRTK = strings.ReplaceAll(newRTK, "$(/bin/cat \""+ver+"\")", "0.51.0")
|
||||
rtkDownloadBase = fakeRTKRelease(t, newRTK, false)
|
||||
|
||||
// winget has records, none of them this folder
|
||||
wingetOn(t, h, wingetUnlisted, 0, func() ([]string, bool) { return []string{filepath.Join(h, "elsewhere")}, true })
|
||||
if c := rtkUpgrader(link); len(c) != 2 || c[0] != rtkWindowsRelease || c[1] != real {
|
||||
t.Fatalf("no record: upgrader %q; want %s %s", c, rtkWindowsRelease, real)
|
||||
}
|
||||
v, err := UpgradeRTK()
|
||||
if err != nil || v.Version != "0.51.0" {
|
||||
t.Fatalf("%+v, %v", v, err)
|
||||
}
|
||||
|
||||
// winget has it: winget upgrades it
|
||||
wingetOn(t, h, wingetListed, 0, func() ([]string, bool) { return []string{pkg}, true })
|
||||
if c := rtkUpgrader(link); len(c) == 0 || c[0] != "winget" {
|
||||
t.Fatalf("recorded: upgrader %q; want winget upgrade", c)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user