MCPcopy Create free account
hub / github.com/aptly-dev/aptly / apiSnapshotsDiff

Function apiSnapshotsDiff

api/snapshot.go:524–572  ·  view source on GitHub ↗

@Summary Snapshot diff @Description **Return the diff between two snapshots (name & withSnapshot)** @Description Provide `onlyMatching=1` to return only packages present in both snapshots. @Description Otherwise, returns a `left` and `right` result providing packages only in the first and second sna

(c *gin.Context)

Source from the content-addressed store, hash-verified

522// @Failure 500 {object} Error "Internal Server Error"
523// @Router /api/snapshots/{name}/diff/{withSnapshot} [get]
524func apiSnapshotsDiff(c *gin.Context) {
525 onlyMatching := c.Request.URL.Query().Get("onlyMatching") == "1"
526
527 collectionFactory := context.NewCollectionFactory()
528 collection := collectionFactory.SnapshotCollection()
529
530 snapshotA, err := collection.ByName(c.Params.ByName("name"))
531 if err != nil {
532 AbortWithJSONError(c, 404, err)
533 return
534 }
535
536 snapshotB, err := collection.ByName(c.Params.ByName("withSnapshot"))
537 if err != nil {
538 AbortWithJSONError(c, 404, err)
539 return
540 }
541
542 err = collection.LoadComplete(snapshotA)
543 if err != nil {
544 AbortWithJSONError(c, 500, err)
545 return
546 }
547
548 err = collection.LoadComplete(snapshotB)
549 if err != nil {
550 AbortWithJSONError(c, 500, err)
551 return
552 }
553
554 // Calculate diff
555 diff, err := snapshotA.RefList().Diff(snapshotB.RefList(), collectionFactory.PackageCollection())
556 if err != nil {
557 AbortWithJSONError(c, 500, err)
558 return
559 }
560
561 result := []deb.PackageDiff{}
562
563 for _, pdiff := range diff {
564 if onlyMatching && (pdiff.Left == nil || pdiff.Right == nil) {
565 continue
566 }
567
568 result = append(result, pdiff)
569 }
570
571 c.JSON(200, result)
572}
573
574// @Summary List Snapshot Packages
575// @Description **List all packages in snapshot or perform search on snapshot contents and return results**

Callers

nothing calls this directly

Calls 10

SnapshotCollectionMethod · 0.95
PackageCollectionMethod · 0.95
AbortWithJSONErrorFunction · 0.85
NewCollectionFactoryMethod · 0.80
DiffMethod · 0.80
GetMethod · 0.65
QueryMethod · 0.65
ByNameMethod · 0.45
LoadCompleteMethod · 0.45
RefListMethod · 0.45

Tested by

no test coverage detected