// Read the metadata from the given dir func getMetadata(ctx context.Context, ds *datastore.Helper, dir string) (map[string][]byte, error) { res, err := ds.Ls(ctx, dir) if err != nil { return nil, err } if len(res.File) == 0 { log.Infof("No meta found for %s", dir) return nil, nil } meta := make(map[string][]byte) for _, f := range res.File { finfo, ok := f.(*types.FileInfo) if !ok { continue } p := path.Join(dir, finfo.Path) log.Infof("Getting metadata %s", p) rc, err := ds.Download(ctx, p) if err != nil { return nil, err } defer rc.Close() buf, err := ioutil.ReadAll(rc) if err != nil { return nil, err } meta[finfo.Path] = buf } return meta, nil }