Skip to content

Commit

Permalink
Fixes 3539: introspection fails if comps file not detected (#23)
Browse files Browse the repository at this point in the history
* Fixes 3539: introspection fails if comps file not detected

* use filetype instead of file extension
  • Loading branch information
xbhouse authored Feb 9, 2024
1 parent e205d78 commit cba215c
Showing 1 changed file with 18 additions and 8 deletions.
26 changes: 18 additions & 8 deletions pkg/yum/repository.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import (
"net/http"
"net/url"
"path"
"path/filepath"

"github.com/h2non/filetype"
"github.com/h2non/filetype/matchers"
Expand Down Expand Up @@ -344,7 +343,9 @@ func (r *Repository) getCompsURL() (*string, error) {
var compsLocation string

for _, data := range r.repomd.Data {
if data.Type == "group" {
if data.Type == "group_gz" {
compsLocation = data.Location.Href
} else if data.Type == "group" {
compsLocation = data.Location.Href
}
}
Expand Down Expand Up @@ -434,17 +435,26 @@ func ParseCompsXML(body io.ReadCloser, url *string) (Comps, error) {
return comps, fmt.Errorf("io.reader read failure: %w", err)
}

fileExtension := filepath.Ext(*url)
// determine the file type from the header
bufferedReader := bufio.NewReader(bytes.NewReader(byteValue))
header, err := bufferedReader.Peek(20)
if err != nil {
return comps, err
}
fileType, err := filetype.Match(header)
if err != nil {
return comps, err
}

// handle uncompressed comps
if fileExtension == ".xml" {
reader = bytes.NewReader(byteValue)
} else {
// handle compressed comps
// handle compressed comps
if fileType == matchers.TypeGz || fileType == matchers.TypeZstd || fileType == matchers.TypeXz {
reader, err = ParseCompressedData(bytes.NewReader(byteValue))
if err != nil {
return comps, err
}
// handle uncompressed comps
} else {
reader = bytes.NewReader(byteValue)
}

decoder := xml.NewDecoder(reader)
Expand Down

0 comments on commit cba215c

Please sign in to comment.