system: move enablements from state package

This removes the unnecessary import of the state package.

Signed-off-by: Ophestra Umiker <cat@ophivana.moe>
This commit is contained in:
2024-10-16 14:38:57 +09:00
parent 084cd84f36
commit c21168a741
17 changed files with 63 additions and 67 deletions

View File

@@ -6,7 +6,6 @@ import (
"git.ophivana.moe/cat/fortify/acl"
"git.ophivana.moe/cat/fortify/internal/fmsg"
"git.ophivana.moe/cat/fortify/internal/state"
"git.ophivana.moe/cat/fortify/internal/verbose"
)
@@ -16,7 +15,7 @@ func (sys *I) UpdatePerm(path string, perms ...acl.Perm) {
}
// UpdatePermType appends an acl update Op.
func (sys *I) UpdatePermType(et state.Enablement, path string, perms ...acl.Perm) {
func (sys *I) UpdatePermType(et Enablement, path string, perms ...acl.Perm) {
sys.lock.Lock()
defer sys.lock.Unlock()
@@ -24,12 +23,12 @@ func (sys *I) UpdatePermType(et state.Enablement, path string, perms ...acl.Perm
}
type ACL struct {
et state.Enablement
et Enablement
path string
perms []acl.Perm
}
func (a *ACL) Type() state.Enablement {
func (a *ACL) Type() Enablement {
return a.et
}

View File

@@ -7,7 +7,6 @@ import (
"git.ophivana.moe/cat/fortify/dbus"
"git.ophivana.moe/cat/fortify/internal/fmsg"
"git.ophivana.moe/cat/fortify/internal/state"
"git.ophivana.moe/cat/fortify/internal/verbose"
)
@@ -69,7 +68,7 @@ type DBus struct {
done chan struct{}
}
func (d *DBus) Type() state.Enablement {
func (d *DBus) Type() Enablement {
return Process
}

View File

@@ -0,0 +1,46 @@
package system
type (
// Enablement represents an optional system resource
Enablement uint8
// Enablements represents optional system resources to share
Enablements uint64
)
const (
EWayland Enablement = iota
EX11
EDBus
EPulse
)
var enablementString = [...]string{
EWayland: "Wayland",
EX11: "X11",
EDBus: "D-Bus",
EPulse: "PulseAudio",
}
const ELen = len(enablementString)
func (e Enablement) String() string {
return enablementString[e]
}
func (e Enablement) Mask() Enablements {
return 1 << e
}
// Has returns whether a feature is enabled
func (es *Enablements) Has(e Enablement) bool {
return *es&e.Mask() != 0
}
// Set enables a feature
func (es *Enablements) Set(e Enablement) {
if es.Has(e) {
panic("enablement " + e.String() + " set twice")
}
*es |= e.Mask()
}

View File

@@ -6,7 +6,6 @@ import (
"os"
"git.ophivana.moe/cat/fortify/internal/fmsg"
"git.ophivana.moe/cat/fortify/internal/state"
"git.ophivana.moe/cat/fortify/internal/verbose"
)
@@ -19,7 +18,7 @@ func (sys *I) Ensure(name string, perm os.FileMode) {
}
// Ephemeral ensures the temporary existence and mode of a directory through the life of et.
func (sys *I) Ephemeral(et state.Enablement, name string, perm os.FileMode) {
func (sys *I) Ephemeral(et Enablement, name string, perm os.FileMode) {
sys.lock.Lock()
defer sys.lock.Unlock()
@@ -27,13 +26,13 @@ func (sys *I) Ephemeral(et state.Enablement, name string, perm os.FileMode) {
}
type Mkdir struct {
et state.Enablement
et Enablement
path string
perm os.FileMode
ephemeral bool
}
func (m *Mkdir) Type() state.Enablement {
func (m *Mkdir) Type() Enablement {
return m.et
}

View File

@@ -4,19 +4,17 @@ import (
"errors"
"fmt"
"sync"
"git.ophivana.moe/cat/fortify/internal/state"
)
const (
// Process type is unconditionally reverted on exit.
Process = state.EnableLength + 1
// User type is reverted at final launcher exit.
User = state.EnableLength
User = Enablement(ELen)
// Process type is unconditionally reverted on exit.
Process = Enablement(ELen + 1)
)
type Criteria struct {
*state.Enablements
*Enablements
}
func (ec *Criteria) hasType(o Op) bool {
@@ -31,7 +29,7 @@ func (ec *Criteria) hasType(o Op) bool {
// Op is a reversible system operation.
type Op interface {
// Type returns Op's enablement type.
Type() state.Enablement
Type() Enablement
// apply the Op
apply(sys *I) error
@@ -43,7 +41,7 @@ type Op interface {
String() string
}
func TypeString(e state.Enablement) string {
func TypeString(e Enablement) string {
switch e {
case User:
return "User"

View File

@@ -9,7 +9,6 @@ import (
"git.ophivana.moe/cat/fortify/acl"
"git.ophivana.moe/cat/fortify/internal/fmsg"
"git.ophivana.moe/cat/fortify/internal/state"
"git.ophivana.moe/cat/fortify/internal/verbose"
)
@@ -19,7 +18,7 @@ func (sys *I) CopyFile(dst, src string) {
}
// CopyFileType registers a file copying Op labelled with type et.
func (sys *I) CopyFileType(et state.Enablement, dst, src string) {
func (sys *I) CopyFileType(et Enablement, dst, src string) {
sys.lock.Lock()
sys.ops = append(sys.ops, &Tmpfile{et, tmpfileCopy, dst, src})
sys.lock.Unlock()
@@ -33,7 +32,7 @@ func (sys *I) Link(oldname, newname string) {
}
// LinkFileType registers a file linking Op labelled with type et.
func (sys *I) LinkFileType(et state.Enablement, oldname, newname string) {
func (sys *I) LinkFileType(et Enablement, oldname, newname string) {
sys.lock.Lock()
defer sys.lock.Unlock()
@@ -46,7 +45,7 @@ func (sys *I) Write(dst, src string) {
}
// WriteType registers a file writing Op labelled with type et.
func (sys *I) WriteType(et state.Enablement, dst, src string) {
func (sys *I) WriteType(et Enablement, dst, src string) {
sys.lock.Lock()
sys.ops = append(sys.ops, &Tmpfile{et, tmpfileWrite, dst, src})
sys.lock.Unlock()
@@ -61,12 +60,12 @@ const (
)
type Tmpfile struct {
et state.Enablement
et Enablement
method uint8
dst, src string
}
func (t *Tmpfile) Type() state.Enablement {
func (t *Tmpfile) Type() Enablement {
return t.et
}

View File

@@ -4,7 +4,6 @@ import (
"fmt"
"git.ophivana.moe/cat/fortify/internal/fmsg"
"git.ophivana.moe/cat/fortify/internal/state"
"git.ophivana.moe/cat/fortify/internal/verbose"
"git.ophivana.moe/cat/fortify/xcb"
)
@@ -19,8 +18,8 @@ func (sys *I) ChangeHosts(username string) {
type XHost string
func (x XHost) Type() state.Enablement {
return state.EnableX
func (x XHost) Type() Enablement {
return EX11
}
func (x XHost) apply(_ *I) error {