MCPcopy Create free account
hub / github.com/cli/cli / CopyFile

Method CopyFile

internal/safepaths/root.go:253–266  ·  view source on GitHub ↗

CopyFile copies content into a file beneath the root. Creation permissions follow [Root.Create].

(name string, src io.Reader, filePerm, dirPerm os.FileMode, replace bool)

Source from the content-addressed store, hash-verified

251// CopyFile copies content into a file beneath the root.
252// Creation permissions follow [Root.Create].
253func (r *Root) CopyFile(name string, src io.Reader, filePerm, dirPerm os.FileMode, replace bool) (err error) {
254 file, err := r.Create(name, filePerm, dirPerm, replace)
255 if err != nil {
256 return err
257 }
258 defer func() {
259 if closeErr := file.Close(); err == nil && closeErr != nil {
260 err = closeErr
261 }
262 }()
263
264 _, err = io.Copy(file, src)
265 return err
266}
267
268func (r *Root) localPath(name string) (string, error) {
269 return validateChildPath(name)

Callers 2

extractTarGzFunction · 0.80
TestFileCreationModesFunction · 0.80

Calls 3

CreateMethod · 0.95
CloseMethod · 0.65
CopyMethod · 0.45

Tested by 1

TestFileCreationModesFunction · 0.64