container/init: op interface valid method
All checks were successful
Test / Create distribution (push) Successful in 34s
Test / Sandbox (push) Successful in 2m10s
Test / Hakurei (push) Successful in 3m12s
Test / Hpkg (push) Successful in 3m58s
Test / Sandbox (race detector) (push) Successful in 4m19s
Test / Hakurei (race detector) (push) Successful in 4m57s
Test / Flake checks (push) Successful in 1m25s
All checks were successful
Test / Create distribution (push) Successful in 34s
Test / Sandbox (push) Successful in 2m10s
Test / Hakurei (push) Successful in 3m12s
Test / Hpkg (push) Successful in 3m58s
Test / Sandbox (race detector) (push) Successful in 4m19s
Test / Hakurei (race detector) (push) Successful in 4m57s
Test / Flake checks (push) Successful in 1m25s
Check ops early and eliminate duplicate checks. Signed-off-by: Ophestra <cat@gensokyo.uk>
This commit is contained in:
@@ -53,10 +53,10 @@ type MountOverlayOp struct {
|
||||
lower []string
|
||||
// The upperdir is normally on a writable filesystem.
|
||||
//
|
||||
// If Work is nil and Upper holds the special value [FHSRoot],
|
||||
// If Work is nil and Upper holds the special value [AbsFHSRoot],
|
||||
// an ephemeral upperdir and workdir will be set up.
|
||||
//
|
||||
// If both Work and Upper are empty strings, upperdir and workdir is omitted and the overlay is mounted readonly.
|
||||
// If both Work and Upper are nil, upperdir and workdir is omitted and the overlay is mounted readonly.
|
||||
Upper *Absolute
|
||||
// formatted for [OptionOverlayUpperdir], resolved, prefixed and escaped during early
|
||||
upper string
|
||||
@@ -68,6 +68,19 @@ type MountOverlayOp struct {
|
||||
ephemeral bool
|
||||
}
|
||||
|
||||
func (o *MountOverlayOp) Valid() bool {
|
||||
if o == nil {
|
||||
return false
|
||||
}
|
||||
if o.Work != nil && o.Upper == nil {
|
||||
return false
|
||||
}
|
||||
if slices.Contains(o.Lower, nil) {
|
||||
return false
|
||||
}
|
||||
return o.Target != nil
|
||||
}
|
||||
|
||||
func (o *MountOverlayOp) early(*setupState) error {
|
||||
if o.Work == nil && o.Upper != nil {
|
||||
switch o.Upper.String() {
|
||||
@@ -104,11 +117,7 @@ func (o *MountOverlayOp) early(*setupState) error {
|
||||
}
|
||||
|
||||
o.lower = make([]string, len(o.Lower))
|
||||
for i, a := range o.Lower {
|
||||
if a == nil {
|
||||
return EBADE
|
||||
}
|
||||
|
||||
for i, a := range o.Lower { // nil checked in Valid
|
||||
if v, err := filepath.EvalSymlinks(a.String()); err != nil {
|
||||
return wrapErrSelf(err)
|
||||
} else {
|
||||
@@ -119,9 +128,6 @@ func (o *MountOverlayOp) early(*setupState) error {
|
||||
}
|
||||
|
||||
func (o *MountOverlayOp) apply(state *setupState) error {
|
||||
if o.Target == nil {
|
||||
return EBADE
|
||||
}
|
||||
target := toSysroot(o.Target.String())
|
||||
if err := os.MkdirAll(target, state.ParentPerm); err != nil {
|
||||
return wrapErrSelf(err)
|
||||
@@ -163,10 +169,10 @@ func (o *MountOverlayOp) apply(state *setupState) error {
|
||||
|
||||
func (o *MountOverlayOp) Is(op Op) bool {
|
||||
vo, ok := op.(*MountOverlayOp)
|
||||
return ok && ((o == nil && vo == nil) || (o != nil && vo != nil &&
|
||||
o.Target != nil && vo.Target != nil && o.Target.Is(vo.Target) &&
|
||||
return ok && o.Valid() && vo.Valid() &&
|
||||
o.Target.Is(vo.Target) &&
|
||||
slices.EqualFunc(o.Lower, vo.Lower, func(a *Absolute, v *Absolute) bool { return a.Is(v) }) &&
|
||||
o.Upper.Is(vo.Upper) && o.Work.Is(vo.Work)))
|
||||
o.Upper.Is(vo.Upper) && o.Work.Is(vo.Work)
|
||||
}
|
||||
func (*MountOverlayOp) prefix() string { return "mounting" }
|
||||
func (o *MountOverlayOp) String() string {
|
||||
|
||||
Reference in New Issue
Block a user