MCPcopy
hub / github.com/git-lfs/git-lfs / CheckCloneFileSupported

Function CheckCloneFileSupported

tools/util_windows.go:40–67  ·  view source on GitHub ↗

CheckCloneFileSupported runs explicit test of clone file on supplied directory. This function creates some (src and dst) file in the directory and remove after test finished. If check failed (e.g. directory is read-only), returns err.

(dir string)

Source from the content-addressed store, hash-verified

38//
39// If check failed (e.g. directory is read-only), returns err.
40func CheckCloneFileSupported(dir string) (supported bool, err error) {
41 src, err := os.CreateTemp(dir, "src")
42 if err != nil {
43 return false, err
44 }
45 defer func() {
46 src.Close()
47 os.Remove(src.Name())
48 }()
49
50 // Make src file not empty.
51 // Because `FSCTL_DUPLICATE_EXTENTS_TO_FILE` on empty file is always success even filesystem don't support it.
52 _, err = src.WriteString("TESTING")
53 if err != nil {
54 return false, err
55 }
56
57 dst, err := os.CreateTemp(dir, "dst")
58 if err != nil {
59 return false, err
60 }
61 defer func() {
62 dst.Close()
63 os.Remove(dst.Name())
64 }()
65
66 return CloneFile(dst, src)
67}
68
69func CloneFileByPath(dst, src string) (success bool, err error) {
70 dstFile, err := os.OpenFile(dst, os.O_RDWR|os.O_CREATE, 0666) // No truncate version of os.Create

Callers

nothing calls this directly

Calls 4

CloneFileFunction · 0.70
CloseMethod · 0.65
NameMethod · 0.65
RemoveMethod · 0.45

Tested by

no test coverage detected