MCPcopy Index your code
hub / github.com/devspace-sh/devspace / downloadFiles

Method downloadFiles

pkg/devspace/sync/downstream.go:312–395  ·  view source on GitHub ↗

downloadFiles downloads the given files from the remote server and writes the contents into the given writer

(writer io.WriteCloser, changes []*remote.Change)

Source from the content-addressed store, hash-verified

310
311// downloadFiles downloads the given files from the remote server and writes the contents into the given writer
312func (d *downstream) downloadFiles(writer io.WriteCloser, changes []*remote.Change) error {
313 defer writer.Close()
314
315 // cancel after 1 hour
316 ctx, cancel := context.WithTimeout(d.sync.ctx, time.Hour)
317 defer cancel()
318
319 // Print log message
320 if len(changes) <= 3 || d.sync.Options.Verbose {
321 for _, element := range changes {
322 d.sync.log.Infof("Downstream - Download file '.%s', uncompressed: ~%0.2f KB", element.Path, float64(element.Size)/1024.0)
323 }
324 } else if len(changes) > 3 {
325 filesize := int64(0)
326 for _, v := range changes {
327 filesize += v.Size
328 }
329
330 d.sync.log.Infof("Downstream - Download %d file(s) (Uncompressed: ~%0.2f KB)", len(changes), float64(filesize)/1024.0)
331 }
332
333 // Create new download client
334 downloadClient, err := d.client.Download(ctx)
335 if err != nil {
336 return errors.Wrap(err, "download files")
337 }
338
339 // Send files to download
340 downloadFiles := make([]string, 0, downloadFilesBufferSize)
341 for _, change := range changes {
342 downloadFiles = append(downloadFiles, change.Path)
343
344 if len(downloadFiles) >= downloadFilesBufferSize {
345 err = downloadClient.Send(&remote.Paths{
346 Paths: downloadFiles,
347 })
348 if err != nil {
349 return errors.Wrap(err, "send path")
350 }
351
352 downloadFiles = make([]string, 0, downloadFilesBufferSize)
353 }
354 }
355
356 if len(downloadFiles) >= 0 {
357 err = downloadClient.Send(&remote.Paths{
358 Paths: downloadFiles,
359 })
360 if err != nil {
361 return errors.Wrap(err, "send path")
362 }
363 }
364
365 // We finish sending and start receiving the tar
366 err = downloadClient.CloseSend()
367 if err != nil {
368 return errors.Wrap(err, "close send")
369 }

Callers 1

initDownloadMethod · 0.95

Calls 8

WithTimeoutMethod · 0.80
CloseMethod · 0.65
DownloadMethod · 0.65
SendMethod · 0.65
RecvMethod · 0.65
InfofMethod · 0.45
WriteMethod · 0.45
ErrorMethod · 0.45

Tested by

no test coverage detected