MCPcopy
hub / github.com/docker/compose / Lock

Method Lock

internal/locker/pidfile_windows.go:28–48  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

26)
27
28func (f *Pidfile) Lock() error {
29 newPID := os.Getpid()
30 err := pidfile.Write(f.path, newPID)
31 if err != nil {
32 // Get PID registered in the file
33 pid, errPid := pidfile.Read(f.path)
34 if errPid != nil {
35 return err
36 }
37 // Some users faced issues on Windows where the process written in the pidfile was identified as still existing
38 // So we used a 2nd process library to verify if this not a false positive feedback
39 // Check if the process exists
40 process, errPid := ps.FindProcess(pid)
41 if process == nil && errPid == nil {
42 // If the process does not exist, remove the pidfile and try to lock again
43 _ = os.Remove(f.path)
44 return pidfile.Write(f.path, newPID)
45 }
46 }
47 return err
48}

Callers

nothing calls this directly

Calls 3

WriteFunction · 0.92
ReadFunction · 0.92
RemoveMethod · 0.65

Tested by

no test coverage detected