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") +}