From e60b110364688cf334ec68e073edf8d9cebc9fcb Mon Sep 17 00:00:00 2001 From: Kris Alder Date: Tue, 3 May 2022 11:05:34 -0700 Subject: pkg/build: refactor cuttlefish image code to embedFiles() Since most of the image mounting code is duplicated, we can instead extract it to an embedFiles() function that takes a callback. The Linux- or Android-specific code can be in the callback. --- pkg/build/linux_linux.go | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) (limited to 'pkg/build/linux_linux.go') diff --git a/pkg/build/linux_linux.go b/pkg/build/linux_linux.go index 4a8270353..55f21a7ee 100644 --- a/pkg/build/linux_linux.go +++ b/pkg/build/linux_linux.go @@ -23,6 +23,17 @@ import ( // - cmdline file is not supported (should be moved to kernel config) // - the kernel is stored in the image in /vmlinuz file. func embedLinuxKernel(params Params, kernelPath string) error { + return embedFiles(params, func(mountDir string) error { + if err := copyKernel(mountDir, kernelPath); err != nil { + return err + } + return nil + }) +} + +// embedFiles mounts the disk image specified by params.UserspaceDir and then calls the given +// callback function which should copy files into the image as needed. +func embedFiles(params Params, callback func(mountDir string) error) error { if params.CmdlineFile != "" { return fmt.Errorf("cmdline file is not supported for linux images") } @@ -51,7 +62,7 @@ func embedLinuxKernel(params Params, kernelPath string) error { return fmt.Errorf("mount(%vp1, %v) failed: %v", loopFile, mountDir, err) } defer unix.Unmount(mountDir, 0) - if err := copyKernel(mountDir, kernelPath); err != nil { + if err := callback(mountDir); err != nil { return err } if params.SysctlFile != "" { -- cgit mrf-deployment