MCPcopy Index your code
hub / github.com/containerd/containerd / copyFileWithSync

Function copyFileWithSync

plugins/snapshots/blockfile/blockfile.go:456–482  ·  view source on GitHub ↗
(target, source string)

Source from the content-addressed store, hash-verified

454}
455
456func copyFileWithSync(target, source string) error {
457 // The Go stdlib does not seem to have an efficient os.File.ReadFrom
458 // routine for other platforms like it does on Linux with
459 // copy_file_range. For Darwin at least we can use clonefile
460 // in its place, otherwise if we have a sparse file we'd have
461 // a fun surprise waiting below.
462 //
463 // TODO: Enlighten other platforms (windows?)
464 if runtime.GOOS == "darwin" {
465 return fs.CopyFile(target, source)
466 }
467
468 src, err := os.Open(source)
469 if err != nil {
470 return fmt.Errorf("failed to open source %s: %w", source, err)
471 }
472 defer src.Close()
473 tgt, err := os.Create(target)
474 if err != nil {
475 return fmt.Errorf("failed to open target %s: %w", target, err)
476 }
477 defer tgt.Close()
478 defer tgt.Sync()
479
480 _, err = io.Copy(tgt, src)
481 return err
482}

Callers 2

WithScratchFileFunction · 0.85
createSnapshotMethod · 0.85

Calls 6

CopyMethod · 0.80
CopyFileMethod · 0.65
CloseMethod · 0.65
CreateMethod · 0.65
SyncMethod · 0.65
OpenMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…