All checks were successful
Test / Create distribution (push) Successful in 35s
Test / Sandbox (push) Successful in 2m5s
Test / Hakurei (push) Successful in 3m20s
Test / Hpkg (push) Successful in 3m57s
Test / Sandbox (race detector) (push) Successful in 4m41s
Test / Hakurei (race detector) (push) Successful in 5m25s
Test / Flake checks (push) Successful in 1m39s
This cleans up for the test overhaul of this package. Signed-off-by: Ophestra <cat@gensokyo.uk>
38 lines
1.1 KiB
Go
38 lines
1.1 KiB
Go
package system
|
|
|
|
import (
|
|
"hakurei.app/system/internal/xcb"
|
|
)
|
|
|
|
// ChangeHosts appends [XHostOp] to [I].
|
|
func (sys *I) ChangeHosts(username string) *I {
|
|
sys.ops = append(sys.ops, XHostOp(username))
|
|
return sys
|
|
}
|
|
|
|
// XHostOp inserts the target user into X11 hosts and deletes it once its [Enablement] is no longer satisfied.
|
|
type XHostOp string
|
|
|
|
func (x XHostOp) Type() Enablement { return EX11 }
|
|
|
|
func (x XHostOp) apply(*I) error {
|
|
msg.Verbosef("inserting entry %s to X11", x)
|
|
return newOpError("xhost",
|
|
xcb.ChangeHosts(xcb.HostModeInsert, xcb.FamilyServerInterpreted, "localuser\x00"+string(x)), false)
|
|
}
|
|
|
|
func (x XHostOp) revert(_ *I, ec *Criteria) error {
|
|
if ec.hasType(x.Type()) {
|
|
msg.Verbosef("deleting entry %s from X11", x)
|
|
return newOpError("xhost",
|
|
xcb.ChangeHosts(xcb.HostModeDelete, xcb.FamilyServerInterpreted, "localuser\x00"+string(x)), false)
|
|
} else {
|
|
msg.Verbosef("skipping entry %s in X11", x)
|
|
return nil
|
|
}
|
|
}
|
|
|
|
func (x XHostOp) Is(o Op) bool { target, ok := o.(XHostOp); return ok && x == target }
|
|
func (x XHostOp) Path() string { return string(x) }
|
|
func (x XHostOp) String() string { return string("SI:localuser:" + x) }
|