Exemple #1
0
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")
}
Exemple #2
0
func CopyFile(src, dest string) (int64, error) {
	DeleteFile(dest)
	fi, fi_err := os.Stat(src)
	if fi_err != nil {
		return 0, fi_err
	}
	srcFile, err := os.OpenFile(src, os.O_RDONLY, fi.Mode())
	if err != nil {
		return 0, err
	}
	defer srcFile.Close()

	if strings.HasSuffix(dest, pathutil.SLASH) {
		pathutil.MkDir(dest)
		dest += pathutil.BaseName(src)
	} else {
		DeleteFile(dest)
		parent_path := pathutil.ParentPath(dest)
		pathutil.MkDir(parent_path)
	}

	destFile, err := os.OpenFile(dest, os.O_CREATE|os.O_WRONLY, fi.Mode())
	if err != nil {
		return 0, err
	}
	defer destFile.Close()

	return io.Copy(destFile, srcFile)
}
Exemple #3
0
Fichier : misc.go Projet : jsli/ota
func RecordMd5(path, txt_path string) error {
	md5_str, err := file.Md5SumFile(path)
	if md5_str == "" || err != nil {
		return err
	} else {
		parent := pathutil.ParentPath(path)
		if parent == "" {
			return fmt.Errorf("record md5 failed: %s parent path is empty", path)
		}
		base_name := pathutil.BaseName(path)
		err := file.WriteString2File(fmt.Sprintf("%s %s", md5_str, base_name), txt_path)
		if err != nil {
			return err
		}
	}
	return nil
}
Exemple #4
0
func (cp *CpRelease) LoadSelfFromFileEvent(event *fsnotify.FileEvent) error {
	path := event.Name
	parent_path := pathutil.ParentPath(path)
	cp.Mode = constant.PATH_TO_MODE[parent_path[:len(parent_path)-1]]

	base_name := pathutil.BaseName(path)
	version := policy.ExtractVersion(base_name)
	if version == "" {
		return errors.New(fmt.Sprintf("Illegal version : %s", base_name))
	}
	cp.Version = version
	cp.VersionScalar = policy.QuantitateVersion(version)

	cp.Sim = constant.MODE_TO_SIM[cp.Mode]
	cp.LastModifyTs = time.Now().Unix()
	cp.Flag = constant.AVAILABLE_FLAG
	cp.RelPath = path[constant.PATH_PREFIX_LEN:]
	return nil
}