[pm][snapshot] Deny packages with duplicate paths
Packages are not allowed to map more than one blob to a path within the
package. Detect and report malformed blobs.json inputs.
Test: manual
Change-Id: I59fb5a5496c923589cc20ce8180d7e8827013821
diff --git a/go/src/pm/cmd/pm/snapshot/snapshot.go b/go/src/pm/cmd/pm/snapshot/snapshot.go
index e3b72f3..4a8b8eb 100644
--- a/go/src/pm/cmd/pm/snapshot/snapshot.go
+++ b/go/src/pm/cmd/pm/snapshot/snapshot.go
@@ -152,6 +152,14 @@
return nil, err
}
+ packagePaths := make(map[string]struct{})
+ for _, blob := range members {
+ if _, ok := packagePaths[blob.Path]; ok {
+ return nil, fmt.Errorf("%q contains more than one entry with path = %q", path, blob.Path)
+ }
+ packagePaths[blob.Path] = struct{}{}
+ }
+
return members, nil
}
@@ -209,7 +217,7 @@
}
}
- return snapshot, nil
+ return snapshot, snapshot.Verify()
}
// Run executes the snapshot command