1package daemon23import (4 "context"5 "errors"67 "github.com/FelineStateMachine/tinyrelay/internal/catalog"8)910// deleteTenant stops the live services before erasing the catalog row and11// tenant directory. It removes the app map entry before waiting so a request12// arriving concurrently cannot acquire a second reference to the tenant.13func (a *App) deleteTenant(ctx context.Context, id string) error {14 a.mu.Lock()15 t := a.tenants[id]16 if t == nil {17 a.mu.Unlock()18 return catalog.ErrNotFound19 }20 if err := a.catalog.Disable(ctx, id); err != nil && !errors.Is(err, catalog.ErrInvalidTransition) {21 a.mu.Unlock()22 return err23 }24 delete(a.tenants, id)25 a.mu.Unlock()26 if err := t.Close(ctx); err != nil {27 return err28 }29 return a.catalog.Delete(ctx, id)30}