/
lock.go
38 lines (31 loc) · 746 Bytes
/
lock.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
package client
import (
"os"
)
// LockProcess recipe on process
func LockProcess(name string, client *Client) bool {
file := client.Config.recipesPath + "/" + name + ".lock"
_, err := os.OpenFile(file, os.O_RDONLY|os.O_CREATE, 0666)
if err != nil {
return false
}
return true
}
// IsLocked check does lock exists
func IsLocked(name string, client *Client) bool {
file := client.Config.recipesPath + "/" + name + ".lock"
if _, err := os.Stat(file); err == nil {
return true
}
return false
}
// RemoveLock recipe on process
func RemoveLock(name string, client *Client) bool {
file := client.Config.recipesPath + "/" + name + ".lock"
// delete file
var err = os.Remove(file)
if err != nil {
return false
}
return true
}