func getCpByRelPath(full_path string, dal *release.Dal) *release.CpRelease { rel_path := full_path[constant.PATH_PREFIX_LEN:] cp, err := release.FindCpReleaseByPath(dal, rel_path) if err != nil { log.Printf("Find cp failed by [%s]: %s\n", rel_path, err) return nil } return cp }
func ProcessDir(info os.FileInfo, dal *release.Dal, path string, mode string, sim string, force bool) error { version := policy.ExtractVersion(info.Name()) if version == "" { //illegal version fmt, ignore return fmt.Errorf("Illegal version format : %s", info.Name()) } rel_path := fmt.Sprintf("%s/%s", path, info.Name())[constant.PATH_PREFIX_LEN:] cp, err := release.FindCpReleaseByPath(dal, rel_path) if err != nil { return err } if cp != nil { if !force { return fmt.Errorf("Existed CP release : %s", cp) } else { log.Printf("Existed CP release, delete arbi&grbi for force updating : %s", cp) release.DeleteArbiByCpId(dal, cp.Id) release.DeleteGrbiByCpId(dal, cp.Id) release.DeleteRficByCpId(dal, cp.Id) } } else { cp = &release.CpRelease{} cp.Mode = mode cp.Sim = sim cp.Version = version cp.VersionScalar = policy.QuantitateVersion(version) cp.LastModifyTs = time.Now().Unix() cp.Flag = constant.AVAILABLE_FLAG cp.RelPath = rel_path slice := strings.Split(rel_path, "/") cp.Prefix = strings.TrimSuffix(slice[2], version) log.Printf("Find new CP release : %s\n", cp) id, err := cp.Save(dal) if err != nil { cp.Id = -1 log.Printf("Save CP release failed: %s\n", err) } else { cp.Id = id log.Printf("Save CP release success: %d | %s\n", id, cp) } } //find detail information if cp.Id > 0 && FLAG_SCAN_DETAIL { ProcessDetail(cp, dal) } else { return fmt.Errorf("Neither finding or saving CP release success! in [%s]", info.Name()) } return nil }