MCPcopy Index your code
hub / github.com/coder/coder / File

Function File

scripts/atomicwrite/atomicwrite.go:13–32  ·  view source on GitHub ↗

File atomically writes data to the named file. It writes to a temporary file in the same directory and renames it so that an interrupted write never leaves a partially-written target.

(path string, data []byte)

Source from the content-addressed store, hash-verified

11// temporary file in the same directory and renames it so that an
12// interrupted write never leaves a partially-written target.
13func File(path string, data []byte) error {
14 dir := filepath.Dir(path)
15 tmp, err := os.CreateTemp(dir, filepath.Base(path)+".tmp.*")
16 if err != nil {
17 return xerrors.Errorf("create temp file: %w", err)
18 }
19 defer os.Remove(tmp.Name())
20
21 if _, err := tmp.Write(data); err != nil {
22 _ = tmp.Close()
23 return xerrors.Errorf("write temp file: %w", err)
24 }
25 if err := tmp.Close(); err != nil {
26 return xerrors.Errorf("close temp file: %w", err)
27 }
28 if err := os.Rename(tmp.Name(), path); err != nil {
29 return xerrors.Errorf("rename temp file: %w", err)
30 }
31 return nil
32}

Callers 9

mainFunction · 0.92
writeAuditDocFunction · 0.92
generateIconListFunction · 0.92
writeDocsFunction · 0.92
writePrometheusDocFunction · 0.92
genTreeFunction · 0.92
mainFunction · 0.92
generateConstraintsFunction · 0.92

Calls 6

RemoveMethod · 0.65
NameMethod · 0.65
WriteMethod · 0.65
CloseMethod · 0.65
ErrorfMethod · 0.45
RenameMethod · 0.45

Tested by

no test coverage detected