Пример #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
}
Пример #2
0
func doGetCpList(dal *release.Dal, query string) ([]*release.CpRelease, error) {
	cps, err := release.FindCpReleaseList(dal, query)
	if err != nil {
		return nil, err
	}

	return cps, nil
}
Пример #3
0
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
}
Пример #4
0
func CheckTimestamp(dal *release.Dal, mode string) error {
	query := fmt.Sprintf("SELECT * FROM %s where mode='%s' and flag=%d", constant.TABLE_CP, mode, constant.DISABLE_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)
		mTs, err := file.GetFileModifyTs(full_path)
		if err != nil {
			continue
		}
		nTs := time.Now().Unix()
		i := nTs - mTs
		fmt.Println(full_path, " ======================", i)
		if (nTs - mTs) > 5*1000000000 {
			cp.Flag = constant.AVAILABLE_FLAG
			cp.LastModifyTs = nTs
			cp.Update(dal)
		}
	}
	return nil
}