MCPcopy
hub / github.com/kopia/kopia / downloadFile

Function downloadFile

internal/diff/diff.go:370–389  ·  view source on GitHub ↗
(ctx context.Context, f fs.File, fname string)

Source from the content-addressed store, hash-verified

368}
369
370func downloadFile(ctx context.Context, f fs.File, fname string) error {
371 if err := os.MkdirAll(filepath.Dir(fname), dirMode); err != nil {
372 return errors.Wrap(err, "error making directory")
373 }
374
375 src, err := f.Open(ctx)
376 if err != nil {
377 return errors.Wrap(err, "error opening object")
378 }
379 defer src.Close() //nolint:errcheck
380
381 dst, err := os.Create(fname) //nolint:gosec
382 if err != nil {
383 return errors.Wrap(err, "error creating file to edit")
384 }
385
386 defer dst.Close() //nolint:errcheck
387
388 return errors.Wrap(iocopy.JustCopy(dst, src), "error downloading file")
389}
390
391// Stats returns aggregated statistics computed during snapshot comparison
392// must be invoked after a call to Compare which populates ComparerStats struct.

Callers 1

compareFilesMethod · 0.85

Calls 4

JustCopyFunction · 0.92
MkdirAllMethod · 0.65
OpenMethod · 0.65
CloseMethod · 0.65

Tested by

no test coverage detected