Skip to content
quarry Artifact [db904f4d34]
Login

Artifact [db904f4d34]

Artifact db904f4d34547e4d20cc6230033efef01afc9f05adb8b601dedf8058f16ceeba:


//go:build unix

package main

import (
	"os"
	"syscall"
)

// deployRunning reports whether scripts/deploy.sh holds its lock: the
// script keeps an exclusive flock on the file for the whole deploy and
// the kernel drops it with the process, so a shared non-blocking lock
// failing means a deploy is running. A file that cannot be opened is
// no deploy.
func deployRunning(path string) bool {
	f, err := os.Open(path)
	if err != nil {
		return false
	}
	defer f.Close()
	if err := syscall.Flock(int(f.Fd()), syscall.LOCK_SH|syscall.LOCK_NB); err != nil {
		return err == syscall.EWOULDBLOCK
	}
	syscall.Flock(int(f.Fd()), syscall.LOCK_UN)
	return false
}