【agent-go】- 修改文件打开指令

This commit is contained in:
zeaslity
2024-11-17 11:46:19 +08:00
parent 98b0e14304
commit 724ef6424c
2 changed files with 12 additions and 20 deletions

View File

@@ -4,7 +4,9 @@ import (
"fmt"
"net"
"os"
"path/filepath"
"strings"
"wdd.io/agent-go/a_agent"
"wdd.io/agent-go/a_executor/beans"
)
@@ -962,7 +964,7 @@ func (op *AgentOsOperator) InstallDockerBastion() (bool, []string) {
BasicRemoveFolderComplete("/root/wdd/docker")
dockerLocalFile := OctopusAgentInstallPrefix + dockerOfflineFileName
dockerLocalFile := filepath.Join(OctopusAgentInstallPrefix, dockerOfflineFileName)
if !BasicFileExistAndNotNull(dockerLocalFile) {
sprintf := fmt.Sprintf("docker offline file not exists ! => %s", dockerLocalFile)
log.Error(sprintf)
@@ -974,7 +976,7 @@ func (op *AgentOsOperator) InstallDockerBastion() (bool, []string) {
"-vxf",
dockerLocalFile,
"-C",
"/root/wdd",
"/root/wdd/",
})
HardCodeCommandExecutor("chmod 777 -R /root/wdd/docker/*")

View File

@@ -5,7 +5,6 @@ import (
"bytes"
"errors"
"fmt"
"golang.org/x/net/proxy"
"io"
"net/http"
"net/url"
@@ -14,6 +13,8 @@ import (
"path/filepath"
"regexp"
"strings"
"golang.org/x/net/proxy"
)
var RemoveForcePrefix = []string{"rm", "-rf"}
@@ -422,26 +423,15 @@ func BasicFileExists(filename string) bool {
// BasicFileExistAndNotNull 文件不为空返回true 文件为空返回false
func BasicFileExistAndNotNull(filename string) bool {
// Check if the file exists
if _, err := os.Stat(filename); os.IsNotExist(err) {
log.DebugF("文件 %s 不存在!", filename)
// 获取文件信息
fileInfo, err := os.Stat(filename)
if err != nil {
// 如果文件不存在或其他错误,返回 false
return false
}
// Open the file for reading
file, err := os.Open(filename)
defer file.Close()
if err != nil {
log.DebugF("文件 %s 打开有误!", filename)
return false // Handle error according to your needs
}
// Get the file size
info, _ := file.Stat()
size := info.Size()
// Check if the file is not empty
return size > 0
// 检查文件大小是否大于零
return fileInfo.Size() > 0
}
func BasicFolderExists(folderName string) bool {