From aee96b0fdf5e8272f36ee67eecfbf423c0aad0b6 Mon Sep 17 00:00:00 2001 From: Ophestra Umiker Date: Sun, 13 Oct 2024 02:26:01 +0900 Subject: [PATCH] helper/bwrap: allow pushing generic arguments to the end of argument stream Bwrap argument order determines the order their corresponding actions are performed. This allows generic arguments like tmpfs to the end of the stream to override bind mounts. Signed-off-by: Ophestra Umiker --- helper/bwrap/config.go | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/helper/bwrap/config.go b/helper/bwrap/config.go index fffddbe..6fdb08d 100644 --- a/helper/bwrap/config.go +++ b/helper/bwrap/config.go @@ -46,6 +46,9 @@ func (c *Config) Args() (args []string) { } for i, arg := range g { for _, v := range arg { + if v.Later() { + continue + } args = append(args, v.Value(interfaceArgs[i])...) } } @@ -59,6 +62,14 @@ func (c *Config) Args() (args []string) { args = append(args, pairArgs[i], v[0], v[1]) } } + for i, arg := range g { + for _, v := range arg { + if !v.Later() { + continue + } + args = append(args, v.Value(interfaceArgs[i])...) + } + } return } @@ -217,6 +228,7 @@ type TmpfsConfig struct { type argOf interface { Value(arg string) (args []string) + Later() bool } func copyToArgOfSlice[T [2]string | string | TmpfsConfig](src []PermConfig[T]) (dst []argOf) { @@ -228,6 +240,9 @@ func copyToArgOfSlice[T [2]string | string | TmpfsConfig](src []PermConfig[T]) ( } type PermConfig[T [2]string | string | TmpfsConfig] struct { + // append this at the end of the argument stream + Last bool + // set permissions of next argument // (--perms OCTAL) Mode *os.FileMode `json:"mode,omitempty"` @@ -236,6 +251,10 @@ type PermConfig[T [2]string | string | TmpfsConfig] struct { Path T } +func (p PermConfig[T]) Later() bool { + return p.Last +} + func (p PermConfig[T]) Value(arg string) (args []string) { // max possible size if p.Mode != nil {