fix(SelfCheck): improve error message handling and update upgrade logic

This commit is contained in:
Jacky 2025-05-05 11:57:59 +00:00
parent 8bbb2ff559
commit 9f6f9088c4
No known key found for this signature in database
GPG key ID: 215C21B10DF38B4D
3 changed files with 12 additions and 7 deletions

View file

@ -3,7 +3,6 @@ package upgrader
import (
"os"
"code.pfad.fr/risefront"
"github.com/0xJacky/Nginx-UI/settings"
"github.com/gorilla/websocket"
"github.com/uozi-tech/cosy/logger"
@ -71,9 +70,8 @@ func BinaryUpgrade(ws *websocket.Conn, control *Control) {
Status: UpgradeStatusInfo,
Message: "Performing core upgrade",
})
// dry run
if control.DryRun || settings.NodeSettings.Demo {
risefront.Restart()
if settings.NodeSettings.Demo {
return
}

View file

@ -7,6 +7,7 @@ import (
"net/http"
"os"
"path/filepath"
"runtime"
"strconv"
"strings"
"sync/atomic"
@ -217,8 +218,10 @@ func (u *Upgrader) PerformCoreUpgrade(tarPath string) (err error) {
}
defer updateInProgress.Store(false)
oldExe := filepath.Join(filepath.Dir(u.ExPath), ".nginx-ui.old."+strconv.FormatInt(time.Now().Unix(), 10))
opts := selfupdate.Options{
OldSavePath: fmt.Sprintf(".nginx-ui.old.%d", time.Now().Unix()),
OldSavePath: oldExe,
}
if err = opts.CheckPermissions(); err != nil {
@ -269,6 +272,10 @@ func (u *Upgrader) PerformCoreUpgrade(tarPath string) (err error) {
return err
}
if runtime.GOOS != "windows" {
_ = os.Remove(oldExe)
}
// wait for the file to be written
time.Sleep(1 * time.Second)