MCPcopy Index your code
hub / github.com/coder/coder / DownloadFile

Method DownloadFile

provisionerd/provisionerd.go:576–603  ·  view source on GitHub ↗

DownloadFile will download a module file from coderd.

(ctx context.Context, request *proto.FileRequest)

Source from the content-addressed store, hash-verified

574
575// DownloadFile will download a module file from coderd.
576func (p *Server) DownloadFile(ctx context.Context, request *proto.FileRequest) ([]byte, error) {
577 data, err := clientDoWithRetries(ctx, p.client, func(ctx context.Context, client proto.DRPCProvisionerDaemonClient) ([]byte, error) {
578 // Add some timeout to prevent the stream from hanging indefinitely if something goes wrong.
579 ctx, cancel := context.WithTimeout(ctx, 5*time.Minute)
580 defer cancel()
581
582 stream, err := client.DownloadFile(ctx, request)
583 if err != nil {
584 return nil, xerrors.Errorf("failed to start DownloadFile stream: %w", err)
585 }
586 defer stream.Close()
587
588 file, err := provisionersdk.HandleReceivingDataUpload(stream)
589 if err != nil {
590 return nil, xerrors.Errorf("failed to handle receiving data upload: %w", err)
591 }
592 data, err := file.Complete()
593 if err != nil {
594 return nil, xerrors.Errorf("failed to download file: %w", err)
595 }
596 return data, nil
597 })
598 if err != nil {
599 return nil, xerrors.Errorf("download file %s: %w", request.FileId, err)
600 }
601
602 return data, nil
603}
604
605func (p *Server) CompleteJob(ctx context.Context, in *proto.CompletedJob) error {
606 // If the moduleFiles exceed the max message size, we need to upload them separately.

Callers

nothing calls this directly

Calls 6

clientDoWithRetriesFunction · 0.85
DownloadFileMethod · 0.65
CloseMethod · 0.65
ErrorfMethod · 0.45
CompleteMethod · 0.45

Tested by

no test coverage detected