func (n *node) ReadDir(intr fusefs.Intr) ([]fuse.Dirent, fuse.Error) { log.Printf("CAMLI ReadDir on %v", n.blobref) n.dmu.Lock() defer n.dmu.Unlock() if n.dirents != nil { return n.dirents, nil } ss, err := n.schema() if err != nil { log.Printf("camli.ReadDir error on %v: %v", n.blobref, err) return nil, fuse.EIO } dr, err := schema.NewDirReader(n.fs.fetcher, ss.BlobRef()) if err != nil { log.Printf("camli.ReadDir error on %v: %v", n.blobref, err) return nil, fuse.EIO } schemaEnts, err := dr.Readdir(-1) if err != nil { log.Printf("camli.ReadDir error on %v: %v", n.blobref, err) return nil, fuse.EIO } n.dirents = make([]fuse.Dirent, 0) for _, sent := range schemaEnts { if name := sent.FileName(); name != "" { n.addLookupEntry(name, sent.BlobRef()) n.dirents = append(n.dirents, fuse.Dirent{Name: name}) } } return n.dirents, nil }
// blobsFromDir returns the list of file blobs in directory dirBlob. // It only traverses permanode directories. func (zh *zipHandler) blobsFromDir(dirPath string, dirBlob blob.Ref) ([]*blobFile, error) { var list []*blobFile dr, err := schema.NewDirReader(zh.storageSeekFetcher(), dirBlob) if err != nil { return nil, fmt.Errorf("Could not read dir blob %v: %v", dirBlob, err) } ent, err := dr.Readdir(-1) if err != nil { return nil, fmt.Errorf("Could not read dir entries: %v", err) } for _, v := range ent { fullpath := path.Join(dirPath, v.FileName()) switch v.CamliType() { case "file": list = append(list, &blobFile{v.BlobRef(), fullpath}) case "directory": children, err := zh.blobsFromDir(fullpath, v.BlobRef()) if err != nil { return nil, fmt.Errorf("Could not get list of blobs from %v: %v", v.BlobRef(), err) } list = append(list, children...) } } return list, nil }