Ejemplo n.º 1
0
func CheckConsistency(dal *release.Dal, mode string) error {
	query := fmt.Sprintf("SELECT * FROM %s where mode='%s' and flag=%d", constant.TABLE_CP, mode, constant.AVAILABLE_FLAG)
	cp_list, err := release.FindCpReleaseList(dal, query)
	if err != nil {
		return err
	}

	for _, cp := range cp_list {
		full_path := fmt.Sprintf("%s%s", constant.CP_RELEASE_ROOT_FINAL, cp.RelPath)
		exist, err := pathutil.IsExist(full_path)
		if err != nil {
			continue
		}

		if !exist {
			log.Printf("CheckDir db and fs unmatched, delete db record: %s", cp)
			cp.Delete(dal)
			release.DeleteArbiByCpId(dal, cp.Id)
			release.DeleteGrbiByCpId(dal, cp.Id)
			release.DeleteRficByCpId(dal, cp.Id)
		} else {
			ProcessDetail(cp, dal)
		}
	}
	return nil
}
Ejemplo n.º 2
0
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
}
Ejemplo n.º 3
0
func ProcessModifyEvent(event *fsnotify.FileEvent) {
	log.Printf("Modify [%s]\n", event.Name)

	dal, err := release.NewDal()
	if err != nil {
		log.Printf("New DAL failed: %s\n", err)
		return
	}
	defer dal.Close()

	cp := getCpByRelPath(event.Name, dal)
	if cp != nil {
		if cp.Flag == constant.AVAILABLE_FLAG {
			log.Printf("CP release modified, delete arbi&grbi for updating in scanner : %s", cp)
			release.DeleteArbiByCpId(dal, cp.Id)
			release.DeleteGrbiByCpId(dal, cp.Id)
			release.DeleteRficByCpId(dal, cp.Id)
		}
	}
}
Ejemplo n.º 4
0
func ProcessDeleteEvent(event *fsnotify.FileEvent) {
	log.Printf("Delete [%s]\n", event.Name)

	dal, err := release.NewDal()
	if err != nil {
		log.Printf("New DAL failed: %s\n", err)
		return
	}
	defer dal.Close()

	cp := getCpByRelPath(event.Name, dal)
	if cp != nil {
		_, err := cp.Delete(dal)
		if err != nil {
			log.Printf("Delete failed: %s\n", err)
		} else {
			log.Printf("Delete success: %s\n", cp)
			log.Printf("CP release deleted, delete arbi&grbi together : %s", cp)
			release.DeleteArbiByCpId(dal, cp.Id)
			release.DeleteGrbiByCpId(dal, cp.Id)
		}
	}
}