Skip to content

Commit

Permalink
Correctly detect product name and product version number
Browse files Browse the repository at this point in the history
Signed-off-by: Ricardo Mateus <rmateus@suse.com>
  • Loading branch information
rjmateus committed May 15, 2023
1 parent 70ec0d6 commit ab53329
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 13 deletions.
2 changes: 2 additions & 0 deletions inter-server-sync.changes
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
* Correctly detect product name and product version number

-------------------------------------------------------------------
Wed Feb 8 10:41:54 UTC 2023 - Cédric Bosdonnat <cbosdonnat@suse.com>

Expand Down
27 changes: 14 additions & 13 deletions utils/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -107,8 +107,8 @@ func GetCurrentServerFQDN(serverConfig string) string {
}

func getProperty(filePaths []string, names []string) (string, error) {
for _, path := range filePaths {
for _, search := range names {
for _, search := range names {
for _, path := range filePaths {
p, err := ScannerFunc(path, search)
if err == nil {
return p, nil
Expand All @@ -119,24 +119,25 @@ func getProperty(filePaths []string, names []string) (string, error) {
}

func ScannerFunc(path string, search string) (string, error) {
var output string
f, err := os.Open(path)
if err != nil {
log.Fatal().Msgf("Couldn't open file: %s", path)
}
defer f.Close()
scanner := bufio.NewScanner(f)
for scanner.Scan() {
if strings.Contains(scanner.Text(), search) {
splits := strings.Split(scanner.Text(), "=")
output = splits[1]
if output == " SUSE Manager" {
output = strings.Replace(output, " SUSE Manager", "SUSE Manager", 1)
} else {
splits = strings.Split(output, " ")
output = splits[len(splits)-1]
}
return output, nil
linetext := scanner.Text()

index := strings.Index(linetext, "=")
if index < 0 {
continue
}

key := strings.Trim(linetext[:index], " ")
value := strings.Trim(linetext[index+1:], " ")

if key == search {
return value, nil
}
}
return "", fmt.Errorf("String not found!")
Expand Down

0 comments on commit ab53329

Please sign in to comment.