diff options
| author | Ophestra <cat@gensokyo.uk> | 2025-08-21 00:18:50 +0900 |
|---|---|---|
| committer | Ophestra <cat@gensokyo.uk> | 2025-08-21 00:18:50 +0900 |
| commit | 5d8a2199b6c8dc5f75b529a39d196c6cb14c98c2 (patch) | |
| tree | 5ad693466483081342b24df929365490015b4efa /container/autoroot.go | |
| parent | a1482ecdd0f98728f4b97137cd7b2fa17f67bb89 (diff) | |
container/init: op interface valid method
Check ops early and eliminate duplicate checks.
Signed-off-by: Ophestra <cat@gensokyo.uk>
Diffstat (limited to 'container/autoroot.go')
| -rw-r--r-- | container/autoroot.go | 13 |
1 files changed, 6 insertions, 7 deletions
diff --git a/container/autoroot.go b/container/autoroot.go index a7a3f33c..0de6bce7 100644 --- a/container/autoroot.go +++ b/container/autoroot.go @@ -28,11 +28,9 @@ type AutoRootOp struct { resolved []Op } -func (r *AutoRootOp) early(state *setupState) error { - if r.Host == nil { - return syscall.EBADE - } +func (r *AutoRootOp) Valid() bool { return r != nil && r.Host != nil } +func (r *AutoRootOp) early(state *setupState) error { if d, err := os.ReadDir(r.Host.String()); err != nil { return wrapErrSelf(err) } else { @@ -72,9 +70,10 @@ func (r *AutoRootOp) apply(state *setupState) error { func (r *AutoRootOp) Is(op Op) bool { vr, ok := op.(*AutoRootOp) - return ok && ((r == nil && vr == nil) || (r != nil && vr != nil && - r.Host != nil && vr.Host != nil && r.Host.Is(vr.Host) && - r.Prefix == vr.Prefix && r.Flags == vr.Flags)) + return ok && r.Valid() && vr.Valid() && + r.Host.Is(vr.Host) && + r.Prefix == vr.Prefix && + r.Flags == vr.Flags } func (*AutoRootOp) prefix() string { return "setting up" } func (r *AutoRootOp) String() string { |
