(manifestLocation string, searchCriteria map[string]string, archiveLocation string)
| 414 | } |
| 415 | |
| 416 | func isManifestValid(manifestLocation string, searchCriteria map[string]string, archiveLocation string) map[string]string { |
| 417 | mtaArchiveReader, err := zip.OpenReader(archiveLocation) |
| 418 | if err != nil { |
| 419 | return map[string]string{} |
| 420 | } |
| 421 | defer mtaArchiveReader.Close() |
| 422 | searchCriteriaResult := make(map[string]string) |
| 423 | for _, file := range mtaArchiveReader.File { |
| 424 | if file.Name == manifestLocation { |
| 425 | reader, err := file.Open() |
| 426 | if err != nil { |
| 427 | return map[string]string{} |
| 428 | } |
| 429 | defer reader.Close() |
| 430 | manifestBytes, _ := io.ReadAll(reader) |
| 431 | manifestSplittedByNewLine := strings.Split(string(manifestBytes), "\n") |
| 432 | for _, manifestSectionElement := range manifestSplittedByNewLine { |
| 433 | if strings.Trim(manifestSectionElement, " ") == "" { |
| 434 | continue |
| 435 | } |
| 436 | separatorIndex := strings.Index(manifestSectionElement, ":") |
| 437 | key := manifestSectionElement[:separatorIndex] |
| 438 | value := manifestSectionElement[separatorIndex+1:] |
| 439 | if searchCriteria[key] != "" { |
| 440 | delete(searchCriteria, key) |
| 441 | searchCriteriaResult[key] = strings.Trim(value, " ") |
| 442 | } |
| 443 | } |
| 444 | break |
| 445 | } |
| 446 | } |
| 447 | return searchCriteriaResult |
| 448 | } |
| 449 | |
| 450 | func filepathUnixJoin(elements ...string) string { |
| 451 | return strings.Join(elements, "/") |
no test coverage detected