MCPcopy
hub / github.com/containerd/containerd / updateFile

Function updateFile

core/snapshots/benchsuite/benchmark_test.go:285–316  ·  view source on GitHub ↗

updateFile modifies a few bytes in the middle in order to demonstrate the difference in performance for block-based snapshotters (like devicemapper) against file-based snapshotters (like overlay, which need to perform a copy-up of the full file any time a single bit is modified).

(name string)

Source from the content-addressed store, hash-verified

283// for block-based snapshotters (like devicemapper) against file-based snapshotters (like overlay, which need to
284// perform a copy-up of the full file any time a single bit is modified).
285func updateFile(name string) applierFn {
286 return func(root string) error {
287 path := filepath.Join(root, name)
288 file, err := os.OpenFile(path, os.O_WRONLY, 0600)
289 if err != nil {
290 return fmt.Errorf("failed to open %q: %w", path, err)
291 }
292
293 info, err := file.Stat()
294 if err != nil {
295 file.Close()
296 return err
297 }
298
299 var (
300 offset = info.Size() / 2
301 buf = make([]byte, 4)
302 )
303
304 if _, err := rand.Read(buf); err != nil {
305 file.Close()
306 return err
307 }
308
309 if _, err := file.WriteAt(buf, offset); err != nil {
310 file.Close()
311 return fmt.Errorf("failed to write %q at offset %d: %w", path, offset, err)
312 }
313
314 return file.Close()
315 }
316}

Callers 1

makeApplierFunction · 0.85

Calls 4

StatMethod · 0.65
CloseMethod · 0.65
SizeMethod · 0.65
ReadMethod · 0.65

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…