MCPcopy
hub / github.com/dgraph-io/dgraph / ReadFileFromContainer

Method ReadFileFromContainer

dgraphtest/local_cluster.go:1527–1546  ·  view source on GitHub ↗

CopyExportToHost copies exported files from the container to a host directory. It returns the paths to RDF/JSON files and schema files on the host.

(containerPath string)

Source from the content-addressed store, hash-verified

1525// CopyExportToHost copies exported files from the container to a host directory.
1526// It returns the paths to RDF/JSON files and schema files on the host.
1527func (c *LocalCluster) ReadFileFromContainer(containerPath string) ([]byte, error) {
1528 ctx, cancel := context.WithTimeout(context.Background(), requestTimeout)
1529 defer cancel()
1530
1531 ts, _, err := c.dcli.CopyFromContainer(ctx, c.alphas[0].cid(), containerPath)
1532 if err != nil {
1533 return nil, errors.Wrapf(err, "error copying file from container [%v]", c.alphas[0].cname())
1534 }
1535 defer ts.Close()
1536
1537 tr := tar.NewReader(ts)
1538 if _, err := tr.Next(); err != nil {
1539 return nil, errors.Wrap(err, "error reading tar header")
1540 }
1541 data, err := io.ReadAll(tr)
1542 if err != nil {
1543 return nil, errors.Wrap(err, "error reading file contents from tar stream")
1544 }
1545 return data, nil
1546}
1547
1548func (c *LocalCluster) CopyExportToHost(exportDir, hostDir string) (dataFiles, schemaFiles []string, err error) {
1549 ctx, cancel := context.WithTimeout(context.Background(), requestTimeout)

Callers 2

readBackupManifestFunction · 0.80

Calls 4

cidMethod · 0.65
cnameMethod · 0.65
CloseMethod · 0.65
NextMethod · 0.45

Tested by 2

readBackupManifestFunction · 0.64