// CheckFileHashes checks that the downloaded file content matches the hashes
// listed in the manifests
CheckFileHashes checks that the downloaded file content matches the hashes
listed in the manifests
// CheckFileHashes checks that the downloaded file content matches the hashes // listed in the manifests
func CheckFileHashes(r *diva.Results, c *config.Config, version, minVer uint) error {
	cLoc := filepath.Join(c.Paths.CacheLocation, "update")
	momPath := filepath.Join(cLoc, fmt.Sprint(version), "Manifest.MoM")
	MoM, err := swupd.ParseManifestFile(momPath)
	if err != nil {
		return err
	}
	var wg sync.WaitGroup
	nworkers := len(MoM.Files)
	wg.Add(nworkers)
	fChan := make(chan *swupd.File)
	errChan := make(chan error, nworkers)
	for i := 0; i < nworkers; i++ {
		go func() {
			defer wg.Done()
			for f := range fChan {
				if uint(f.Version) < minVer {
					continue
				}
				mPath := filepath.Join(cLoc, fmt.Sprint(f.Version), "Manifest."+f.Name)
				m, e := swupd.ParseManifestFile(mPath)
				if e != nil {
					errChan <- e
					break
				}
				failures, e := checkBundleFileHashes(c.Paths.CacheLocation, m, minVer)
				if e != nil {
					errChan <- e
					break
				}
				desc := fmt.Sprintf("file hashes for %s bundle match hashes in manifest", m.Name)
				r.Ok(len(failures) == 0, desc)
				if len(failures) > 0 {
					r.Diagnostic("mismatched hashes:\n" + strings.Join(failures, "\n"))
				}
			}
		}()
	}
	for i := range MoM.Files {
		fChan <- MoM.Files[i]
		select {
		case fChan <- MoM.Files[i]:
		case err = <-errChan:
			break
		}
	}
	close(fChan)
	wg.Wait()
	if err == nil && len(errChan) > 0 {
		err = <-errChan
	}
	chanLen := len(errChan)
	for i := 0; i < chanLen; i++ {
		<-errChan
	}
	return err
}
func CheckFileHashes ( r * diva . Results , c * config . Config , version , minVer uint ) error { cLoc := filepath . Join ( c . Paths . CacheLocation , " " ) momPath := filepath . Join ( cLoc , fmt . Sprint ( version ) , " " ) MoM , err := swupd . ParseManifestFile ( momPath ) if err != nil { return err } var wg sync . WaitGroup nworkers := len ( MoM . Files ) wg . Add ( nworkers ) fChan := make ( chan * swupd . File ) errChan := make ( chan error , nworkers ) for i := 0 ; i < nworkers ; i ++ { go func ( ) { defer wg . Done ( ) for f := range fChan { if uint ( f . Version ) < minVer { continue } mPath := filepath . Join ( cLoc , fmt . Sprint ( f . Version ) , " " + f . Name ) m , e := swupd . ParseManifestFile ( mPath ) if e != nil { errChan <- e break } failures , e := checkBundleFileHashes ( c . Paths . CacheLocation , m , minVer ) if e != nil { errChan <- e break } desc := fmt . Sprintf ( " " , m . Name ) r . Ok ( len ( failures ) == 0 , desc ) if len ( failures ) > 0 { r . Diagnostic ( " \n " + strings . Join ( failures , " \n " ) ) } } } ( ) } for i := range MoM . Files { fChan <- MoM . Files [ i ] select { case fChan <- MoM . Files [ i ] : case err = <- errChan : break } } close ( fChan ) wg . Wait ( ) if err == nil && len ( errChan ) > 0 { err = <- errChan } chanLen := len ( errChan ) for i := 0 ; i < chanLen ; i ++ { <- errChan } return err }
CheckFileHashes checks that the downloaded file content matches the hashes
listed in the manifests
CheckFileHashes checks that the downloaded file content matches the hashes listed in the manifests
// break on first failure