コード例 #1
0
ファイル: merge.go プロジェクト: uwedeportivo/romba
func (w *mergeWorker) mergeGzip(path string, size int64) error {
	rom, err := RomFromGZDepotFile(path)
	if err != nil {
		return err
	}

	sha1Hex := hex.EncodeToString(rom.Sha1)
	exists, _, err := w.pm.depot.RomInDepot(sha1Hex)
	if err != nil {
		return err
	}

	if exists {
		return nil
	}

	hh, rSize, err := HashesFromGZHeader(path, w.md5crcBuffer)
	if err != nil {
		return err
	}

	rom.Md5 = hh.Md5
	rom.Crc = hh.Crc

	rom.Size = rSize
	rom.Path = path

	if w.pm.onlyneeded {
		dats, err := w.depot.romDB.DatsForRom(rom)
		if err != nil {
			return err
		}

		if len(dats) == 0 {
			return nil
		}
	}

	err = w.depot.romDB.IndexRom(rom)
	if err != nil {
		return err
	}

	root, err := w.depot.reserveRoot(size)
	if err != nil {
		return err
	}

	outpath := pathFromSha1HexEncoding(w.depot.roots[root], sha1Hex, gzipSuffix)

	err = worker.Cp(path, outpath)
	if err != nil {
		return err
	}

	w.depot.adjustSize(root, size)
	return nil
}
コード例 #2
0
ファイル: lookup.go プロジェクト: uwedeportivo/romba
func (rs *RombaService) lookupRom(cmd *commander.Command, r *types.Rom, outpath string) error {
	err := rs.romDB.CompleteRom(r)
	if err != nil {
		return err
	}

	if r.Sha1 != nil {
		sha1Str := hex.EncodeToString(r.Sha1)

		inDepot, hh, rompath, size, err := rs.depot.SHA1InDepot(sha1Str)
		if err != nil {
			return err
		}

		if inDepot {
			fmt.Fprintf(cmd.Stdout, "-----------------\n")
			fmt.Fprintf(cmd.Stdout, "rom file %s in depot\n", rompath)
			fmt.Fprintf(cmd.Stdout, "crc = %s\n", hex.EncodeToString(hh.Crc))
			fmt.Fprintf(cmd.Stdout, "md5 = %s\n", hex.EncodeToString(hh.Md5))
			fmt.Fprintf(cmd.Stdout, "size = %d\n", size)
			r.Crc = hh.Crc
			r.Md5 = hh.Md5

			if outpath != "" {
				worker.Cp(rompath, filepath.Join(outpath, filepath.Base(rompath)))
			}
		}
	}

	dats, err := rs.romDB.DatsForRom(r)
	if err != nil {
		return err
	}

	if len(dats) > 0 {
		fmt.Fprintf(cmd.Stdout, "-----------------\n")
		fmt.Fprintf(cmd.Stdout, "rom found in:\n")
		for _, dat := range dats {
			dn := dat.NarrowToRom(r)
			if dn != nil {
				fmt.Fprintf(cmd.Stdout, "%s\n", types.PrintDat(dn))
			}
		}
	}
	return nil
}