mirror of
				https://github.com/TeaOSLab/EdgeAPI.git
				synced 2025-11-04 07:50:25 +08:00 
			
		
		
		
	在升级API节点前检查版本号
This commit is contained in:
		@@ -1,6 +1,7 @@
 | 
			
		||||
package services
 | 
			
		||||
 | 
			
		||||
import (
 | 
			
		||||
	"bytes"
 | 
			
		||||
	"compress/gzip"
 | 
			
		||||
	"context"
 | 
			
		||||
	"crypto/md5"
 | 
			
		||||
@@ -11,6 +12,7 @@ import (
 | 
			
		||||
	rpcutils "github.com/TeaOSLab/EdgeAPI/internal/rpc/utils"
 | 
			
		||||
	"github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb"
 | 
			
		||||
	"github.com/iwind/TeaGo/dbs"
 | 
			
		||||
	stringutil "github.com/iwind/TeaGo/utils/string"
 | 
			
		||||
	"io"
 | 
			
		||||
	"os"
 | 
			
		||||
	"os/exec"
 | 
			
		||||
@@ -435,12 +437,19 @@ func (this *APINodeService) UploadAPINodeFile(ctx context.Context, req *pb.Uploa
 | 
			
		||||
		}
 | 
			
		||||
 | 
			
		||||
		// 检查文件是否可执行
 | 
			
		||||
		var testCmd = exec.Command(targetFile, "-V")
 | 
			
		||||
		err = testCmd.Run()
 | 
			
		||||
		var versionCmd = exec.Command(targetFile, "-V")
 | 
			
		||||
		var versionBuf = &bytes.Buffer{}
 | 
			
		||||
		versionCmd.Stdout = versionBuf
 | 
			
		||||
		err = versionCmd.Run()
 | 
			
		||||
		if err != nil {
 | 
			
		||||
			return nil, errors.New("test file failed: " + err.Error())
 | 
			
		||||
		}
 | 
			
		||||
 | 
			
		||||
		// 检查版本
 | 
			
		||||
		if stringutil.VersionCompare(versionCmd.String(), teaconst.Version) >= 0 {
 | 
			
		||||
			return &pb.UploadAPINodeFileResponse{}, nil
 | 
			
		||||
		}
 | 
			
		||||
 | 
			
		||||
		// 替换文件
 | 
			
		||||
		err = os.Remove(exe)
 | 
			
		||||
		if err != nil {
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user