aboutsummaryrefslogtreecommitdiffstats
path: root/pkg/build/linux_linux.go
diff options
context:
space:
mode:
authorKris Alder <kalder@google.com>2022-05-03 11:05:34 -0700
committerDmitry Vyukov <dvyukov@google.com>2022-05-06 08:59:20 +0200
commite60b110364688cf334ec68e073edf8d9cebc9fcb (patch)
treee10026e4c1246c6b4d7206da4a7cd3acbff8343e /pkg/build/linux_linux.go
parentabda9b1a98d331fa672f556e33f18df2eed424bd (diff)
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.
Diffstat (limited to 'pkg/build/linux_linux.go')
-rw-r--r--pkg/build/linux_linux.go13
1 files changed, 12 insertions, 1 deletions
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 != "" {