diff --git a/api/snapshot.go b/api/snapshot.go index a9061eb1..3256242d 100644 --- a/api/snapshot.go +++ b/api/snapshot.go @@ -209,24 +209,37 @@ func apiSnapshotsCreate(c *gin.Context) { } } - list := deb.NewPackageList() - - // verify package refs and build package list using fresh factory - for _, ref := range b.PackageRefs { - p, err := taskPackageCollection.ByKey([]byte(ref)) - if err != nil { - if err == database.ErrNotFound { - return &task.ProcessReturnValue{Code: http.StatusNotFound, Value: nil}, fmt.Errorf("package %s: %s", ref, err) - } - return &task.ProcessReturnValue{Code: http.StatusInternalServerError, Value: nil}, err - } - err = list.Add(p) - if err != nil { - return &task.ProcessReturnValue{Code: http.StatusBadRequest, Value: nil}, err + // Merge packages from all source snapshots + var refList *deb.PackageRefList + if len(freshSources) > 0 { + refList = freshSources[0].RefList() + for i := 1; i < len(freshSources); i++ { + refList = refList.Merge(freshSources[i].RefList(), true, false) } + } else { + refList = deb.NewPackageRefList() } - snapshot = deb.NewSnapshotFromRefList(b.Name, freshSources, deb.NewPackageRefListFromPackageList(list), b.Description) + // Add any explicitly specified package refs on top + if len(b.PackageRefs) > 0 { + list := deb.NewPackageList() + for _, ref := range b.PackageRefs { + p, err := taskPackageCollection.ByKey([]byte(ref)) + if err != nil { + if err == database.ErrNotFound { + return &task.ProcessReturnValue{Code: http.StatusNotFound, Value: nil}, fmt.Errorf("package %s: %s", ref, err) + } + return &task.ProcessReturnValue{Code: http.StatusInternalServerError, Value: nil}, err + } + err = list.Add(p) + if err != nil { + return &task.ProcessReturnValue{Code: http.StatusBadRequest, Value: nil}, err + } + } + refList = refList.Merge(deb.NewPackageRefListFromPackageList(list), true, false) + } + + snapshot = deb.NewSnapshotFromRefList(b.Name, freshSources, refList, b.Description) err = taskSnapshotCollection.Add(snapshot) if err != nil { diff --git a/system/t12_api/publish.py b/system/t12_api/publish.py index a9d5cf0d..cd92f775 100644 --- a/system/t12_api/publish.py +++ b/system/t12_api/publish.py @@ -1207,11 +1207,10 @@ class PublishSwitchAPITestSnapshot(APITest): self.check_equal(all_repos.status_code, 200) self.check_in(repo_expected, all_repos.json()) - # FIXME: what should exist here ? publish snapshot of snapshot self.check_not_exists( "public/" + prefix + "/pool/main/b/boost-defaults/libboost-program-options-dev_1.49.0.1_i386.deb") - self.check_not_exists("public/" + prefix + - "/pool/main/p/pyspi/pyspi-0.6.1-1.3.stripped.dsc") + self.check_exists("public/" + prefix + + "/pool/main/p/pyspi/pyspi-0.6.1-1.3.stripped.dsc") task = self.delete_task("/api/publish/" + prefix + "/wheezy") self.check_task(task)