diff options
| author | Ophestra Umiker <cat@ophivana.moe> | 2024-10-16 14:38:57 +0900 |
|---|---|---|
| committer | Ophestra Umiker <cat@ophivana.moe> | 2024-10-16 14:38:57 +0900 |
| commit | c21168a74181903535c63f49c5a6d3bd2052c883 (patch) | |
| tree | 6ed272c6a4d3712624077cf39794d7d1eb22295f /internal/system | |
| parent | 084cd84f36a1d608541b4aa4e1e95334395d8953 (diff) | |
system: move enablements from state package
This removes the unnecessary import of the state package.
Signed-off-by: Ophestra Umiker <cat@ophivana.moe>
Diffstat (limited to 'internal/system')
| -rw-r--r-- | internal/system/acl.go | 7 | ||||
| -rw-r--r-- | internal/system/dbus.go | 3 | ||||
| -rw-r--r-- | internal/system/enablement.go | 46 | ||||
| -rw-r--r-- | internal/system/mkdir.go | 7 | ||||
| -rw-r--r-- | internal/system/op.go | 14 | ||||
| -rw-r--r-- | internal/system/tmpfiles.go | 11 | ||||
| -rw-r--r-- | internal/system/xhost.go | 5 |
7 files changed, 66 insertions, 27 deletions
diff --git a/internal/system/acl.go b/internal/system/acl.go index 9c89752b..9fc047f0 100644 --- a/internal/system/acl.go +++ b/internal/system/acl.go @@ -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 } diff --git a/internal/system/dbus.go b/internal/system/dbus.go index 3e4a6e65..21b8cef7 100644 --- a/internal/system/dbus.go +++ b/internal/system/dbus.go @@ -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 } diff --git a/internal/system/enablement.go b/internal/system/enablement.go new file mode 100644 index 00000000..7876f6b5 --- /dev/null +++ b/internal/system/enablement.go @@ -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() +} diff --git a/internal/system/mkdir.go b/internal/system/mkdir.go index 2c303630..9733b056 100644 --- a/internal/system/mkdir.go +++ b/internal/system/mkdir.go @@ -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 } diff --git a/internal/system/op.go b/internal/system/op.go index c3f93cdb..a9040187 100644 --- a/internal/system/op.go +++ b/internal/system/op.go @@ -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" diff --git a/internal/system/tmpfiles.go b/internal/system/tmpfiles.go index 2a9f724a..ba25e077 100644 --- a/internal/system/tmpfiles.go +++ b/internal/system/tmpfiles.go @@ -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 } diff --git a/internal/system/xhost.go b/internal/system/xhost.go index 2cdddd56..40914756 100644 --- a/internal/system/xhost.go +++ b/internal/system/xhost.go @@ -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 { |
