diff --git a/snapshot/manager.go b/snapshot/manager.go index e1cea3b9b..d5f33d0ba 100644 --- a/snapshot/manager.go +++ b/snapshot/manager.go @@ -123,6 +123,10 @@ func SaveSnapshot(ctx context.Context, rep repo.RepositoryWriter, man *Manifest) return "", errors.New("missing path") } + // clear manifest ID in case it was set, since we'll be generating a new one and we don't want + // to write previous ID in JSON. + man.ID = "" + id, err := rep.PutManifest(ctx, sourceInfoToLabels(man.Source), man) if err != nil { return "", errors.Wrap(err, "error putting manifest") diff --git a/snapshot/manifest.go b/snapshot/manifest.go index 1f50cdbbd..8ceacc214 100644 --- a/snapshot/manifest.go +++ b/snapshot/manifest.go @@ -15,7 +15,7 @@ import ( // Manifest represents information about a single point-in-time filesystem snapshot. type Manifest struct { - ID manifest.ID `json:"-"` + ID manifest.ID `json:"id"` Source SourceInfo `json:"source"` Description string `json:"description"` diff --git a/tests/end_to_end_test/snapshot_create_test.go b/tests/end_to_end_test/snapshot_create_test.go index e4ee157a0..7106a951a 100644 --- a/tests/end_to_end_test/snapshot_create_test.go +++ b/tests/end_to_end_test/snapshot_create_test.go @@ -46,10 +46,22 @@ func TestSnapshotCreate(t *testing.T) { mustParseJSONLines(t, e.RunAndExpectSuccess(t, "snapshot", "create", sharedTestDataDir2, "--json"), &man1) mustParseJSONLines(t, e.RunAndExpectSuccess(t, "snapshot", "create", sharedTestDataDir2, "--json"), &man2) + if man1.ID == "" { + t.Fatalf("missing root id") + } + + if man2.ID == "" { + t.Fatalf("missing root id") + } + if man1.RootEntry.ObjectID == "" { t.Fatalf("missing root id") } + if man1.ID == man2.ID { + t.Fatalf("unexpectedly identical snapshot IDs: %v", man1.ID) + } + if man1.RootEntry.ObjectID != man2.RootEntry.ObjectID { t.Fatalf("unexpected difference in root objects %v vs %v", man1.RootEntry.ObjectID, man2.RootEntry.ObjectID) }