@Summary Copy Package @Description Copies a package from a source to destination repository @Tags Repos @Param name path string true "Destination repo" @Param src path string true "Source repo" @Param file path string true "File/packages to copy" @Param _async query bool false "Run in background and
(c *gin.Context)
| 718 | // @Failure 500 {object} Error "Internal Server Error" |
| 719 | // @Router /api/repos/{name}/copy/{src}/{file} [post] |
| 720 | func apiReposCopyPackage(c *gin.Context) { |
| 721 | dstRepoName := c.Params.ByName("name") |
| 722 | srcRepoName := c.Params.ByName("src") |
| 723 | fileName := c.Params.ByName("file") |
| 724 | |
| 725 | jsonBody := reposCopyPackageParams{ |
| 726 | WithDeps: false, |
| 727 | DryRun: false, |
| 728 | } |
| 729 | |
| 730 | err := c.Bind(&jsonBody) |
| 731 | if err != nil { |
| 732 | return |
| 733 | } |
| 734 | |
| 735 | // Load shallowly for 404 check and resource keys. |
| 736 | // Full load and mutations happen inside the task. |
| 737 | collectionFactory := context.NewCollectionFactory() |
| 738 | dstRepo, err := collectionFactory.LocalRepoCollection().ByName(dstRepoName) |
| 739 | if err != nil { |
| 740 | AbortWithJSONError(c, http.StatusBadRequest, fmt.Errorf("dest repo error: %s", err)) |
| 741 | return |
| 742 | } |
| 743 | |
| 744 | var srcRepo *deb.LocalRepo |
| 745 | srcRepo, err = collectionFactory.LocalRepoCollection().ByName(srcRepoName) |
| 746 | if err != nil { |
| 747 | AbortWithJSONError(c, http.StatusBadRequest, fmt.Errorf("src repo error: %s", err)) |
| 748 | return |
| 749 | } |
| 750 | |
| 751 | if srcRepo.UUID == dstRepo.UUID { |
| 752 | AbortWithJSONError(c, http.StatusBadRequest, fmt.Errorf("dest and source are identical")) |
| 753 | return |
| 754 | } |
| 755 | |
| 756 | taskName := fmt.Sprintf("Copy packages from repo %s to repo %s", srcRepoName, dstRepoName) |
| 757 | resources := []string{string(dstRepo.Key()), string(srcRepo.Key())} |
| 758 | |
| 759 | maybeRunTaskInBackground(c, taskName, resources, func(_ aptly.Progress, _ *task.Detail) (*task.ProcessReturnValue, error) { |
| 760 | // Task: Create fresh factory and collections inside task after lock |
| 761 | taskCollectionFactory := context.NewCollectionFactory() |
| 762 | |
| 763 | // Fresh load of both repos after lock acquired |
| 764 | dstRepo, err := taskCollectionFactory.LocalRepoCollection().ByName(dstRepoName) |
| 765 | if err != nil { |
| 766 | return &task.ProcessReturnValue{Code: http.StatusBadRequest, Value: nil}, fmt.Errorf("dest repo error: %s", err) |
| 767 | } |
| 768 | |
| 769 | srcRepo, err := taskCollectionFactory.LocalRepoCollection().ByName(srcRepoName) |
| 770 | if err != nil { |
| 771 | return &task.ProcessReturnValue{Code: http.StatusBadRequest, Value: nil}, fmt.Errorf("src repo error: %s", err) |
| 772 | } |
| 773 | |
| 774 | err = taskCollectionFactory.LocalRepoCollection().LoadComplete(dstRepo) |
| 775 | if err != nil { |
| 776 | return &task.ProcessReturnValue{Code: http.StatusBadRequest, Value: nil}, fmt.Errorf("dest repo error: %s", err) |
| 777 | } |
nothing calls this directly
no test coverage detected