示例#1
0
文件: main.go 项目: hako/afto
// updateRepo updates all the packages that exist in the current repo.
func (af *AftoRepo) updateRepo() {
	af.checkReqs()
	log.Println("updating repo: \"" + af.Name + "\"")
	path, err := afutil.GetRepo(af.Name)
	if err != nil {
		log.Fatalln(err)
	}

	// The debfile we are comparing to in -r <deb>
	inputDeb, err := afutil.ParseDeb(file)
	if err != nil {
		log.Fatalf(aftoUnexpectedError)
	}
	var newDeb, name, version, oldDeb = false, "", "", ""

	// The debfile we are comparing against <repo>
	for _, deb := range af.Debs {
		repodeb, err := afutil.ParseDeb(deb)
		if err != nil {
			log.Fatalf(aftoUnexpectedError)
		}
		if repodeb.Name() == inputDeb.Name() && repodeb.Version() != inputDeb.Version() {
			newDeb = true
			name = inputDeb.Name()
			version = inputDeb.Version()
			oldDeb = deb
		}
	}
	if newDeb != true {
		log.Println("No update is available.")
		os.Exit(0)
	}

	// Copy updated deb outside of folder.
	log.Println("Update is available for \"" + name + "\" version " + version)
	stripedRepo := strings.Replace(path, af.Name, "", -1)
	e := afutil.Copy(af.SingleDeb, stripedRepo+filepath.Base(af.SingleDeb))
	if err != nil {
		fmt.Println(e)
	}

	// Move other debs outside of folder, except old one. Delete that.
	currentDebs, _ := afutil.CheckDebWithPath(path)
	for _, c := range currentDebs {
		if filepath.Base(oldDeb) == c {
			continue
		}
		movedDeb := stripedRepo + filepath.Base(c)
		os.Rename(path+"/"+c, movedDeb)
	}

	// Delete and recreate repo. change command to update.
	os.RemoveAll(path)
	af.Cmd = "new"
	af.newRepo()
}
示例#2
0
文件: main.go 项目: hako/afto
// checkReqs checks for dpkg and deb files.
func (af *AftoRepo) checkReqs() {
	// Check for the dpkg command.
	err := afutil.CheckDPKG()
	if err != nil {
		log.Println(err)
		// Now check for compatible platform.
		message, err := afutil.DetectPlatform()
		if err != nil {
			log.Fatalln(err)
		}
		fmt.Println(message)
	}
	// Check for deb files. De(b)pending on the command given.
	log.Println("checking for deb files...")
	if af.Cmd == "new" {
		debs, err := afutil.CheckDeb()
		if err != nil {
			log.Fatalln(err)
		}
		log.Println(strconv.Itoa(len(debs)) + " deb file(s) found.")
		af.Debs = debs
	}
	if af.Cmd == "update" {
		// We must compare debfile with the repo debfile. (Needs refactoring.)
		if file != "" {

			deb, err := afutil.CheckDebWithFile(af.SingleDeb)
			if err != nil {
				log.Fatalln(err)
			}
			log.Println("deb file: \"" + filepath.Base(af.SingleDeb) + "\" found.")
			af.Debs = append(af.Debs, deb)
		}
		debs, err := afutil.CheckDebWithPath(af.Name)
		if err != nil {
			log.Fatalln(err)
		}
		log.Println(strconv.Itoa(len(debs)) + " deb file(s) found.")
		for _, d := range debs {
			af.Debs = append(af.Debs, af.Name+"/"+d)
		}
	}
}