| 27 | var locked *os.File |
| 28 | |
| 29 | func 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 | |
| 46 | func Unlock() error { |
| 47 | return filesystem.Unlock(locked) |