message: relocate from container
All checks were successful
Test / Create distribution (push) Successful in 35s
Test / Sandbox (push) Successful in 2m22s
Test / Hpkg (push) Successful in 4m2s
Test / Sandbox (race detector) (push) Successful in 4m28s
Test / Hakurei (race detector) (push) Successful in 5m21s
Test / Hakurei (push) Successful in 2m9s
Test / Flake checks (push) Successful in 1m29s
All checks were successful
Test / Create distribution (push) Successful in 35s
Test / Sandbox (push) Successful in 2m22s
Test / Hpkg (push) Successful in 4m2s
Test / Sandbox (race detector) (push) Successful in 4m28s
Test / Hakurei (race detector) (push) Successful in 5m21s
Test / Hakurei (push) Successful in 2m9s
Test / Flake checks (push) Successful in 1m29s
This package is quite useful. This change allows it to be imported without importing container. Signed-off-by: Ophestra <cat@gensokyo.uk>
This commit is contained in:
@@ -11,8 +11,8 @@ import (
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"hakurei.app/container"
|
||||
"hakurei.app/helper"
|
||||
"hakurei.app/message"
|
||||
"hakurei.app/system/dbus"
|
||||
)
|
||||
|
||||
@@ -93,9 +93,9 @@ func testProxyFinaliseStartWaitCloseString(t *testing.T, useSandbox bool) {
|
||||
|
||||
t.Run("invalid start", func(t *testing.T) {
|
||||
if !useSandbox {
|
||||
p = dbus.NewDirect(t.Context(), container.NewMsg(nil), nil, nil)
|
||||
p = dbus.NewDirect(t.Context(), message.NewMsg(nil), nil, nil)
|
||||
} else {
|
||||
p = dbus.New(t.Context(), container.NewMsg(nil), nil, nil)
|
||||
p = dbus.New(t.Context(), message.NewMsg(nil), nil, nil)
|
||||
}
|
||||
|
||||
if err := p.Start(); !errors.Is(err, syscall.ENOTRECOVERABLE) {
|
||||
@@ -128,9 +128,9 @@ func testProxyFinaliseStartWaitCloseString(t *testing.T, useSandbox bool) {
|
||||
defer cancel()
|
||||
output := new(strings.Builder)
|
||||
if !useSandbox {
|
||||
p = dbus.NewDirect(ctx, container.NewMsg(nil), final, output)
|
||||
p = dbus.NewDirect(ctx, message.NewMsg(nil), final, output)
|
||||
} else {
|
||||
p = dbus.New(ctx, container.NewMsg(nil), final, output)
|
||||
p = dbus.New(ctx, message.NewMsg(nil), final, output)
|
||||
}
|
||||
|
||||
t.Run("invalid wait", func(t *testing.T) {
|
||||
|
||||
@@ -4,11 +4,11 @@ import (
|
||||
"context"
|
||||
"io"
|
||||
|
||||
"hakurei.app/container"
|
||||
"hakurei.app/message"
|
||||
)
|
||||
|
||||
// NewDirect returns a new instance of [Proxy] with its sandbox disabled.
|
||||
func NewDirect(ctx context.Context, msg container.Msg, final *Final, output io.Writer) *Proxy {
|
||||
func NewDirect(ctx context.Context, msg message.Msg, final *Final, output io.Writer) *Proxy {
|
||||
p := New(ctx, msg, final, output)
|
||||
p.useSandbox = false
|
||||
return p
|
||||
|
||||
@@ -6,9 +6,9 @@ import (
|
||||
"sync"
|
||||
"syscall"
|
||||
|
||||
"hakurei.app/container"
|
||||
"hakurei.app/helper"
|
||||
"hakurei.app/hst"
|
||||
"hakurei.app/message"
|
||||
)
|
||||
|
||||
// ProxyName is the file name or path to the proxy program.
|
||||
@@ -19,7 +19,7 @@ var ProxyName = "xdg-dbus-proxy"
|
||||
type Proxy struct {
|
||||
helper helper.Helper
|
||||
ctx context.Context
|
||||
msg container.Msg
|
||||
msg message.Msg
|
||||
|
||||
cancel context.CancelCauseFunc
|
||||
cause func() error
|
||||
@@ -100,6 +100,6 @@ func Finalise(sessionBus, systemBus ProxyPair, session, system *hst.BusConfig) (
|
||||
}
|
||||
|
||||
// New returns a new instance of [Proxy].
|
||||
func New(ctx context.Context, msg container.Msg, final *Final, output io.Writer) *Proxy {
|
||||
func New(ctx context.Context, msg message.Msg, final *Final, output io.Writer) *Proxy {
|
||||
return &Proxy{name: ProxyName, ctx: ctx, msg: msg, final: final, output: output, useSandbox: true}
|
||||
}
|
||||
|
||||
@@ -6,6 +6,7 @@ import (
|
||||
"os"
|
||||
|
||||
"hakurei.app/container"
|
||||
"hakurei.app/message"
|
||||
)
|
||||
|
||||
// OpError is returned by [I.Commit] and [I.Revert].
|
||||
@@ -70,14 +71,14 @@ func printJoinedError(println func(v ...any), fallback string, err error) {
|
||||
error
|
||||
}
|
||||
if !errors.As(err, &joinErr) {
|
||||
if m, ok := container.GetErrorMessage(err); ok {
|
||||
if m, ok := message.GetMessage(err); ok {
|
||||
println(m)
|
||||
} else {
|
||||
println(fallback, err)
|
||||
}
|
||||
} else {
|
||||
for _, err = range joinErr.Unwrap() {
|
||||
if m, ok := container.GetErrorMessage(err); ok {
|
||||
if m, ok := message.GetMessage(err); ok {
|
||||
println(m)
|
||||
} else {
|
||||
println(err.Error())
|
||||
|
||||
@@ -9,6 +9,7 @@ import (
|
||||
"testing"
|
||||
|
||||
"hakurei.app/container"
|
||||
"hakurei.app/message"
|
||||
)
|
||||
|
||||
func TestOpError(t *testing.T) {
|
||||
@@ -64,13 +65,13 @@ func TestOpError(t *testing.T) {
|
||||
})
|
||||
|
||||
t.Run("msg", func(t *testing.T) {
|
||||
if got, ok := container.GetErrorMessage(tc.err); !ok {
|
||||
if got, ok := message.GetMessage(tc.err); !ok {
|
||||
if tc.msg != "" {
|
||||
t.Errorf("GetErrorMessage: err does not implement MessageError")
|
||||
t.Errorf("GetMessage: err does not implement MessageError")
|
||||
}
|
||||
return
|
||||
} else if got != tc.msg {
|
||||
t.Errorf("GetErrorMessage: %q, want %q", got, tc.msg)
|
||||
t.Errorf("GetMessage: %q, want %q", got, tc.msg)
|
||||
}
|
||||
})
|
||||
})
|
||||
|
||||
@@ -6,8 +6,8 @@ import (
|
||||
"errors"
|
||||
"strings"
|
||||
|
||||
"hakurei.app/container"
|
||||
"hakurei.app/hst"
|
||||
"hakurei.app/message"
|
||||
)
|
||||
|
||||
const (
|
||||
@@ -68,7 +68,7 @@ func TypeString(e hst.Enablement) string {
|
||||
}
|
||||
|
||||
// New returns the address of a new [I] targeting uid.
|
||||
func New(ctx context.Context, msg container.Msg, uid int) (sys *I) {
|
||||
func New(ctx context.Context, msg message.Msg, uid int) (sys *I) {
|
||||
if ctx == nil || msg == nil || uid < 0 {
|
||||
panic("invalid call to New")
|
||||
}
|
||||
@@ -89,7 +89,7 @@ type I struct {
|
||||
// the behaviour of Revert is only defined for up to one call
|
||||
reverted bool
|
||||
|
||||
msg container.Msg
|
||||
msg message.Msg
|
||||
syscallDispatcher
|
||||
}
|
||||
|
||||
|
||||
@@ -8,10 +8,10 @@ import (
|
||||
"strconv"
|
||||
"testing"
|
||||
|
||||
"hakurei.app/container"
|
||||
"hakurei.app/container/check"
|
||||
"hakurei.app/container/stub"
|
||||
"hakurei.app/hst"
|
||||
"hakurei.app/message"
|
||||
"hakurei.app/system/internal/xcb"
|
||||
)
|
||||
|
||||
@@ -74,7 +74,7 @@ func TestNew(t *testing.T) {
|
||||
t.Errorf("recover: %v, want %v", r, want)
|
||||
}
|
||||
}()
|
||||
New(nil, container.NewMsg(nil), 0)
|
||||
New(nil, message.NewMsg(nil), 0)
|
||||
})
|
||||
|
||||
t.Run("msg", func(t *testing.T) {
|
||||
@@ -94,11 +94,11 @@ func TestNew(t *testing.T) {
|
||||
t.Errorf("recover: %v, want %v", r, want)
|
||||
}
|
||||
}()
|
||||
New(t.Context(), container.NewMsg(nil), -1)
|
||||
New(t.Context(), message.NewMsg(nil), -1)
|
||||
})
|
||||
})
|
||||
|
||||
sys := New(t.Context(), container.NewMsg(nil), 0xdeadbeef)
|
||||
sys := New(t.Context(), message.NewMsg(nil), 0xdeadbeef)
|
||||
if sys.ctx == nil {
|
||||
t.Error("New: ctx = nil")
|
||||
}
|
||||
@@ -115,51 +115,51 @@ func TestEqual(t *testing.T) {
|
||||
want bool
|
||||
}{
|
||||
{"simple UID",
|
||||
New(t.Context(), container.NewMsg(nil), 150),
|
||||
New(t.Context(), container.NewMsg(nil), 150),
|
||||
New(t.Context(), message.NewMsg(nil), 150),
|
||||
New(t.Context(), message.NewMsg(nil), 150),
|
||||
true},
|
||||
|
||||
{"simple UID differ",
|
||||
New(t.Context(), container.NewMsg(nil), 150),
|
||||
New(t.Context(), container.NewMsg(nil), 151),
|
||||
New(t.Context(), message.NewMsg(nil), 150),
|
||||
New(t.Context(), message.NewMsg(nil), 151),
|
||||
false},
|
||||
|
||||
{"simple UID nil",
|
||||
New(t.Context(), container.NewMsg(nil), 150),
|
||||
New(t.Context(), message.NewMsg(nil), 150),
|
||||
nil,
|
||||
false},
|
||||
|
||||
{"op length mismatch",
|
||||
New(t.Context(), container.NewMsg(nil), 150).
|
||||
New(t.Context(), message.NewMsg(nil), 150).
|
||||
ChangeHosts("chronos"),
|
||||
New(t.Context(), container.NewMsg(nil), 150).
|
||||
New(t.Context(), message.NewMsg(nil), 150).
|
||||
ChangeHosts("chronos").
|
||||
Ensure(m("/run"), 0755),
|
||||
false},
|
||||
|
||||
{"op value mismatch",
|
||||
New(t.Context(), container.NewMsg(nil), 150).
|
||||
New(t.Context(), message.NewMsg(nil), 150).
|
||||
ChangeHosts("chronos").
|
||||
Ensure(m("/run"), 0644),
|
||||
New(t.Context(), container.NewMsg(nil), 150).
|
||||
New(t.Context(), message.NewMsg(nil), 150).
|
||||
ChangeHosts("chronos").
|
||||
Ensure(m("/run"), 0755),
|
||||
false},
|
||||
|
||||
{"op type mismatch",
|
||||
New(t.Context(), container.NewMsg(nil), 150).
|
||||
New(t.Context(), message.NewMsg(nil), 150).
|
||||
ChangeHosts("chronos").
|
||||
CopyFile(new([]byte), m("/home/ophestra/xdg/config/pulse/cookie"), 0, 256),
|
||||
New(t.Context(), container.NewMsg(nil), 150).
|
||||
New(t.Context(), message.NewMsg(nil), 150).
|
||||
ChangeHosts("chronos").
|
||||
Ensure(m("/run"), 0755),
|
||||
false},
|
||||
|
||||
{"op equals",
|
||||
New(t.Context(), container.NewMsg(nil), 150).
|
||||
New(t.Context(), message.NewMsg(nil), 150).
|
||||
ChangeHosts("chronos").
|
||||
Ensure(m("/run"), 0755),
|
||||
New(t.Context(), container.NewMsg(nil), 150).
|
||||
New(t.Context(), message.NewMsg(nil), 150).
|
||||
ChangeHosts("chronos").
|
||||
Ensure(m("/run"), 0755),
|
||||
true},
|
||||
|
||||
Reference in New Issue
Block a user