Example #1
0
File: provider.go Project: jsli/ota
func getGrbiList(dal *release.Dal, cp *release.CpRelease, original_grbi string) ([]string, error) {
	//0. search in primary CP
	grbi_list, err := doGetGrbiList(dal, cp, original_grbi)
	if err == nil && grbi_list != nil && len(grbi_list) > 0 {
		return grbi_list, nil
	}

	query := fmt.Sprintf("SELECT * FROM %s where cp_id=%d AND flag=%d", cp_constant.TABLE_GRBI, cp.Id, cp_constant.AVAILABLE_FLAG)
	grbis, err := release.FindGrbiList(dal, query)
	if err == nil && grbis != nil && len(grbis) > 0 {
		for _, grbi := range grbis {
			grbi_list = append(grbi_list, grbi.RelPath)
		}
		if len(grbi_list) > 0 {
			return grbi_list, nil
		}
	}

	//1. search in lower CP by replacing version and comparing basename
	query = fmt.Sprintf("SELECT * FROM %s WHERE mode='%s' AND sim='%s' AND prefix='%s' AND version_scalar<%d  AND flag=%d ORDER BY version_scalar DESC",
		cp_constant.TABLE_CP, cp.Mode, cp.Sim, cp.Prefix, cp.VersionScalar, cp_constant.AVAILABLE_FLAG)
	cps, err := release.FindCpReleaseList(dal, query)
	if err != nil {
		return nil, err
	}
	for _, _cp := range cps {
		grbi_list, err := doGetGrbiList(dal, _cp, original_grbi)
		if err == nil && grbi_list != nil && len(grbi_list) > 0 {
			return grbi_list, nil
		}
	}

	//2. search any available msa in lower CP
	for _, _cp := range cps {
		query = fmt.Sprintf("SELECT * FROM %s where cp_id=%d AND flag=%d", cp_constant.TABLE_GRBI, _cp.Id, cp_constant.AVAILABLE_FLAG)
		grbis, err := release.FindGrbiList(dal, query)
		if err == nil && grbis != nil && len(grbis) > 0 {
			for _, grbi := range grbis {
				grbi_list = append(grbi_list, grbi.RelPath)
			}
			if len(grbi_list) > 0 {
				return grbi_list, nil
			}
		}
	}

	return nil, nil
}
Example #2
0
File: provider.go Project: jsli/ota
func doGetGrbiList(dal *release.Dal, cp *release.CpRelease, original_grbi string) ([]string, error) {
	grbi_list := make([]string, 0, 5)

	//0. replace version
	grbi_primary, err := ReplaceVersionInPath(original_grbi, cp.Version)
	if err == nil && grbi_primary != "" {
		rel_grbi, err := release.FindGrbiByPath(dal, grbi_primary)
		if err == nil && rel_grbi != nil {
			//			fmt.Println(" primary grbi ", grbi_primary, " exist")
			grbi_list = append(grbi_list, grbi_primary)
			return grbi_list, nil
		} else {
			//			fmt.Println(" primary grbi ", grbi_primary, " not exist")
		}
	}

	//1. searching by basename
	query := fmt.Sprintf("SELECT * FROM %s where cp_id=%d AND flag=%d", cp_constant.TABLE_GRBI, cp.Id, cp_constant.AVAILABLE_FLAG)
	grbis, err := release.FindGrbiList(dal, query)
	if err == nil && grbis != nil && len(grbis) > 0 {
		original_name := pathutil.BaseName(original_grbi)
		for _, grbi := range grbis {
			base_name := pathutil.BaseName(grbi.RelPath)
			if base_name == original_name {
				grbi_list = append(grbi_list, grbi.RelPath)
			}
		}
		if len(grbi_list) > 0 {
			return grbi_list, nil
		}
	}

	return nil, fmt.Errorf("Cannot find grbi")
}