package updates import ( "fmt" "time" ) // canStart is the whole "may this phase begin" decision. The maintenance // window deadline only gates the start of a phase: a package manager that is // already running is never interrupted by it, because killing apt, dnf or // Windows Update partway through a transaction is worse than letting it // finish late. A zero deadline is a manual run, which always may start. func canStart(now, deadline time.Time) bool { return deadline.IsZero() || now.Before(deadline) } // startGate returns the error reported when a phase is refused. func startGate(deadline time.Time, phase string) error { if canStart(time.Now(), deadline) { return nil } return fmt.Errorf("the maintenance window ended before %s could start", phase) }