diff options
| author | Ophestra <cat@gensokyo.uk> | 2025-08-16 02:06:41 +0900 |
|---|---|---|
| committer | Ophestra <cat@gensokyo.uk> | 2025-08-16 02:06:41 +0900 |
| commit | 8dd3e1ee5d10c150f58e3b49771d3ca847f6d4cf (patch) | |
| tree | 08c0c6812d34da419cd06323073989fb7b8d0c21 /hst | |
| parent | 4ffeec3004607b76f73e504da220a1490c598348 (diff) | |
hst/fs: rename method Target to Path
This allows adapter structs to use the same field names as Op structs.
Signed-off-by: Ophestra <cat@gensokyo.uk>
Diffstat (limited to 'hst')
| -rw-r--r-- | hst/fs.go | 8 | ||||
| -rw-r--r-- | hst/fs_test.go | 44 | ||||
| -rw-r--r-- | hst/fsbind.go | 36 | ||||
| -rw-r--r-- | hst/fsbind_test.go | 20 | ||||
| -rw-r--r-- | hst/fsephemeral.go | 16 | ||||
| -rw-r--r-- | hst/fsephemeral_test.go | 16 | ||||
| -rw-r--r-- | hst/fsoverlay.go | 16 | ||||
| -rw-r--r-- | hst/fsoverlay_test.go | 26 | ||||
| -rw-r--r-- | hst/template.go | 22 |
9 files changed, 102 insertions, 102 deletions
@@ -13,11 +13,11 @@ import ( type FilesystemConfig interface { // Valid returns whether the configuration is valid. Valid() bool - // Target returns the pathname of the mount point in the container. - Target() *container.Absolute - // Host returns a slice of all host paths used by this mount point. + // Path returns the target path in the container. + Path() *container.Absolute + // Host returns a slice of all host paths used by this operation. Host() []*container.Absolute - // Apply appends the [container.Op] implementing this mount point. + // Apply appends the [container.Op] implementing this operation. Apply(ops *container.Ops) fmt.Stringer diff --git a/hst/fs_test.go b/hst/fs_test.go index c251d070..43825c65 100644 --- a/hst/fs_test.go +++ b/hst/fs_test.go @@ -41,8 +41,8 @@ func TestFilesystemConfigJSON(t *testing.T) { {"bind", hst.FilesystemConfigJSON{ FilesystemConfig: &hst.FSBind{ - Dst: m("/etc"), - Src: m("/mnt/etc"), + Target: m("/etc"), + Source: m("/mnt/etc"), Optional: true, }, }, nil, @@ -51,10 +51,10 @@ func TestFilesystemConfigJSON(t *testing.T) { {"ephemeral", hst.FilesystemConfigJSON{ FilesystemConfig: &hst.FSEphemeral{ - Dst: m("/run/user/65534"), - Write: true, - Size: 1 << 10, - Perm: 0700, + Target: m("/run/user/65534"), + Write: true, + Size: 1 << 10, + Perm: 0700, }, }, nil, `{"type":"ephemeral","dst":"/run/user/65534","write":true,"size":1024,"perm":448}`, @@ -62,10 +62,10 @@ func TestFilesystemConfigJSON(t *testing.T) { {"overlay", hst.FilesystemConfigJSON{ FilesystemConfig: &hst.FSOverlay{ - Dst: m("/nix/store"), - Lower: ms("/mnt-root/nix/.ro-store"), - Upper: m("/mnt-root/nix/.rw-store/upper"), - Work: m("/mnt-root/nix/.rw-store/work"), + Target: m("/nix/store"), + Lower: ms("/mnt-root/nix/.ro-store"), + Upper: m("/mnt-root/nix/.rw-store/upper"), + Work: m("/mnt-root/nix/.rw-store/work"), }, }, nil, `{"type":"overlay","dst":"/nix/store","lower":["/mnt-root/nix/.ro-store"],"upper":"/mnt-root/nix/.rw-store/upper","work":"/mnt-root/nix/.rw-store/work"}`, @@ -159,7 +159,7 @@ func TestFilesystemConfigJSON(t *testing.T) { t.Errorf("Valid: %v, want false", got) } - if got := (&hst.FilesystemConfigJSON{FilesystemConfig: &hst.FSBind{Src: m("/etc")}}).Valid(); !got { + if got := (&hst.FilesystemConfigJSON{FilesystemConfig: &hst.FSBind{Source: m("/etc")}}).Valid(); !got { t.Errorf("Valid: %v, want true", got) } }) @@ -207,7 +207,7 @@ type stubFS struct { } func (s stubFS) Valid() bool { return false } -func (s stubFS) Target() *container.Absolute { panic("unreachable") } +func (s stubFS) Path() *container.Absolute { panic("unreachable") } func (s stubFS) Host() []*container.Absolute { panic("unreachable") } func (s stubFS) Apply(*container.Ops) { panic("unreachable") } func (s stubFS) String() string { return "<invalid " + s.typeName + ">" } @@ -218,13 +218,13 @@ type sCheck struct { } type fsTestCase struct { - name string - fs hst.FilesystemConfig - valid bool - ops container.Ops - target *container.Absolute - host []*container.Absolute - str string + name string + fs hst.FilesystemConfig + valid bool + ops container.Ops + path *container.Absolute + host []*container.Absolute + str string } func checkFs(t *testing.T, testCases []fsTestCase) { @@ -252,9 +252,9 @@ func checkFs(t *testing.T, testCases []fsTestCase) { } }) - t.Run("target", func(t *testing.T) { - if got := tc.fs.Target(); !reflect.DeepEqual(got, tc.target) { - t.Errorf("Target: %q, want %q", got, tc.target) + t.Run("path", func(t *testing.T) { + if got := tc.fs.Path(); !reflect.DeepEqual(got, tc.path) { + t.Errorf("Target: %q, want %q", got, tc.path) } }) diff --git a/hst/fsbind.go b/hst/fsbind.go index beceecb2..c6f4a7ea 100644 --- a/hst/fsbind.go +++ b/hst/fsbind.go @@ -15,9 +15,9 @@ const FilesystemBind = "bind" // FSBind represents a host to container bind mount. type FSBind struct { // mount point in container, same as src if empty - Dst *container.Absolute `json:"dst,omitempty"` + Target *container.Absolute `json:"dst,omitempty"` // host filesystem path to make available to the container - Src *container.Absolute `json:"src"` + Source *container.Absolute `json:"src"` // do not mount filesystem read-only Write bool `json:"write,omitempty"` // do not disable device files, implies Write @@ -26,23 +26,23 @@ type FSBind struct { Optional bool `json:"optional,omitempty"` } -func (b *FSBind) Valid() bool { return b != nil && b.Src != nil } +func (b *FSBind) Valid() bool { return b != nil && b.Source != nil } -func (b *FSBind) Target() *container.Absolute { +func (b *FSBind) Path() *container.Absolute { if !b.Valid() { return nil } - if b.Dst == nil { - return b.Src + if b.Target == nil { + return b.Source } - return b.Dst + return b.Target } func (b *FSBind) Host() []*container.Absolute { if !b.Valid() { return nil } - return []*container.Absolute{b.Src} + return []*container.Absolute{b.Source} } func (b *FSBind) Apply(ops *container.Ops) { @@ -50,9 +50,9 @@ func (b *FSBind) Apply(ops *container.Ops) { return } - dst := b.Dst - if dst == nil { - dst = b.Src + target := b.Target + if target == nil { + target = b.Source } var flags int if b.Write { @@ -64,7 +64,7 @@ func (b *FSBind) Apply(ops *container.Ops) { if b.Optional { flags |= container.BindOptional } - ops.Bind(b.Src, dst, flags) + ops.Bind(b.Source, target, flags) } func (b *FSBind) String() string { @@ -73,9 +73,9 @@ func (b *FSBind) String() string { return "<invalid>" } - g += len(b.Src.String()) - if b.Dst != nil { - g += len(b.Dst.String()) + g += len(b.Source.String()) + if b.Target != nil { + g += len(b.Target.String()) } expr := new(strings.Builder) @@ -93,9 +93,9 @@ func (b *FSBind) String() string { expr.WriteString("+") } - expr.WriteString(b.Src.String()) - if b.Dst != nil { - expr.WriteString(":" + b.Dst.String()) + expr.WriteString(b.Source.String()) + if b.Target != nil { + expr.WriteString(":" + b.Target.String()) } return expr.String() diff --git a/hst/fsbind_test.go b/hst/fsbind_test.go index ce904dfa..21d3640d 100644 --- a/hst/fsbind_test.go +++ b/hst/fsbind_test.go @@ -12,8 +12,8 @@ func TestFSBind(t *testing.T) { {"nil", (*hst.FSBind)(nil), false, nil, nil, nil, "<invalid>"}, {"full", &hst.FSBind{ - Dst: m("/dev"), - Src: m("/mnt/dev"), + Target: m("/dev"), + Source: m("/mnt/dev"), Optional: true, Device: true, }, true, container.Ops{&container.BindMountOp{ @@ -24,8 +24,8 @@ func TestFSBind(t *testing.T) { "d+/mnt/dev:/dev"}, {"full write dev", &hst.FSBind{ - Dst: m("/dev"), - Src: m("/mnt/dev"), + Target: m("/dev"), + Source: m("/mnt/dev"), Write: true, Device: true, }, true, container.Ops{&container.BindMountOp{ @@ -36,9 +36,9 @@ func TestFSBind(t *testing.T) { "d*/mnt/dev:/dev"}, {"full write", &hst.FSBind{ - Dst: m("/tmp"), - Src: m("/mnt/tmp"), - Write: true, + Target: m("/tmp"), + Source: m("/mnt/tmp"), + Write: true, }, true, container.Ops{&container.BindMountOp{ Source: m("/mnt/tmp"), Target: m("/tmp"), @@ -47,8 +47,8 @@ func TestFSBind(t *testing.T) { "w*/mnt/tmp:/tmp"}, {"full no flags", &hst.FSBind{ - Dst: m("/etc"), - Src: m("/mnt/etc"), + Target: m("/etc"), + Source: m("/mnt/etc"), }, true, container.Ops{&container.BindMountOp{ Source: m("/mnt/etc"), Target: m("/etc"), @@ -56,7 +56,7 @@ func TestFSBind(t *testing.T) { "*/mnt/etc:/etc"}, {"nil dst", &hst.FSBind{ - Src: m("/"), + Source: m("/"), }, true, container.Ops{&container.BindMountOp{ Source: m("/"), Target: m("/"), diff --git a/hst/fsephemeral.go b/hst/fsephemeral.go index 0ed50874..424a058d 100644 --- a/hst/fsephemeral.go +++ b/hst/fsephemeral.go @@ -16,7 +16,7 @@ const FilesystemEphemeral = "ephemeral" // FSEphemeral represents an ephemeral container mount point. type FSEphemeral struct { // mount point in container - Dst *container.Absolute `json:"dst,omitempty"` + Target *container.Absolute `json:"dst,omitempty"` // do not mount filesystem read-only Write bool `json:"write,omitempty"` // upper limit on the size of the filesystem @@ -25,13 +25,13 @@ type FSEphemeral struct { Perm os.FileMode `json:"perm,omitempty"` } -func (e *FSEphemeral) Valid() bool { return e != nil && e.Dst != nil } +func (e *FSEphemeral) Valid() bool { return e != nil && e.Target != nil } -func (e *FSEphemeral) Target() *container.Absolute { +func (e *FSEphemeral) Path() *container.Absolute { if !e.Valid() { return nil } - return e.Dst + return e.Target } func (e *FSEphemeral) Host() []*container.Absolute { return nil } @@ -54,9 +54,9 @@ func (e *FSEphemeral) Apply(ops *container.Ops) { } if e.Write { - ops.Tmpfs(e.Dst, size, perm) + ops.Tmpfs(e.Target, size, perm) } else { - ops.Readonly(e.Dst, perm) + ops.Readonly(e.Target, perm) } } @@ -66,7 +66,7 @@ func (e *FSEphemeral) String() string { } expr := new(strings.Builder) - expr.Grow(15 + len(FilesystemEphemeral) + len(e.Dst.String())) + expr.Grow(15 + len(FilesystemEphemeral) + len(e.Target.String())) if e.Write { expr.WriteString("w") @@ -77,7 +77,7 @@ func (e *FSEphemeral) String() string { } else { expr.WriteString(fsEphemeralDefaultPerm.String()) } - expr.WriteString("):" + e.Dst.String()) + expr.WriteString("):" + e.Target.String()) return expr.String() } diff --git a/hst/fsephemeral_test.go b/hst/fsephemeral_test.go index 9286ac44..ed8bbf46 100644 --- a/hst/fsephemeral_test.go +++ b/hst/fsephemeral_test.go @@ -13,10 +13,10 @@ func TestFSEphemeral(t *testing.T) { {"nil", (*hst.FSEphemeral)(nil), false, nil, nil, nil, "<invalid>"}, {"full", &hst.FSEphemeral{ - Dst: m("/run/user/65534"), - Write: true, - Size: 1 << 10, - Perm: 0700, + Target: m("/run/user/65534"), + Write: true, + Size: 1 << 10, + Perm: 0700, }, true, container.Ops{&container.MountTmpfsOp{ FSName: "ephemeral", Path: m("/run/user/65534"), @@ -26,7 +26,7 @@ func TestFSEphemeral(t *testing.T) { }}, m("/run/user/65534"), nil, "w+ephemeral(-rwx------):/run/user/65534"}, - {"cover ro", &hst.FSEphemeral{Dst: m("/run/nscd")}, true, + {"cover ro", &hst.FSEphemeral{Target: m("/run/nscd")}, true, container.Ops{&container.MountTmpfsOp{ FSName: "readonly", Path: m("/run/nscd"), @@ -36,9 +36,9 @@ func TestFSEphemeral(t *testing.T) { "+ephemeral(-rwxr-xr-x):/run/nscd"}, {"negative size", &hst.FSEphemeral{ - Dst: hst.AbsTmp, - Write: true, - Size: -1, + Target: hst.AbsTmp, + Write: true, + Size: -1, }, true, container.Ops{&container.MountTmpfsOp{ FSName: "ephemeral", Path: hst.AbsTmp, diff --git a/hst/fsoverlay.go b/hst/fsoverlay.go index cbf7cd6d..8d63e163 100644 --- a/hst/fsoverlay.go +++ b/hst/fsoverlay.go @@ -15,7 +15,7 @@ const FilesystemOverlay = "overlay" // FSOverlay represents an overlay mount point. type FSOverlay struct { // mount point in container - Dst *container.Absolute `json:"dst"` + Target *container.Absolute `json:"dst"` // any filesystem, does not need to be on a writable filesystem, must not be nil Lower []*container.Absolute `json:"lower"` @@ -26,7 +26,7 @@ type FSOverlay struct { } func (o *FSOverlay) Valid() bool { - if o == nil || o.Dst == nil { + if o == nil || o.Target == nil { return false } @@ -43,11 +43,11 @@ func (o *FSOverlay) Valid() bool { } } -func (o *FSOverlay) Target() *container.Absolute { +func (o *FSOverlay) Path() *container.Absolute { if !o.Valid() { return nil } - return o.Dst + return o.Target } func (o *FSOverlay) Host() []*container.Absolute { @@ -68,9 +68,9 @@ func (o *FSOverlay) Apply(op *container.Ops) { } if o.Upper != nil && o.Work != nil { // rw - op.Overlay(o.Dst, o.Upper, o.Work, o.Lower...) + op.Overlay(o.Target, o.Upper, o.Work, o.Lower...) } else { // ro - op.OverlayReadonly(o.Dst, o.Lower...) + op.OverlayReadonly(o.Target, o.Lower...) } } @@ -86,13 +86,13 @@ func (o *FSOverlay) String() string { if o.Upper != nil && o.Work != nil { return "w*" + strings.Join(append([]string{ - container.EscapeOverlayDataSegment(o.Dst.String()), + container.EscapeOverlayDataSegment(o.Target.String()), container.EscapeOverlayDataSegment(o.Upper.String()), container.EscapeOverlayDataSegment(o.Work.String())}, lower...), container.SpecialOverlayPath) } else { return "*" + strings.Join(append([]string{ - container.EscapeOverlayDataSegment(o.Dst.String())}, + container.EscapeOverlayDataSegment(o.Target.String())}, lower...), container.SpecialOverlayPath) } } diff --git a/hst/fsoverlay_test.go b/hst/fsoverlay_test.go index 18ed0773..8a5732a3 100644 --- a/hst/fsoverlay_test.go +++ b/hst/fsoverlay_test.go @@ -10,16 +10,16 @@ import ( func TestFSOverlay(t *testing.T) { checkFs(t, []fsTestCase{ {"nil", (*hst.FSOverlay)(nil), false, nil, nil, nil, "<invalid>"}, - {"nil lower", &hst.FSOverlay{Dst: m("/etc"), Lower: []*container.Absolute{nil}}, false, nil, nil, nil, "<invalid>"}, - {"zero lower", &hst.FSOverlay{Dst: m("/etc"), Upper: m("/"), Work: m("/")}, false, nil, nil, nil, "<invalid>"}, - {"zero lower ro", &hst.FSOverlay{Dst: m("/etc")}, false, nil, nil, nil, "<invalid>"}, - {"short lower", &hst.FSOverlay{Dst: m("/etc"), Lower: ms("/etc")}, false, nil, nil, nil, "<invalid>"}, + {"nil lower", &hst.FSOverlay{Target: m("/etc"), Lower: []*container.Absolute{nil}}, false, nil, nil, nil, "<invalid>"}, + {"zero lower", &hst.FSOverlay{Target: m("/etc"), Upper: m("/"), Work: m("/")}, false, nil, nil, nil, "<invalid>"}, + {"zero lower ro", &hst.FSOverlay{Target: m("/etc")}, false, nil, nil, nil, "<invalid>"}, + {"short lower", &hst.FSOverlay{Target: m("/etc"), Lower: ms("/etc")}, false, nil, nil, nil, "<invalid>"}, {"full", &hst.FSOverlay{ - Dst: m("/nix/store"), - Lower: ms("/mnt-root/nix/.ro-store"), - Upper: m("/mnt-root/nix/.rw-store/upper"), - Work: m("/mnt-root/nix/.rw-store/work"), + Target: m("/nix/store"), + Lower: ms("/mnt-root/nix/.ro-store"), + Upper: m("/mnt-root/nix/.rw-store/upper"), + Work: m("/mnt-root/nix/.rw-store/work"), }, true, container.Ops{&container.MountOverlayOp{ Target: m("/nix/store"), Lower: ms("/mnt-root/nix/.ro-store"), @@ -29,8 +29,8 @@ func TestFSOverlay(t *testing.T) { "w*/nix/store:/mnt-root/nix/.rw-store/upper:/mnt-root/nix/.rw-store/work:/mnt-root/nix/.ro-store"}, {"ro", &hst.FSOverlay{ - Dst: m("/mnt/src"), - Lower: ms("/tmp/.src0", "/tmp/.src1"), + Target: m("/mnt/src"), + Lower: ms("/tmp/.src0", "/tmp/.src1"), }, true, container.Ops{&container.MountOverlayOp{ Target: m("/mnt/src"), Lower: ms("/tmp/.src0", "/tmp/.src1"), @@ -38,9 +38,9 @@ func TestFSOverlay(t *testing.T) { "*/mnt/src:/tmp/.src0:/tmp/.src1"}, {"ro work", &hst.FSOverlay{ - Dst: m("/mnt/src"), - Lower: ms("/tmp/.src0", "/tmp/.src1"), - Work: m("/tmp"), + Target: m("/mnt/src"), + Lower: ms("/tmp/.src0", "/tmp/.src1"), + Work: m("/tmp"), }, true, container.Ops{&container.MountOverlayOp{ Target: m("/mnt/src"), Lower: ms("/tmp/.src0", "/tmp/.src1"), diff --git a/hst/template.go b/hst/template.go index ea27fbb4..b06e3239 100644 --- a/hst/template.go +++ b/hst/template.go @@ -78,19 +78,19 @@ func Template() *Config { "GOOGLE_DEFAULT_CLIENT_SECRET": "OTJgUOQcT7lO7GsGZq2G4IlT", }, Filesystem: []FilesystemConfigJSON{ - {&FSEphemeral{Dst: container.AbsFHSTmp, Write: true, Perm: 0755}}, + {&FSEphemeral{Target: container.AbsFHSTmp, Write: true, Perm: 0755}}, {&FSOverlay{ - Dst: container.MustAbs("/nix/store"), - Lower: []*container.Absolute{container.MustAbs("/mnt-root/nix/.ro-store")}, - Upper: container.MustAbs("/mnt-root/nix/.rw-store/upper"), - Work: container.MustAbs("/mnt-root/nix/.rw-store/work"), + Target: container.MustAbs("/nix/store"), + Lower: []*container.Absolute{container.MustAbs("/mnt-root/nix/.ro-store")}, + Upper: container.MustAbs("/mnt-root/nix/.rw-store/upper"), + Work: container.MustAbs("/mnt-root/nix/.rw-store/work"), }}, - {&FSBind{Src: container.MustAbs("/nix/store")}}, - {&FSBind{Src: container.AbsFHSRun.Append("current-system")}}, - {&FSBind{Src: container.AbsFHSRun.Append("opengl-driver")}}, - {&FSBind{Src: container.AbsFHSVarLib.Append("hakurei/u0/org.chromium.Chromium"), - Dst: container.MustAbs("/data/data/org.chromium.Chromium"), Write: true}}, - {&FSBind{Src: container.AbsFHSDev.Append("dri"), Device: true, Optional: true}}, + {&FSBind{Source: container.MustAbs("/nix/store")}}, + {&FSBind{Source: container.AbsFHSRun.Append("current-system")}}, + {&FSBind{Source: container.AbsFHSRun.Append("opengl-driver")}}, + {&FSBind{Source: container.AbsFHSVarLib.Append("hakurei/u0/org.chromium.Chromium"), + Target: container.MustAbs("/data/data/org.chromium.Chromium"), Write: true}}, + {&FSBind{Source: container.AbsFHSDev.Append("dri"), Device: true, Optional: true}}, }, Link: []LinkConfig{{container.AbsFHSRunUser.Append("65534"), container.FHSRunUser + "150"}}, AutoRoot: container.AbsFHSVarLib.Append("hakurei/base/org.debian"), |
