diff --git a/agent-go/a_executor/BaseFunction.go b/agent-go/a_executor/BaseFunction.go index f07504d..e8b61b9 100755 --- a/agent-go/a_executor/BaseFunction.go +++ b/agent-go/a_executor/BaseFunction.go @@ -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/*") diff --git a/agent-go/a_executor/BasicFunction.go b/agent-go/a_executor/BasicFunction.go index 08c3000..123372c 100755 --- a/agent-go/a_executor/BasicFunction.go +++ b/agent-go/a_executor/BasicFunction.go @@ -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 {