// CheckDeltaPacks checks the delta packs for the m bundle to validate that all
// necessary files are present. Full files are verified to have the correct
// hash and delta files are verified to apply correctly with the correct
// result.
CheckDeltaPacks checks the delta packs for the m bundle to validate that all
necessary files are present. Full files are verified to have the correct
hash and delta files are verified to apply correctly with the correct
result.
// CheckDeltaPacks checks the delta packs for the m bundle to validate that all // necessary files are present . Full files are verified to have the correct // hash and delta files are verified to apply correctly with the correct // result .
func CheckDeltaPacks(c *config.Config, m *swupd.Manifest) ([]string, error) {
	vers := make(map[uint32]struct{})
	var exists = struct{}{}
	for _, f := range m.Files {
		vers[f.Version] = exists
	}
	var wg sync.WaitGroup
	workers := len(vers)
	wg.Add(workers)
	vCh := make(chan uint32)
	errCh := make(chan error, workers)
	failCh := make(chan string, workers)
	for i := 0; i < workers; i++ {
		go func() {
			defer wg.Done()
			for v := range vCh {
				tmpDir, err := ioutil.TempDir("", fmt.Sprintf("check-delta-pack-%s-%d-", m.Name, v))
				if err != nil {
					errCh <- err
					break
				}
				defer func() {
					_ = os.RemoveAll(tmpDir)
				}()
				url := fmt.Sprintf("%s/update/%d/pack-%s-from-%d.tar", c.UpstreamURL, m.Header.Version, m.Name, v)
				err = helpers.TarExtractURL(url, filepath.Join(tmpDir, fmt.Sprint(v)))
				if err != nil {
					_ = os.RemoveAll(tmpDir)
					continue
				}
				err = checkDeltaPack(c, tmpDir, m)
				if err != nil {
					failCh <- err.Error()
					break
				}
			}
		}()
	}
	var err error
	for v := range vers {
		select {
		case vCh <- v:
		case err = <-errCh:
			break
		}
	}
	close(vCh)
	wg.Wait()
	if err == nil && len(errCh) > 0 {
		err = <-errCh
	}
	chanLen := len(errCh)
	for i := 0; i < chanLen; i++ {
		<-errCh
	}
	var fails []string
	chanLen = len(failCh)
	for i := 0; i < chanLen; i++ {
		fails = append(fails, <-failCh)
	}
	return fails, err
}
func CheckDeltaPacks ( c * config . Config , m * swupd . Manifest ) ( [ ] string , error ) { vers := make ( map [ uint32 ] struct { } ) var exists = struct { } { } for _ , f := range m . Files { vers [ f . Version ] = exists } var wg sync . WaitGroup workers := len ( vers ) wg . Add ( workers ) vCh := make ( chan uint32 ) errCh := make ( chan error , workers ) failCh := make ( chan string , workers ) for i := 0 ; i < workers ; i ++ { go func ( ) { defer wg . Done ( ) for v := range vCh { tmpDir , err := ioutil . TempDir ( " " , fmt . Sprintf ( " " , m . Name , v ) ) if err != nil { errCh <- err break } defer func ( ) { _ = os . RemoveAll ( tmpDir ) } ( ) url := fmt . Sprintf ( " " , c . UpstreamURL , m . Header . Version , m . Name , v ) err = helpers . TarExtractURL ( url , filepath . Join ( tmpDir , fmt . Sprint ( v ) ) ) if err != nil { _ = os . RemoveAll ( tmpDir ) continue } err = checkDeltaPack ( c , tmpDir , m ) if err != nil { failCh <- err . Error ( ) break } } } ( ) } var err error for v := range vers { select { case vCh <- v : case err = <- errCh : break } } close ( vCh ) wg . Wait ( ) if err == nil && len ( errCh ) > 0 { err = <- errCh } chanLen := len ( errCh ) for i := 0 ; i < chanLen ; i ++ { <- errCh } var fails [ ] string chanLen = len ( failCh ) for i := 0 ; i < chanLen ; i ++ { fails = append ( fails , <- failCh ) } return fails , err }
CheckDeltaPacks checks the delta packs for the m bundle to validate that all
necessary files are present.
CheckDeltaPacks checks the delta packs for the m bundle to validate that all necessary files are present .
// assume no delta pack // break on first failure