Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit a56a834

Browse files
authoredMar 23, 2025··
disable self-update for windows versions below 17763 (#177)
1 parent 3cd0cc0 commit a56a834

File tree

3 files changed

+38
-26
lines changed

3 files changed

+38
-26
lines changed
 

‎model/config.go

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import (
1313
"github.com/knadh/koanf/v2"
1414
"sigs.k8s.io/yaml"
1515

16+
"github.com/nezhahq/agent/pkg/logger"
1617
"github.com/nezhahq/agent/pkg/util"
1718
)
1819

@@ -76,10 +77,19 @@ func (c *AgentConfig) Read(path string) error {
7677
return err
7778
}
7879

80+
if !c.DisableAutoUpdate || !c.DisableForceUpdate {
81+
if util.IsBelow10() {
82+
c.DisableAutoUpdate = true
83+
c.DisableForceUpdate = true
84+
logger.Println("This version of Windows is no longer supported, disabling self-update now")
85+
defer saveOnce()
86+
}
87+
}
88+
7989
if c.UUID == "" {
8090
if uuid, err := uuid.GenerateUUID(); err == nil {
8191
c.UUID = uuid
82-
saveOnce()
92+
defer saveOnce()
8393
} else {
8494
return fmt.Errorf("generate UUID failed: %v", err)
8595
}

‎pkg/pty/pty_windows.go

Lines changed: 3 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -9,20 +9,19 @@ import (
99
"os"
1010
"os/exec"
1111
"path/filepath"
12-
"regexp"
1312
"runtime"
14-
"strconv"
1513

1614
"github.com/UserExistsError/conpty"
1715
"github.com/artdarek/go-unzip"
1816
"github.com/iamacarpet/go-winpty"
19-
"github.com/shirou/gopsutil/v4/host"
17+
18+
"github.com/nezhahq/agent/pkg/util"
2019
)
2120

2221
var _ IPty = (*winPTY)(nil)
2322
var _ IPty = (*conPty)(nil)
2423

25-
var isWin10 = VersionCheck()
24+
var isWin10 = !util.IsBelow10()
2625

2726
type winPTY struct {
2827
tty *winpty.WinPTY
@@ -32,27 +31,6 @@ type conPty struct {
3231
tty *conpty.ConPty
3332
}
3433

35-
func VersionCheck() bool {
36-
hi, err := host.Info()
37-
if err != nil {
38-
return false
39-
}
40-
41-
re := regexp.MustCompile(`Build (\d+(\.\d+)?)`)
42-
match := re.FindStringSubmatch(hi.KernelVersion)
43-
if len(match) > 1 {
44-
versionStr := match[1]
45-
46-
version, err := strconv.ParseFloat(versionStr, 64)
47-
if err != nil {
48-
return false
49-
}
50-
51-
return version >= 17763
52-
}
53-
return false
54-
}
55-
5634
func DownloadDependency() error {
5735
if isWin10 {
5836
return nil

‎pkg/util/util.go

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,13 @@ import (
66
"net"
77
"net/http"
88
"os"
9+
"regexp"
10+
"strconv"
911
"strings"
1012
"sync"
1113

1214
jsoniter "github.com/json-iterator/go"
15+
"github.com/shirou/gopsutil/v4/host"
1316
"github.com/shirou/gopsutil/v4/process"
1417
)
1518

@@ -147,3 +150,24 @@ func SubUintChecked[T Unsigned](a, b T) T {
147150
type Unsigned interface {
148151
~uint | ~uint8 | ~uint16 | ~uint32 | ~uint64
149152
}
153+
154+
func IsBelow10() bool {
155+
hi, err := host.Info()
156+
if err != nil {
157+
return true
158+
}
159+
160+
re := regexp.MustCompile(`Build (\d+(\.\d+)?)`)
161+
match := re.FindStringSubmatch(hi.KernelVersion)
162+
if len(match) > 1 {
163+
versionStr := match[1]
164+
165+
version, err := strconv.ParseFloat(versionStr, 64)
166+
if err != nil {
167+
return true
168+
}
169+
170+
return version < 17763
171+
}
172+
return true
173+
}

0 commit comments

Comments
 (0)
Please sign in to comment.