當前位置: 首頁>>代碼示例>>Golang>>正文


Golang Dat.UnzipGames方法代碼示例

本文整理匯總了Golang中github.com/uwedeportivo/romba/types.Dat.UnzipGames方法的典型用法代碼示例。如果您正苦於以下問題:Golang Dat.UnzipGames方法的具體用法?Golang Dat.UnzipGames怎麽用?Golang Dat.UnzipGames使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在github.com/uwedeportivo/romba/types.Dat的用法示例。


在下文中一共展示了Dat.UnzipGames方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。

示例1: BuildDat

func (depot *Depot) BuildDat(dat *types.Dat, outpath string, numSubworkers int, deduper dedup.Deduper) (bool, error) {

	datPath := filepath.Join(outpath, dat.Name)

	err := os.Mkdir(datPath, 0777)
	if err != nil {
		return false, err
	}

	fixDat := new(types.Dat)
	fixDat.FixDat = true
	fixDat.Name = "fix_" + dat.Name
	fixDat.Description = dat.Description
	fixDat.Path = dat.Path
	fixDat.UnzipGames = dat.UnzipGames

	wc := make(chan *types.Game)
	erc := make(chan error)
	closeC := make(chan bool)
	mutex := new(sync.Mutex)

	for i := 0; i < numSubworkers; i++ {
		gb := new(gameBuilder)
		gb.depot = depot
		gb.wc = wc
		gb.erc = erc
		gb.mutex = mutex
		gb.datPath = datPath
		gb.fixDat = fixDat
		gb.index = i
		gb.deduper = deduper
		gb.closeC = closeC

		go gb.work()
	}

	var minionErr error

endLoop:
	for _, game := range dat.Games {
		select {
		case wc <- game:
		case err := <-erc:
			minionErr = err
			break endLoop
		}
	}
	close(wc)

	finishedSubworkers := 0

endLoop2:
	for {
		glog.V(4).Infof("builder master: finished so far %d", finishedSubworkers)

		select {
		case <-closeC:
			glog.V(4).Infof("builder master: finished another subworker")
			finishedSubworkers++
			if finishedSubworkers == numSubworkers {
				break endLoop2
			}
		case err := <-erc:
			glog.V(4).Infof("builder master: minion error")
			minionErr = err
		}
	}

	if minionErr != nil {
		return false, minionErr
	}

	if len(fixDat.Games) > 0 {
		fixDatPath := filepath.Join(outpath, fixPrefix+dat.Name+datSuffix)

		fixFile, err := os.Create(fixDatPath)
		if err != nil {
			return false, err
		}
		defer fixFile.Close()

		fixWriter := bufio.NewWriter(fixFile)
		defer fixWriter.Flush()

		err = types.ComposeCompliantDat(fixDat, fixWriter)
		if err != nil {
			return false, err
		}
	}

	return len(fixDat.Games) > 0, nil
}
開發者ID:uwedeportivo,項目名稱:romba,代碼行數:92,代碼來源:build.go


注:本文中的github.com/uwedeportivo/romba/types.Dat.UnzipGames方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。