container: repeat and impossible state types
All checks were successful
Test / Create distribution (push) Successful in 34s
Test / Sandbox (push) Successful in 1m45s
Test / Hakurei (push) Successful in 3m18s
Test / Hpkg (push) Successful in 3m35s
Test / Sandbox (race detector) (push) Successful in 3m57s
Test / Hakurei (race detector) (push) Successful in 5m13s
Test / Flake checks (push) Successful in 1m36s
All checks were successful
Test / Create distribution (push) Successful in 34s
Test / Sandbox (push) Successful in 1m45s
Test / Hakurei (push) Successful in 3m18s
Test / Hpkg (push) Successful in 3m35s
Test / Sandbox (race detector) (push) Successful in 3m57s
Test / Hakurei (race detector) (push) Successful in 5m13s
Test / Flake checks (push) Successful in 1m36s
This moves repeated Op errors and impossible internal state errors off of msg. Signed-off-by: Ophestra <cat@gensokyo.uk>
This commit is contained in:
parent
84ad9791e2
commit
a462341a0a
@ -3,7 +3,6 @@ package container
|
|||||||
import (
|
import (
|
||||||
"encoding/gob"
|
"encoding/gob"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io/fs"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
func init() { gob.Register(new(AutoEtcOp)) }
|
func init() { gob.Register(new(AutoEtcOp)) }
|
||||||
@ -24,7 +23,7 @@ func (e *AutoEtcOp) Valid() bool { return e != ni
|
|||||||
func (e *AutoEtcOp) early(*setupState, syscallDispatcher) error { return nil }
|
func (e *AutoEtcOp) early(*setupState, syscallDispatcher) error { return nil }
|
||||||
func (e *AutoEtcOp) apply(state *setupState, k syscallDispatcher) error {
|
func (e *AutoEtcOp) apply(state *setupState, k syscallDispatcher) error {
|
||||||
if state.nonrepeatable&nrAutoEtc != 0 {
|
if state.nonrepeatable&nrAutoEtc != 0 {
|
||||||
return msg.WrapErr(fs.ErrInvalid, "autoetc is not repeatable")
|
return OpRepeatError("autoetc")
|
||||||
}
|
}
|
||||||
state.nonrepeatable |= nrAutoEtc
|
state.nonrepeatable |= nrAutoEtc
|
||||||
|
|
||||||
|
@ -2,14 +2,13 @@ package container
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"errors"
|
"errors"
|
||||||
"io/fs"
|
|
||||||
"os"
|
"os"
|
||||||
"testing"
|
"testing"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestAutoEtcOp(t *testing.T) {
|
func TestAutoEtcOp(t *testing.T) {
|
||||||
t.Run("nonrepeatable", func(t *testing.T) {
|
t.Run("nonrepeatable", func(t *testing.T) {
|
||||||
wantErr := msg.WrapErr(fs.ErrInvalid, "autoetc is not repeatable")
|
wantErr := OpRepeatError("autoetc")
|
||||||
if err := (&AutoEtcOp{Prefix: "81ceabb30d37bbdb3868004629cb84e9"}).apply(&setupState{nonrepeatable: nrAutoEtc}, nil); !errors.Is(err, wantErr) {
|
if err := (&AutoEtcOp{Prefix: "81ceabb30d37bbdb3868004629cb84e9"}).apply(&setupState{nonrepeatable: nrAutoEtc}, nil); !errors.Is(err, wantErr) {
|
||||||
t.Errorf("apply: error = %v, want %v", err, wantErr)
|
t.Errorf("apply: error = %v, want %v", err, wantErr)
|
||||||
}
|
}
|
||||||
|
@ -3,7 +3,6 @@ package container
|
|||||||
import (
|
import (
|
||||||
"encoding/gob"
|
"encoding/gob"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io/fs"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
func init() { gob.Register(new(AutoRootOp)) }
|
func init() { gob.Register(new(AutoRootOp)) }
|
||||||
@ -53,7 +52,7 @@ func (r *AutoRootOp) early(state *setupState, k syscallDispatcher) error {
|
|||||||
|
|
||||||
func (r *AutoRootOp) apply(state *setupState, k syscallDispatcher) error {
|
func (r *AutoRootOp) apply(state *setupState, k syscallDispatcher) error {
|
||||||
if state.nonrepeatable&nrAutoRoot != 0 {
|
if state.nonrepeatable&nrAutoRoot != 0 {
|
||||||
return msg.WrapErr(fs.ErrInvalid, "autoroot is not repeatable")
|
return OpRepeatError("autoroot")
|
||||||
}
|
}
|
||||||
state.nonrepeatable |= nrAutoRoot
|
state.nonrepeatable |= nrAutoRoot
|
||||||
|
|
||||||
|
@ -2,14 +2,13 @@ package container
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"errors"
|
"errors"
|
||||||
"io/fs"
|
|
||||||
"os"
|
"os"
|
||||||
"testing"
|
"testing"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestAutoRootOp(t *testing.T) {
|
func TestAutoRootOp(t *testing.T) {
|
||||||
t.Run("nonrepeatable", func(t *testing.T) {
|
t.Run("nonrepeatable", func(t *testing.T) {
|
||||||
wantErr := msg.WrapErr(fs.ErrInvalid, "autoroot is not repeatable")
|
wantErr := OpRepeatError("autoroot")
|
||||||
if err := new(AutoRootOp).apply(&setupState{nonrepeatable: nrAutoRoot}, nil); !errors.Is(err, wantErr) {
|
if err := new(AutoRootOp).apply(&setupState{nonrepeatable: nrAutoRoot}, nil); !errors.Is(err, wantErr) {
|
||||||
t.Errorf("apply: error = %v, want %v", err, wantErr)
|
t.Errorf("apply: error = %v, want %v", err, wantErr)
|
||||||
}
|
}
|
||||||
|
@ -68,6 +68,16 @@ const (
|
|||||||
nrAutoRoot
|
nrAutoRoot
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// OpRepeatError is returned applying a repeated nonrepeatable [Op].
|
||||||
|
type OpRepeatError string
|
||||||
|
|
||||||
|
func (e OpRepeatError) Error() string { return string(e) + " is not repeatable" }
|
||||||
|
|
||||||
|
// OpStateError indicates an impossible internal state has been reached in an [Op].
|
||||||
|
type OpStateError string
|
||||||
|
|
||||||
|
func (o OpStateError) Error() string { return "impossible " + string(o) + " state reached" }
|
||||||
|
|
||||||
// initParams are params passed from parent.
|
// initParams are params passed from parent.
|
||||||
type initParams struct {
|
type initParams struct {
|
||||||
Params
|
Params
|
||||||
|
@ -63,7 +63,7 @@ func (b *BindMountOp) apply(_ *setupState, k syscallDispatcher) error {
|
|||||||
if b.sourceFinal == nil {
|
if b.sourceFinal == nil {
|
||||||
if b.Flags&BindOptional == 0 {
|
if b.Flags&BindOptional == 0 {
|
||||||
// unreachable
|
// unreachable
|
||||||
return msg.WrapErr(os.ErrClosed, "impossible bind state reached")
|
return OpStateError("bind")
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
@ -143,7 +143,7 @@ func TestBindMountOp(t *testing.T) {
|
|||||||
|
|
||||||
t.Run("unreachable", func(t *testing.T) {
|
t.Run("unreachable", func(t *testing.T) {
|
||||||
t.Run("nil sourceFinal not optional", func(t *testing.T) {
|
t.Run("nil sourceFinal not optional", func(t *testing.T) {
|
||||||
wantErr := msg.WrapErr(os.ErrClosed, "impossible bind state reached")
|
wantErr := OpStateError("bind")
|
||||||
if err := new(BindMountOp).apply(nil, nil); !errors.Is(err, wantErr) {
|
if err := new(BindMountOp).apply(nil, nil); !errors.Is(err, wantErr) {
|
||||||
t.Errorf("apply: error = %v, want %v", err, wantErr)
|
t.Errorf("apply: error = %v, want %v", err, wantErr)
|
||||||
}
|
}
|
||||||
|
@ -97,7 +97,7 @@ func (o *MountOverlayOp) early(_ *setupState, k syscallDispatcher) error {
|
|||||||
if !o.ephemeral {
|
if !o.ephemeral {
|
||||||
if o.Upper != o.Work && (o.Upper == nil || o.Work == nil) {
|
if o.Upper != o.Work && (o.Upper == nil || o.Work == nil) {
|
||||||
// unreachable
|
// unreachable
|
||||||
return msg.WrapErr(fs.ErrClosed, "impossible overlay state reached")
|
return OpStateError("overlay")
|
||||||
}
|
}
|
||||||
|
|
||||||
if o.Upper != nil {
|
if o.Upper != nil {
|
||||||
|
@ -242,7 +242,7 @@ func TestMountOverlayOp(t *testing.T) {
|
|||||||
|
|
||||||
t.Run("unreachable", func(t *testing.T) {
|
t.Run("unreachable", func(t *testing.T) {
|
||||||
t.Run("nil Upper non-nil Work not ephemeral", func(t *testing.T) {
|
t.Run("nil Upper non-nil Work not ephemeral", func(t *testing.T) {
|
||||||
wantErr := msg.WrapErr(fs.ErrClosed, "impossible overlay state reached")
|
wantErr := OpStateError("overlay")
|
||||||
if err := (&MountOverlayOp{
|
if err := (&MountOverlayOp{
|
||||||
Work: MustAbs("/"),
|
Work: MustAbs("/"),
|
||||||
}).early(nil, nil); !errors.Is(err, wantErr) {
|
}).early(nil, nil); !errors.Is(err, wantErr) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user