// buildFileListsURL parses upstream repomd.xml file to find the filelists
// file.  We cannot just look for the filelists file directly because a hash is
// part of the filename. The repomd.xml file lists this file name so we can
// construct the url using this value.
buildFileListsURL parses upstream repomd.xml file to find the filelists
file.  We cannot just look for the filelists file directly because a hash is
part of the filename. The repomd.xml file lists this file name so we can
construct the url using this value.
// buildFileListsURL parses upstream repomd . xml file to find the filelists // file . We cannot just look for the filelists file directly because a hash is // part of the filename . The repomd . xml file lists this file name so we can // construct the url using this value .
func buildFilelistsURL(repo *Repo, workingDir string, update bool) (string, error) {
	repomdFile := filepath.Join(workingDir, "repomd.xml")
	repomdURL := fmt.Sprintf("%s/repodata/repomd.xml", repo.URI)
	var err error
	if !update {
		_, err = os.Stat(repomdFile)
	}
	if err != nil || update {
		err = helpers.Download(repomdURL, repomdFile, update)
		if err != nil {
			return "", err
		}
	}
	type loc struct {
		Path string `xml:"href,attr"`
	}
	type data struct {
		Key      string `xml:"type,attr"`
		Location loc    `xml:"location"`
	}
	type repomd struct {
		XMLName xml.Name `xml:"repomd"`
		Data    []data   `xml:"data"`
	}
	d, err := ioutil.ReadFile(repomdFile)
	if err != nil {
		return "", err
	}
	v := new(repomd)
	err = xml.Unmarshal([]byte(d), v)
	if err != nil {
		return "", err
	}
	var path string
	for _, section := range v.Data {
		if section.Key == "filelists" {
			path = section.Location.Path
			break
		}
	}
	return fmt.Sprintf("%s/%s", repo.URI, path), nil
}
func buildFilelistsURL ( repo * Repo , workingDir string , update bool ) ( string , error ) { repomdFile := filepath . Join ( workingDir , " " ) repomdURL := fmt . Sprintf ( " " , repo . URI ) var err error if ! update { _ , err = os . Stat ( repomdFile ) } if err != nil || update { err = helpers . Download ( repomdURL , repomdFile , update ) if err != nil { return " " , err } } type loc struct { Path string `xml:"href,attr"` } type data struct { Key string `xml:"type,attr"` Location loc `xml:"location"` } type repomd struct { XMLName xml . Name `xml:"repomd"` Data [ ] data `xml:"data"` } d , err := ioutil . ReadFile ( repomdFile ) if err != nil { return " " , err } v := new ( repomd ) err = xml . Unmarshal ( [ ] byte ( d ) , v ) if err != nil { return " " , err } var path string for _ , section := range v . Data { if section . Key == " " { path = section . Location . Path break } } return fmt . Sprintf ( " " , repo . URI , path ) , nil }
buildFileListsURL parses upstream repomd.xml file to find the filelists
file.
buildFileListsURL parses upstream repomd . xml file to find the filelists file .
// download repomd.xml // <repomd> //   <data type="name"> //     <location href="url-extension"/> //   </data> //   ... //   </repomd>