From 1fa5e992e4e73fd6f1774544e07655b88f9c83d6 Mon Sep 17 00:00:00 2001 From: Ophestra Date: Sun, 16 Feb 2025 12:33:59 +0900 Subject: [PATCH] helper/bwrap: expose address of DataConfig This allows the caller to defer fulfilling its payload. Signed-off-by: Ophestra --- helper/bwrap/builder.go | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/helper/bwrap/builder.go b/helper/bwrap/builder.go index d196bc0..e6685aa 100644 --- a/helper/bwrap/builder.go +++ b/helper/bwrap/builder.go @@ -78,11 +78,22 @@ CopyBind(dest, payload, true) copy from FD to file which is bind-mounted on DEST (--bind-data FD DEST) */ func (c *Config) CopyBind(dest string, payload []byte, opts ...bool) *Config { + var p *[]byte + c.CopyBindRef(dest, &p, opts...) + *p = payload + return c +} + +// CopyBindRef is the same as CopyBind but writes the address of DataConfig.Data. +func (c *Config) CopyBindRef(dest string, payloadRef **[]byte, opts ...bool) *Config { t := DataROBind if len(opts) > 0 && opts[0] { t = DataBind } - c.Filesystem = append(c.Filesystem, &DataConfig{Dest: dest, Data: payload, Type: t}) + d := &DataConfig{Dest: dest, Type: t} + *payloadRef = &d.Data + + c.Filesystem = append(c.Filesystem, d) return c }