From bf455d9788ca437fee0bde2065eb9d85e9051c6b Mon Sep 17 00:00:00 2001 From: Mikhail Klementev Date: Thu, 6 Apr 2023 14:48:12 +0000 Subject: [PATCH] Copy from inside the container to avoid permission problems --- kernel.go | 31 ++++++++++++------------------- 1 file changed, 12 insertions(+), 19 deletions(-) diff --git a/kernel.go b/kernel.go index f6e385f..944484e 100644 --- a/kernel.go +++ b/kernel.go @@ -374,20 +374,6 @@ func generateBaseDockerImage(registry string, commands []config.DockerCommand, return } -func copyDirContent(source, target string) (err error) { - files, err := ioutil.ReadDir(source) - if err != nil { - return - } - if len(files) != 0 { - _, err = sh(source, "cp -r * "+target+"/") - if err != nil { - return - } - } - return -} - func installKernel(sk config.KernelMask, pkgname string, force, headers bool) (err error) { tmpdir, err := os.MkdirTemp("", "out-of-tree-"+pkgname+"-") if err != nil { @@ -475,15 +461,22 @@ func installKernel(sk config.KernelMask, pkgname string, force, headers bool) (e return } - err = copyDirContent(c.Volumes.LibModules, volumes.LibModules) + c.Args = append(c.Args, "-v", volumes.LibModules+":/target/lib/modules") + c.Args = append(c.Args, "-v", volumes.UsrSrc+":/target/usr/src") + c.Args = append(c.Args, "-v", volumes.Boot+":/target/boot") + + cmd := "cp -r /lib/modules/* /target/lib/modules/" + + " && cp -r /boot/* /target/boot/" + + files, err := ioutil.ReadDir(c.Volumes.UsrSrc) if err != nil { return } - err = copyDirContent(c.Volumes.UsrSrc, volumes.UsrSrc) - if err != nil { - return + if len(files) != 0 { + cmd += " && cp -r /usr/src/* /target/usr/src/" } - err = copyDirContent(c.Volumes.Boot, volumes.Boot) + + _, err = c.Run("/tmp", cmd) if err != nil { return }