Skip to content

Commit

Permalink
feat: windows agent update (#1036)
Browse files Browse the repository at this point in the history
  • Loading branch information
zzmark authored Aug 23, 2024
1 parent c7f919f commit 7d33cba
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion agent/update/update_windows.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ import (
"os"
"path/filepath"
"strings"

"golang.org/x/sys/windows"
)

func download(file string) (string, error) {
Expand Down Expand Up @@ -40,7 +42,6 @@ func download(file string) (string, error) {
}

func Update(tar string) error {
return fmt.Errorf("linux support only")
// download
fname, err := download(tar)
if err != nil {
Expand Down Expand Up @@ -69,6 +70,16 @@ func Update(tar string) error {
}
log.Printf("I! replace old version:%s with new version:%s", ov, "./"+nv)

// rename current -> current.old
oldBackup := ov + ".old"
err = os.Rename(ov, oldBackup)
if err != nil {
return err
}
err = windows.MoveFileEx(windows.StringToUTF16Ptr(oldBackup), nil, windows.MOVEFILE_DELAY_UNTIL_REBOOT) // optional: delay delete old file
if err != nil {
log.Printf("I! cannot auto remove old file for current user. please manual remove %s. cause: %v", oldBackup, err)
}
// replace
err = os.Rename(nv, ov)
if err != nil {
Expand Down

0 comments on commit 7d33cba

Please sign in to comment.