refactor(thothctl): share Pi lifecycle lock

This commit is contained in:
2026-08-14 17:36:33 +02:00
parent ae1215dc98
commit e902f758b1
4 changed files with 30 additions and 4 deletions
+6 -2
View File
@@ -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 {