MCPcopy Create free account
hub / github.com/Azure/peerd / writeAll

Function writeAll

pkg/cache/item.go:100–116  ·  view source on GitHub ↗

writeAll writes the file.

(file *os.File, buff []byte)

Source from the content-addressed store, hash-verified

98
99// writeAll writes the file.
100func writeAll(file *os.File, buff []byte) (int, error) {
101 offset := 0
102 err := file.Truncate(0)
103 if err != nil {
104 return 0, err
105 }
106
107 l, err := file.Write(buff[offset:])
108 if err != nil {
109 if err := os.Remove(file.Name()); err != nil {
110 log.Error().Err(err).Str("name", file.Name()).Msg("attempted to remove file because the size written did not match the file size")
111 }
112 return 0, err
113 }
114
115 return l, nil
116}
117
118// newItem creates a new cache item that is ready to be filled.
119func newItem(key string, l zerolog.Logger) (*item, error) {

Callers 3

TestWriteAllTruncateFailFunction · 0.85
TestWriteAllFunction · 0.85
fillMethod · 0.85

Calls

no outgoing calls

Tested by 2

TestWriteAllTruncateFailFunction · 0.68
TestWriteAllFunction · 0.68