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

Function Lock

pkg/composer/lock.go:29–44  ·  view source on GitHub ↗
(dataRoot string, address string)

Source from the content-addressed store, hash-verified

27var locked *os.File
28
29func Lock(dataRoot string, address string) error {
30 // Compose right now cannot be made safe to use concurrently, as we shell out to nerdctl for multiple operations,
31 // preventing us from using the lock mechanisms from the API.
32 // This here allows to impose a global lock, effectively preventing multiple compose commands from being run in parallel and
33 // preventing some of the problems with concurrent execution.
34 // This should be removed once we have better, in-depth solutions to make compose concurrency safe.
35 // Note that in most cases we do not close the lock explicitly. Instead, the lock will get released when the `locked` global
36 // variable will get collected and the file descriptor closed (eg: when the binary exits).
37 var err error
38 dataStore, err := clientutil.DataStore(dataRoot, address)
39 if err != nil {
40 return err
41 }
42 locked, err = filesystem.Lock(dataStore)
43 return err
44}
45
46func Unlock() error {
47 return filesystem.Unlock(locked)

Callers 1

NewFunction · 0.92

Calls 2

DataStoreFunction · 0.92
LockFunction · 0.92

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…