From e6526ff6ef458cef4fa66ee57220a18f9364c353 Mon Sep 17 00:00:00 2001 From: Matthew Johnson Date: Thu, 8 Mar 2018 13:53:12 -0800 Subject: [PATCH] Add support for adding extra files to a bundle Allow a user to add extra files to a bundle by adding a file per line to //-extra-files. Each file must be an absolute path. At this point the user must manually create the file in the full chroot as well. The workflow for a user adding additional files to a bundle would be this: - mixer build chroots - echo /path/to/bar >> update/image/my-bundle-extra-files - mkdir -p update/image/full/path/to - cp /local/path/to/bar update/image/full/path/to/bar - mixer build update This can definitely be improved in the future but this is a first step that allows additional content on top of what dnf installs. In the rare case that a post-install action for dnf install adds a file, this file would already exist in the full chroot and would not need to be copied in. The user would only need to append the path to that file to the -extra-files file to make sure it is included in that bundle's manifests. Signed-off-by: Matthew Johnson --- swupd/bundleinfo.go | 25 ++++++++++++++++++++++++- swupd/helpers_test.go | 16 ++++++++++++++++ swupd/swupd_test.go | 15 +++++++++++++++ 3 files changed, 55 insertions(+), 1 deletion(-) diff --git a/swupd/bundleinfo.go b/swupd/bundleinfo.go index f99ce9d..493da45 100644 --- a/swupd/bundleinfo.go +++ b/swupd/bundleinfo.go @@ -60,7 +60,30 @@ func (m *Manifest) getBundleInfo(path string) error { return err } - return json.Unmarshal(biBytes, &m.bundleInfo) + err = json.Unmarshal(biBytes, &m.bundleInfo) + if err != nil { + return err + } + + extraFilesPath := filepath.Join(filepath.Dir(path), m.Name+"-extra-files") + if _, err = os.Stat(extraFilesPath); err == nil { + extraFilesBytes, err := ioutil.ReadFile(extraFilesPath) + if err != nil { + return err + } + + for _, f := range strings.Split(string(extraFilesBytes), "\n") { + if len(f) == 0 { + continue + } + if !strings.HasPrefix(f, "/") { + return fmt.Errorf("invalid extra file %s in %s, must start with '/'", f, extraFilesPath) + } + m.bundleInfo.Files[f] = true + } + } + + return nil } func (m *Manifest) addFilesFromBundleInfo(c config, version uint32) error { diff --git a/swupd/helpers_test.go b/swupd/helpers_test.go index c5e4eb1..01e8aaa 100644 --- a/swupd/helpers_test.go +++ b/swupd/helpers_test.go @@ -499,6 +499,22 @@ func (fs *testFileSystem) addDir(version uint32, bundle, dir string) { fs.addToBundleInfo(version, bundle, dir) } +func (fs *testFileSystem) addExtraFile(version uint32, bundle, file, content string) { + fs.t.Helper() + path := filepath.Join(fs.Dir, "image", fmt.Sprint(version), bundle+"-extra-files") + f, err := os.OpenFile(path, os.O_APPEND|os.O_WRONLY|os.O_CREATE, 0644) + if err != nil { + fs.t.Fatal(err) + } + + _, err = f.WriteString(file + "\n") + if err != nil { + fs.t.Fatal(err) + } + + fs.addToFullChroot(version, file, content) +} + func (fs *testFileSystem) addIncludes(version uint32, bundle string, includes []string) { fs.t.Helper() path := filepath.Join(fs.Dir, "image", fmt.Sprint(version), bundle+"-info") diff --git a/swupd/swupd_test.go b/swupd/swupd_test.go index 406a791..cf84f4a 100644 --- a/swupd/swupd_test.go +++ b/swupd/swupd_test.go @@ -186,3 +186,18 @@ func TestFullRunDelta(t *testing.T) { // NOTE: original test checked whether the packs had the manifests inside. This is // not done by new swupd since it seems the client doesn't take advantage of them. } + +func TestAddFilesToBundleInfo(t *testing.T) { + ts := newTestSwupd(t, "extra-files") + defer ts.cleanup() + ts.Bundles = []string{"os-core", "test-bundle"} + ts.addFile(10, "test-bundle", "/foo", "foo content") + ts.addExtraFile(10, "test-bundle", "/bar", "bar content") + ts.addExtraFile(10, "test-bundle", "/baz", "baz content") + ts.createManifests(10) + + m := ts.parseManifest(10, "test-bundle") + fileInManifest(t, m, 10, "/foo") + fileInManifest(t, m, 10, "/bar") + fileInManifest(t, m, 10, "/baz") +}