MCPcopy Index your code
hub / github.com/aptly-dev/aptly / apiPublishUpdateSwitch

Function apiPublishUpdateSwitch

api/publish.go:452–608  ·  view source on GitHub ↗

@Summary Update Published Repository @Description **Update a published repository** @Description @Description Update a published local repository or switch snapshot. @Description @Description For published local repositories: @Description * update to match local repository contents @Description @Des

(c *gin.Context)

Source from the content-addressed store, hash-verified

450// @Failure 500 {object} Error "Internal Error"
451// @Router /api/publish/{prefix}/{distribution} [put]
452func apiPublishUpdateSwitch(c *gin.Context) {
453 var b publishedRepoUpdateSwitchParams
454
455 param := slashEscape(c.Params.ByName("prefix"))
456 storage, prefix := deb.ParsePrefix(param)
457 distribution := slashEscape(c.Params.ByName("distribution"))
458
459 if c.Bind(&b) != nil {
460 return
461 }
462
463 signer, err := getSigner(&b.Signing)
464 if err != nil {
465 AbortWithJSONError(c, http.StatusInternalServerError, fmt.Errorf("unable to initialize GPG signer: %s", err))
466 return
467 }
468
469 collectionFactory := context.NewCollectionFactory()
470 collection := collectionFactory.PublishedRepoCollection()
471 snapshotCollection := collectionFactory.SnapshotCollection()
472 localRepoCollection := collectionFactory.LocalRepoCollection()
473
474 published, err := collection.ByStoragePrefixDistribution(storage, prefix, distribution)
475 if err != nil {
476 AbortWithJSONError(c, http.StatusNotFound, fmt.Errorf("unable to update: %s", err))
477 return
478 }
479
480 resources := []string{string(published.Key())}
481
482 if published.SourceKind == deb.SourceLocalRepo {
483 if len(b.Snapshots) > 0 {
484 AbortWithJSONError(c, http.StatusBadRequest, fmt.Errorf("snapshots shouldn't be given when updating local repo"))
485 return
486 }
487 for _, uuid := range published.Sources {
488 repo, err2 := localRepoCollection.ByUUID(uuid)
489 if err2 != nil {
490 AbortWithJSONError(c, http.StatusNotFound, err2)
491 return
492 }
493 resources = append(resources, string(repo.Key()))
494 }
495 } else if published.SourceKind == deb.SourceSnapshot {
496 for _, snapshotInfo := range b.Snapshots {
497 snapshot, err2 := snapshotCollection.ByName(snapshotInfo.Name)
498 if err2 != nil {
499 AbortWithJSONError(c, http.StatusNotFound, err2)
500 return
501 }
502 resources = append(resources, string(snapshot.Key()))
503 }
504 } else {
505 AbortWithJSONError(c, http.StatusInternalServerError, fmt.Errorf("unknown published repository type"))
506 return
507 }
508
509 // Non-MultiDist distributions share a single pool/ directory under the

Callers

nothing calls this directly

Calls 15

SnapshotCollectionMethod · 0.95
LocalRepoCollectionMethod · 0.95
ParsePrefixFunction · 0.92
PrefixPoolLockKeyFunction · 0.92
slashEscapeFunction · 0.85
AbortWithJSONErrorFunction · 0.85
maybeRunTaskInBackgroundFunction · 0.85
NewCollectionFactoryMethod · 0.80
StoragePrefixMethod · 0.80
ObtainRevisionMethod · 0.80

Tested by

no test coverage detected