aboutsummaryrefslogtreecommitdiffhomepage
path: root/hst/fsbind.go
diff options
context:
space:
mode:
authorOphestra <cat@gensokyo.uk>2025-08-25 18:30:40 +0900
committerOphestra <cat@gensokyo.uk>2025-08-25 18:38:19 +0900
commit6d202d73b41d28166f7bea7da36d1ce054711ff9 (patch)
tree8af4f9212fe7c3c49c8035119e8a4405e2c97070 /hst/fsbind.go
parent1438096339f49bdd466f3b057c7e695aa126fc3c (diff)
hst/fsbind: optional autoetc behaviour
This generalises the special field allowing any special behaviour to be matched from target. Signed-off-by: Ophestra <cat@gensokyo.uk>
Diffstat (limited to 'hst/fsbind.go')
-rw-r--r--hst/fsbind.go68
1 files changed, 50 insertions, 18 deletions
diff --git a/hst/fsbind.go b/hst/fsbind.go
index 50e8da56..496453b3 100644
--- a/hst/fsbind.go
+++ b/hst/fsbind.go
@@ -25,17 +25,38 @@ type FSBind struct {
// skip this mount point if the host path does not exist
Optional bool `json:"optional,omitempty"`
- // enable autoroot behaviour;
- // this requires Target to be [container.AbsFHSRoot].
- AutoRoot bool `json:"autoroot,omitempty"`
+ // enable special behaviour:
+ // for autoroot, Target must be set to [container.AbsFHSRoot];
+ // for autoetc, Target must be set to [container.AbsFHSEtc]
+ Special bool `json:"special,omitempty"`
+}
+
+// IsAutoRoot returns whether this FSBind has autoroot behaviour enabled.
+func (b *FSBind) IsAutoRoot() bool {
+ return b.Valid() && b.Special && b.Target.String() == container.FHSRoot
+}
+
+// IsAutoEtc returns whether this FSBind has autoetc behaviour enabled.
+func (b *FSBind) IsAutoEtc() bool {
+ return b.Valid() && b.Special && b.Target.String() == container.FHSEtc
}
func (b *FSBind) Valid() bool {
if b == nil || b.Source == nil {
return false
}
- if b.AutoRoot && (b.Target == nil || b.Target.String() != container.FHSRoot) {
- return false
+ if b.Special {
+ if b.Target == nil {
+ return false
+ } else {
+ switch b.Target.String() {
+ case container.FHSRoot, container.FHSEtc:
+ break
+
+ default:
+ return false
+ }
+ }
}
return true
}
@@ -57,7 +78,7 @@ func (b *FSBind) Host() []*container.Absolute {
return []*container.Absolute{b.Source}
}
-func (b *FSBind) Apply(ops *container.Ops) {
+func (b *FSBind) Apply(z *ApplyState) {
if !b.Valid() {
return
}
@@ -77,10 +98,15 @@ func (b *FSBind) Apply(ops *container.Ops) {
flags |= container.BindOptional
}
- if !b.AutoRoot {
- ops.Bind(b.Source, target, flags)
- } else {
- ops.Root(b.Source, flags)
+ switch {
+ case b.IsAutoRoot():
+ z.Root(b.Source, flags)
+
+ case b.IsAutoEtc():
+ z.Etc(b.Source, z.AutoEtcPrefix)
+
+ default:
+ z.Bind(b.Source, target, flags)
}
}
@@ -96,15 +122,21 @@ func (b *FSBind) String() string {
flagSym = "w"
}
- if b.AutoRoot {
- prefix := "autoroot"
- if flagSym != "" {
- prefix += ":" + flagSym
- }
- if b.Source.String() != container.FHSRoot {
- return prefix + ":" + b.Source.String()
+ if b.Special {
+ switch {
+ case b.IsAutoRoot():
+ prefix := "autoroot"
+ if flagSym != "" {
+ prefix += ":" + flagSym
+ }
+ if b.Source.String() != container.FHSRoot {
+ return prefix + ":" + b.Source.String()
+ }
+ return prefix
+
+ case b.IsAutoEtc():
+ return "autoetc:" + b.Source.String()
}
- return prefix
}
g := 4 + len(b.Source.String())