This commit is contained in:
Liang Ding 2023-01-13 16:26:24 +08:00
parent 32ab7b52af
commit 99261db73a
No known key found for this signature in database
GPG key ID: 136F30F901A2231D
2 changed files with 26 additions and 9 deletions

View file

@ -495,6 +495,25 @@ func tryLockWorkspace() {
os.Exit(ExitCodeWorkspaceLocked)
}
func IsWorkspaceLocked(workspacePath string) bool {
if !gulu.File.IsDir(workspacePath) {
return false
}
lockFilePath := filepath.Join(workspacePath, ".lock")
if !gulu.File.IsExist(lockFilePath) {
return false
}
f := flock.New(lockFilePath)
defer f.Unlock()
ok, _ := f.TryLock()
if ok {
return false
}
return true
}
func UnlockWorkspace() {
if nil == WorkspaceLock {
return