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/initbind.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/initbind.go')
| -rw-r--r-- | container/initbind.go | 14 |
1 files changed, 6 insertions, 8 deletions
diff --git a/container/initbind.go b/container/initbind.go index 0b34851e..e19cb5de 100644 --- a/container/initbind.go +++ b/container/initbind.go @@ -24,6 +24,8 @@ type BindMountOp struct { Flags int } +func (b *BindMountOp) Valid() bool { return b != nil && b.Source != nil && b.Target != nil } + const ( // BindOptional skips nonexistent host paths. BindOptional = 1 << iota @@ -34,10 +36,6 @@ const ( ) func (b *BindMountOp) early(*setupState) error { - if b.Source == nil || b.Target == nil { - return EBADE - } - if pathname, err := filepath.EvalSymlinks(b.Source.String()); err != nil { if os.IsNotExist(err) && b.Flags&BindOptional != 0 { // leave sourceFinal as nil @@ -87,10 +85,10 @@ func (b *BindMountOp) apply(*setupState) error { func (b *BindMountOp) Is(op Op) bool { vb, ok := op.(*BindMountOp) - return ok && ((b == nil && vb == nil) || (b != nil && vb != nil && - b.Source != nil && vb.Source != nil && b.Source.Is(vb.Source) && - b.Target != nil && vb.Target != nil && b.Target.Is(vb.Target) && - b.Flags == vb.Flags)) + return ok && b.Valid() && vb.Valid() && + b.Source.Is(vb.Source) && + b.Target.Is(vb.Target) && + b.Flags == vb.Flags } func (*BindMountOp) prefix() string { return "mounting" } func (b *BindMountOp) String() string { |
