MCPcopy
hub / github.com/syncthing/syncthing / WriteFile

Function WriteFile

lib/fs/filesystem.go:371–381  ·  view source on GitHub ↗

WriteFile writes data to the named file, creating it if necessary. If the file does not exist, WriteFile creates it with permissions perm (before umask); otherwise WriteFile truncates it before writing, without changing permissions. Since Writefile requires multiple system calls to complete, a failu

(fs Filesystem, name string, data []byte, perm FileMode)

Source from the content-addressed store, hash-verified

369// Since Writefile requires multiple system calls to complete, a failure mid-operation
370// can leave the file in a partially written state.
371func WriteFile(fs Filesystem, name string, data []byte, perm FileMode) error {
372 f, err := fs.OpenFile(name, os.O_WRONLY|os.O_CREATE|os.O_TRUNC, perm)
373 if err != nil {
374 return err
375 }
376 _, err = f.Write(data)
377 if err1 := f.Close(); err1 != nil && err == nil {
378 err = err1
379 }
380 return err
381}

Callers 7

TestIssue3164Function · 0.92
newTestFSFunction · 0.92
testEscapeFunction · 0.92
TestBrowseFunction · 0.92
newTestFsFunction · 0.92
CreateMarkerMethod · 0.92
TestMtimeFSInsensitiveFunction · 0.85

Calls 3

OpenFileMethod · 0.65
CloseMethod · 0.65
WriteMethod · 0.45

Tested by 6

TestIssue3164Function · 0.74
newTestFSFunction · 0.74
testEscapeFunction · 0.74
TestBrowseFunction · 0.74
newTestFsFunction · 0.74
TestMtimeFSInsensitiveFunction · 0.68