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 <cat@ophivana.moe>
This commit is contained in:
2024-10-13 02:26:01 +09:00
parent 655020eb5d
commit aee96b0fdf

View File

@@ -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 {