// 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 }
func (m *Model) IsBlobs(names ...string) (res map[string]bool, err error) { res = map[string]bool{} var req, res1 []interface{} for _, n := range names { req = append(req, n) } err = m.BatchPool.Do( func(ctx context.Context, in interface{}) (out interface{}, err error) { lock, err := m.FdLocks.Take() if err != nil { return } defer lock.Release() f, err := os.Open(filepath.Join(m.WD, in.(string))) if err != nil { return } defer f.Close() _, isManifest, err := proto.PeekManifest(f) if err != nil { return } out = struct { name string isBlob bool }{in.(string), !isManifest} return }, &req, &res1, concurrency.DefaultBatchOptions(), ) for _, r := range res1 { r1 := r.(struct { name string isBlob bool }) res[r1.name] = r1.isBlob } return }
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 }