Example #1
0
// Get manifest by filename or given reader
func (m *Model) GetManifest(name string, in io.Reader) (res *proto.Manifest, err error) {
	r, isManifest, err := proto.PeekManifest(in)
	if err != nil {
		return
	}

	if isManifest {
		// ok - just read
		res, err = proto.NewFromManifest(r)
		return
	}

	// Hard way. First - try git
	var sideR io.Reader
	if m.Git != nil {
		if sideR = m.getGitReader(name); sideR != nil {
			res, err = proto.NewFromAny(sideR, m.chunkSize)
			return
		}
	}

	// No git - make from blob
	res, err = proto.NewFromBLOB(r, m.chunkSize)
	return
}
Example #2
0
File: model.go Project: akaspin/bar
func (m *Model) getManifest(name string, blobs, manifests bool) (res *proto.Manifest, err error) {
	lock, err := m.FdLocks.Take()
	if err != nil {
		return
	}
	defer lock.Release()

	logx.Tracef("feeding manifest from %s",
		lists.OSFromSlash(lists.OSJoin(m.WD, name)))
	f, err := os.Open(lists.OSFromSlash(lists.OSJoin(m.WD, name)))
	if err != nil {
		logx.Errorf("!!! %s", err)
		return
	}
	defer f.Close()

	var r io.Reader
	var isManifest bool
	if r, isManifest, err = proto.PeekManifest(f); err != nil {
		return
	}
	if (isManifest && !manifests) || (!isManifest && !blobs) {
		return
	}

	if isManifest {
		res, err = proto.NewFromManifest(r)
		return
	}
	// Hard way. First - try git
	var sideR io.Reader
	if m.Git != nil {
		if sideR = m.getGitReader(name); sideR != nil {
			res, err = proto.NewFromAny(sideR, m.chunkSize)
			return
		}
	}
	// No git - make from blob
	res, err = proto.NewFromBLOB(r, m.chunkSize)
	return
}