Esempio n. 1
0
func (ci *CpImage) Validate() (err error) {
	if err := ValidateSim(ci.Sim); err != nil {
		return err
	}
	if err := ValidateNetwork(ci.Network); err != nil {
		return err
	}

	dal, err := release.NewDal()
	if err != nil {
		return fmt.Errorf("Validate dtim error")
	}
	defer dal.Close()

	var image interface{}
	switch ci.Id {
	case ota_constant.ID_ARBI, ota_constant.ID_ARB2:
		image, _ = release.FindArbiByPath(dal, ci.Path)
	case ota_constant.ID_GRBI, ota_constant.ID_GRB2:
		image, _ = release.FindGrbiByPath(dal, ci.Path)
	case ota_constant.ID_RFIC, ota_constant.ID_RFI2:
		image, _ = release.FindRficByPath(dal, ci.Path)
	}

	v := reflect.ValueOf(image)
	if v.IsNil() {
		return fmt.Errorf("Illegal image path in dtim: %s", ci.Path)
	}

	return nil
}
Esempio n. 2
0
File: provider.go Progetto: 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")
}
Esempio n. 3
0
func ProcessGrbi(cp *release.CpRelease, dal *release.Dal) error {
	grbi_list, err := policy.FindGrbi(cp.RelPath, cp.Mode)
	if err != nil {
		return err
	} else {
		for _, grbi_path := range grbi_list {
			grbi_rel_path := grbi_path[constant.PATH_PREFIX_LEN:]
			grbi, err := release.FindGrbiByPath(dal, grbi_rel_path)
			if err == nil && grbi != nil {
				log.Printf("Existed grbi : %s\n", grbi)
				//id unmatched, delete itself
				if grbi.CpId != cp.Id {
					log.Printf("Id unmatched cp[%d] <--> grbi[%d] : delete", cp.Id, grbi.CpId)
					grbi.Delete(dal)
				} else {
					continue
				}
			}
			grbi = &release.Grbi{}
			grbi.CpId = cp.Id
			grbi.Flag = constant.AVAILABLE_FLAG
			grbi.LastModifyTs = time.Now().Unix()
			grbi.RelPath = grbi_rel_path
			log.Printf("Found grbi in [%s] : %s\n", cp.RelPath, grbi)
			id, err := grbi.Save(dal)
			if err != nil {
				log.Printf("Save GRBI failed: %s\n", err)
			} else {
				log.Printf("Save GRBI success: %d | %s\n", id, grbi)
			}
		}
	}
	return nil
}