MCPcopy
hub / github.com/SurgeDM/Surge / CopyFile

Function CopyFile

internal/utils/file.go:9–35  ·  view source on GitHub ↗

CopyFile centralizes the rename-fallback copy path used by download finalization.

(src, dst string)

Source from the content-addressed store, hash-verified

7
8// CopyFile centralizes the rename-fallback copy path used by download finalization.
9func CopyFile(src, dst string) error {
10 in, err := os.Open(src)
11 if err != nil {
12 return err
13 }
14 defer func() {
15 if err := in.Close(); err != nil {
16 Debug("Error closing input file: %v", err)
17 }
18 }()
19
20 out, err := os.Create(dst)
21 if err != nil {
22 return err
23 }
24 defer func() {
25 if err := out.Close(); err != nil {
26 Debug("Error closing output file: %v", err)
27 }
28 }()
29
30 buf := make([]byte, 1<<20)
31 if _, err := io.CopyBuffer(out, in, buf); err != nil {
32 return err
33 }
34 return out.Sync()
35}

Callers 6

TestCopyFileFunction · 0.92
TestCopyFile_EmptyFileFunction · 0.92
TestCopyFile_LargeFileFunction · 0.92

Calls 2

DebugFunction · 0.85
CloseMethod · 0.45

Tested by 6

TestCopyFileFunction · 0.74
TestCopyFile_EmptyFileFunction · 0.74
TestCopyFile_LargeFileFunction · 0.74