refactor(thothctl): share Pi lifecycle lock
This commit is contained in:
@@ -180,13 +180,17 @@ type updateLock struct {
|
||||
metadata string
|
||||
}
|
||||
|
||||
var ErrLockHeld = errors.New("another Pi update or rollback is already in progress")
|
||||
var ErrLockHeld = errors.New("another Pi update, restart, or rollback is already in progress")
|
||||
|
||||
func lifecycleLockPath(statePath string) string {
|
||||
return filepath.Join(filepath.Dir(statePath), "pi-lifecycle.lock")
|
||||
}
|
||||
|
||||
func acquireLock(statePath string) (*updateLock, error) {
|
||||
if err := os.MkdirAll(filepath.Dir(statePath), 0o700); err != nil {
|
||||
return nil, errors.New("could not create Pi update recovery directory")
|
||||
}
|
||||
path := statePath + ".lock"
|
||||
path := lifecycleLockPath(statePath)
|
||||
file := flock.New(path, flock.SetPermissions(0o600))
|
||||
locked, err := file.TryLock()
|
||||
if err != nil {
|
||||
|
||||
Reference in New Issue
Block a user