From e74b2f9b8aceea70f87eb81a2ef515096d9ea5c7 Mon Sep 17 00:00:00 2001 From: simonzhangsz Date: Mon, 18 Sep 2023 16:22:11 +0800 Subject: [PATCH] d --- features/cm/software.go | 6 +----- lib/global/kits.go | 16 +++++++++++++++- 2 files changed, 16 insertions(+), 6 deletions(-) diff --git a/features/cm/software.go b/features/cm/software.go index 2518d889..7de7f212 100644 --- a/features/cm/software.go +++ b/features/cm/software.go @@ -674,11 +674,7 @@ func ActiveSoftwareToNF(w http.ResponseWriter, r *http.Request) { if !config.GetYamlConfig().OMC.TestMode { filePath := (*neVersion)[0]["file_path"] sshHost := fmt.Sprintf("%s@%s", config.GetYamlConfig().NE.User, neInfo.Ip) - fileType, err := global.IsRpmOrDebPackage(filePath) - if err != nil { - log.Error("Failed to JudgeRpmOrDebPackage:", err) - services.ResponseInternalServerError500ProcessError(w, err) - } + fileType := global.IsRpmOrDebPackage(filePath) if fileType == 1 { rpmCmd := fmt.Sprintf("sudo rpm -Uvh '%s'", filePath) cmd := exec.Command("ssh", sshHost, rpmCmd) diff --git a/lib/global/kits.go b/lib/global/kits.go index 7ed8b81d..b36da021 100644 --- a/lib/global/kits.go +++ b/lib/global/kits.go @@ -640,7 +640,7 @@ func isDebPackage(file *os.File) bool { return string(buffer) == string(magic) } -func IsRpmOrDebPackage(filePath string) (int, error) { +func CheckRpmOrDebPackage(filePath string) (int, error) { var fileType int = 0 file, err := os.Open(filePath) if err != nil { @@ -661,3 +661,17 @@ func IsRpmOrDebPackage(filePath string) (int, error) { return fileType, nil } + +func IsRpmOrDebPackage(filePath string) int { + var fileType int = 0 + + if strings.Contains(filePath, ".rpm") { + fileType = 1 + } else if strings.Contains(filePath, ".deb") { + fileType = 2 + } else { + fileType = 0 + } + + return fileType +}