Skip to content

Commit

Permalink
fix: Don't use replace-executable for WinGet installations
Browse files Browse the repository at this point in the history
  • Loading branch information
bradenhilton authored and twpayne committed Oct 7, 2023
1 parent 9d017bb commit 5c0140d
Show file tree
Hide file tree
Showing 3 changed files with 428 additions and 27 deletions.
25 changes: 3 additions & 22 deletions internal/cmd/upgradecmd.go
@@ -1,4 +1,4 @@
//go:build !noupgrade
//go:build !noupgrade && !windows

package cmd

Expand Down Expand Up @@ -331,15 +331,6 @@ func (c *Config) replaceExecutable(
var archiveFormat chezmoi.ArchiveFormat
var archiveName string
switch {
case runtime.GOOS == "windows":
archiveFormat = chezmoi.ArchiveFormatZip
archiveName = fmt.Sprintf(
"%s_%s_%s_%s.zip",
c.upgrade.repo,
releaseVersion,
runtime.GOOS,
runtime.GOARCH,
)
case runtime.GOOS == "linux" && runtime.GOARCH == "amd64":
archiveFormat = chezmoi.ArchiveFormatTarGz
var libc string
Expand Down Expand Up @@ -389,19 +380,15 @@ func (c *Config) replaceExecutable(
// Extract the executable from the archive.
var executableData []byte
walkArchiveFunc := func(name string, info fs.FileInfo, r io.Reader, linkname string) error {
switch {
case runtime.GOOS != "windows" && name == c.upgrade.repo:
fallthrough
case runtime.GOOS == "windows" && name == c.upgrade.repo+".exe":
if name == c.upgrade.repo {
var err error
executableData, err = io.ReadAll(r)
if err != nil {
return err
}
return fs.SkipAll
default:
return nil
}
return nil
}
if err = chezmoi.WalkArchive(archiveData, archiveFormat, walkArchiveFunc); err != nil {
return
Expand All @@ -411,12 +398,6 @@ func (c *Config) replaceExecutable(
return
}

// Replace the executable.
if runtime.GOOS == "windows" {
if err = c.baseSystem.Rename(executableFilenameAbsPath, executableFilenameAbsPath.Append(".old")); err != nil {
return
}
}
err = c.baseSystem.WriteFile(executableFilenameAbsPath, executableData, 0o755)

return
Expand Down

0 comments on commit 5c0140d

Please sign in to comment.