From 50fd3928d8fee90d8a902223deaaa3fd414c2933 Mon Sep 17 00:00:00 2001 From: John Akre Date: Wed, 4 Mar 2020 15:21:42 -0800 Subject: [PATCH] Install special case files last When adding special case files to the full chroot, they will create missing directories in their path with permissions that may conflict with content that will be added at a later point. By adding special case files last, they will not create directories with potentially conflicting permissions. Fixes #738 Signed-off-by: John Akre --- builder/bundles.go | 53 +++++++++++++++++++++++++++------------------- 1 file changed, 31 insertions(+), 22 deletions(-) diff --git a/builder/bundles.go b/builder/bundles.go index b412c91..4cb8eee 100644 --- a/builder/bundles.go +++ b/builder/bundles.go @@ -759,13 +759,7 @@ func installBundleToFull(packagerCmd []string, baseDir string, bundle *bundle, d return <-errorCh } - bundleDir := filepath.Join(baseDir, "usr/share/clear/bundles") - err = os.MkdirAll(filepath.Join(bundleDir), 0755) - if err != nil { - return err - } - - return ioutil.WriteFile(filepath.Join(bundleDir, bundle.Name), nil, 0644) + return nil } func clearDNFCache(packagerCmd []string) error { @@ -841,26 +835,41 @@ func buildFullChroot(b *Builder, set *bundleSet, packagerCmd []string, buildVers if err := installBundleToFull(packagerCmd, fullDir, bundle, downloadRetries, numWorkers, b.repos); err != nil { return err } - // special handling for os-core - if bundle.Name == "os-core" { - fmt.Println("... building special os-core content") - if err := buildOsCore(b, packagerCmd, fullDir, version); err != nil { - return err - } - } - // special handling for update bundle - if bundle.Name == b.Config.Swupd.Bundle { - fmt.Printf("... Adding swupd default values to %s bundle\n", bundle.Name) - if err := genUpdateBundleSpecialFiles(fullDir, b); err != nil { - return err - } - } } // Resolve bundle content chroots against the full chroot. New files are copied // to the full chroot and the bundle file lists are updated to contain the files // within the chroot. - return addBundleContentChroots(set, fullDir) + if err = addBundleContentChroots(set, fullDir); err != nil { + return err + } + + return installSpecialFilesToFull(b, packagerCmd, set, fullDir, version) +} + +// installSpecialFilesToFull installs the bundle tracking files and installs special case files for the +// os-core and update bundles. +func installSpecialFilesToFull(b *Builder, packagerCmd []string, set *bundleSet, fullDir, version string) error { + // bundle tracking files + bundleDir := filepath.Join(fullDir, "usr/share/clear/bundles") + if err := os.MkdirAll(bundleDir, 0755); err != nil { + return err + } + for _, bundle := range *set { + if err := ioutil.WriteFile(filepath.Join(bundleDir, bundle.Name), nil, 0644); err != nil { + return err + } + } + + // special handling for os-core + fmt.Println("... building special os-core content") + if err := buildOsCore(b, packagerCmd, fullDir, version); err != nil { + return err + } + + // special handling for update bundle + fmt.Printf("... Adding swupd default values to %s bundle\n", b.Config.Swupd.Bundle) + return genUpdateBundleSpecialFiles(fullDir, b) } // addBundleContentChroots resolves each bundle's content choots against the full chroot