MCPcopy Create free account
hub / github.com/containerd/nerdctl / WithLock

Function WithLock

pkg/internal/filesystem/lock.go:101–112  ·  view source on GitHub ↗

WithLock executes the provided function after placing a write lock on `path`. The lock is released once the function has been run, regardless of outcome.

(path string, function func() error)

Source from the content-addressed store, hash-verified

99// WithLock executes the provided function after placing a write lock on `path`.
100// The lock is released once the function has been run, regardless of outcome.
101func WithLock(path string, function func() error) (err error) {
102 file, err := Lock(path)
103 if err != nil {
104 return err
105 }
106
107 defer func() {
108 err = errors.Join(Unlock(file), err)
109 }()
110
111 return function()
112}
113
114// WithReadOnlyLock executes the provided function after placing a read lock on `path`.
115// The lock is released once the function has been run, regardless of outcome.

Callers 8

writeHealthLogFunction · 0.92
WaitForLoggerFunction · 0.92
loggerFuncFunction · 0.92
TestLockWriteConcurrentFunction · 0.92
TestLockMultiReadFunction · 0.92
TestLockWriteBlocksReadFunction · 0.92
fsRemoveFunction · 0.92
fsWriteFunction · 0.92

Calls 2

LockFunction · 0.70
UnlockFunction · 0.70

Tested by 3

TestLockWriteConcurrentFunction · 0.74
TestLockMultiReadFunction · 0.74
TestLockWriteBlocksReadFunction · 0.74

Used in the wild real call sites across dependent graphs

searching dependent graphs…