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

Method WriteFile

internal/safepaths/root.go:236–249  ·  view source on GitHub ↗

WriteFile writes a complete file beneath the root. Creation permissions follow [Root.Create].

(name string, data []byte, filePerm, dirPerm os.FileMode, replace bool)

Source from the content-addressed store, hash-verified

234// WriteFile writes a complete file beneath the root.
235// Creation permissions follow [Root.Create].
236func (r *Root) WriteFile(name string, data []byte, filePerm, dirPerm os.FileMode, replace bool) (err error) {
237 file, err := r.Create(name, filePerm, dirPerm, replace)
238 if err != nil {
239 return err
240 }
241 defer func() {
242 if closeErr := file.Close(); err == nil && closeErr != nil {
243 err = closeErr
244 }
245 }()
246
247 _, err = file.Write(data)
248 return err
249}
250
251// CopyFile copies content into a file beneath the root.
252// Creation permissions follow [Root.Create].

Callers 15

TestCmdSetFunction · 0.80
TestCmdGitFunction · 0.80
TestCmdExportFunction · 0.80
extractTestArchiveFunction · 0.80
TestSchemaSourceLocateFunction · 0.80
TestCmdSchemasFunction · 0.80
newScratchFunction · 0.80
writeGHConfigFunction · 0.80
copyGitPathFileFunction · 0.80
cmdWriteFunction · 0.80
fakeGHFunction · 0.80
writeFakeGHFunction · 0.80

Calls 3

CreateMethod · 0.95
CloseMethod · 0.65
WriteMethod · 0.65

Tested by 15

TestCmdSetFunction · 0.64
TestCmdGitFunction · 0.64
TestCmdExportFunction · 0.64
extractTestArchiveFunction · 0.64
TestSchemaSourceLocateFunction · 0.64
TestCmdSchemasFunction · 0.64
fakeGHFunction · 0.64
writeFakeGHFunction · 0.64
TestRunAllFunction · 0.64
writeConfigFixtureFunction · 0.64