@Summary Update Mirror @Description **Update Mirror and download packages** @Tags Mirrors @Param name path string true "mirror name to update" @Consume json @Param request body mirrorUpdateParams true "Parameters" @Param _async query bool false "Run in background and return task object" @Produce jso
(c *gin.Context)
| 539 | // @Failure 500 {object} Error "Internal Error" |
| 540 | // @Router /api/mirrors/{name} [put] |
| 541 | func apiMirrorsUpdate(c *gin.Context) { |
| 542 | var ( |
| 543 | err error |
| 544 | remote *deb.RemoteRepo |
| 545 | b mirrorUpdateParams |
| 546 | ) |
| 547 | |
| 548 | collectionFactory := context.NewCollectionFactory() |
| 549 | collection := collectionFactory.RemoteRepoCollection() |
| 550 | |
| 551 | name := c.Params.ByName("name") |
| 552 | remote, err = collection.ByName(name) |
| 553 | if err != nil { |
| 554 | AbortWithJSONError(c, 404, err) |
| 555 | return |
| 556 | } |
| 557 | |
| 558 | b.Name = remote.Name |
| 559 | b.IgnoreSignatures = context.Config().GpgDisableVerify |
| 560 | |
| 561 | log.Info().Msgf("%s: Starting mirror update", b.Name) |
| 562 | |
| 563 | if c.Bind(&b) != nil { |
| 564 | return |
| 565 | } |
| 566 | |
| 567 | // Pre-task validation of new name if provided |
| 568 | if b.Name != remote.Name { |
| 569 | _, err = collection.ByName(b.Name) |
| 570 | if err == nil { |
| 571 | AbortWithJSONError(c, 409, fmt.Errorf("unable to rename: mirror %s already exists", b.Name)) |
| 572 | return |
| 573 | } |
| 574 | } |
| 575 | |
| 576 | verifier, err := getVerifier(b.Keyrings) |
| 577 | if err != nil { |
| 578 | AbortWithJSONError(c, 400, fmt.Errorf("unable to initialize GPG verifier: %s", err)) |
| 579 | return |
| 580 | } |
| 581 | |
| 582 | resources := []string{string(remote.Key())} |
| 583 | maybeRunTaskInBackground(c, "Update mirror "+b.Name, resources, func(out aptly.Progress, detail *task.Detail) (*task.ProcessReturnValue, error) { |
| 584 | // Phase 2: Inside task lock - create fresh factory |
| 585 | taskCollectionFactory := context.NewCollectionFactory() |
| 586 | taskCollection := taskCollectionFactory.RemoteRepoCollection() |
| 587 | |
| 588 | // Fresh load after lock acquired (use captured `name` variable, not gin context) |
| 589 | remote, err := taskCollection.ByName(name) |
| 590 | if err != nil { |
| 591 | return &task.ProcessReturnValue{Code: http.StatusInternalServerError, Value: nil}, fmt.Errorf("unable to update: %s", err) |
| 592 | } |
| 593 | |
| 594 | // Fresh rename check inside lock (if renaming) |
| 595 | if b.Name != remote.Name { |
| 596 | _, err := taskCollection.ByName(b.Name) |
| 597 | if err == nil { |
| 598 | return &task.ProcessReturnValue{Code: http.StatusConflict, Value: nil}, fmt.Errorf("unable to rename: mirror %s already exists", b.Name) |
nothing calls this directly
no test coverage detected