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 }
func getRficList(dal *release.Dal, cp *release.CpRelease, original_rfic string) ([]string, error) { rfic_list := make([]string, 0, 5) //0. replace version rfic_primary, err := ReplaceVersionInPath(original_rfic, cp.Version) if err == nil && rfic_primary != "" { rel_rfic, err := release.FindRficByPath(dal, rfic_primary) if err == nil && rel_rfic != nil { // fmt.Println("primary rfic ", rfic_primary, " exist") rfic_list = append(rfic_list, rfic_primary) return rfic_list, nil } else { // fmt.Println("primary rfic ", rfic_primary, " not exist") } } //1. search in db if !ota_constant.QUERY_MODE_STRICT { query := fmt.Sprintf("SELECT * FROM %s where cp_id=%d AND flag=%d", cp_constant.TABLE_RFIC, cp.Id, cp_constant.AVAILABLE_FLAG) rfics, err := release.FindRficList(dal, query) if err != nil { return nil, err } if len(rfics) == 0 { return nil, fmt.Errorf("Cannot find the right Image.") } for _, rfic := range rfics { rfic_list = append(rfic_list, rfic.RelPath) } } return rfic_list, nil }
func ProcessRfic(cp *release.CpRelease, dal *release.Dal) error { rfic_list, err := policy.FindRfic(cp.RelPath, cp.Mode) if err != nil { return err } else { for _, rfic_path := range rfic_list { rfic_rel_path := rfic_path[constant.PATH_PREFIX_LEN:] rfic, err := release.FindRficByPath(dal, rfic_rel_path) if err == nil && rfic != nil { log.Printf("Existed rfic : %s\n", rfic) //id unmatched, delete itself if rfic.CpId != cp.Id { log.Printf("Id unmatched cp[%d] <--> rfic[%d] : delete", cp.Id, rfic.CpId) rfic.Delete(dal) } else { continue } } rfic = &release.Rfic{} rfic.CpId = cp.Id rfic.Flag = constant.AVAILABLE_FLAG rfic.LastModifyTs = time.Now().Unix() rfic.RelPath = rfic_rel_path log.Printf("Found rfic in [%s] : %s\n", cp.RelPath, rfic) id, err := rfic.Save(dal) if err != nil { log.Printf("Save RFIC failed: %s\n", err) } else { log.Printf("Save RFIC success: %d | %s\n", id, rfic) } } } return nil }