@Summary Add Uploaded Directory @Description Import packages from files (uploaded using File Upload API) to the local repository. If directory specified, aptly would discover package files automatically. @Description Adding same package to local repository is not an error. @Description By default ap
(c *gin.Context)
| 567 | // @Failure 500 {object} Error "Error adding files" |
| 568 | // @Router /api/repos/{name}/file/{dir} [post] |
| 569 | func apiReposPackageFromDir(c *gin.Context) { |
| 570 | forceReplace := c.Request.URL.Query().Get("forceReplace") == "1" |
| 571 | noRemove := c.Request.URL.Query().Get("noRemove") == "1" |
| 572 | |
| 573 | if !verifyDir(c) { |
| 574 | return |
| 575 | } |
| 576 | |
| 577 | dirParam := utils.SanitizePath(c.Params.ByName("dir")) |
| 578 | fileParam := utils.SanitizePath(c.Params.ByName("file")) |
| 579 | if fileParam != "" && !verifyPath(fileParam) { |
| 580 | AbortWithJSONError(c, 400, fmt.Errorf("wrong file")) |
| 581 | return |
| 582 | } |
| 583 | |
| 584 | // Load shallowly for 404 check and resource key. |
| 585 | // Full load and mutations happen inside the task. |
| 586 | collectionFactory := context.NewCollectionFactory() |
| 587 | collection := collectionFactory.LocalRepoCollection() |
| 588 | |
| 589 | name := c.Params.ByName("name") |
| 590 | repo, err := collection.ByName(name) |
| 591 | if err != nil { |
| 592 | AbortWithJSONError(c, 404, err) |
| 593 | return |
| 594 | } |
| 595 | |
| 596 | var taskName string |
| 597 | var sources []string |
| 598 | if fileParam == "" { |
| 599 | taskName = fmt.Sprintf("Add packages from dir %s to repo %s", dirParam, name) |
| 600 | sources = []string{filepath.Join(context.UploadPath(), dirParam)} |
| 601 | } else { |
| 602 | sources = []string{filepath.Join(context.UploadPath(), dirParam, fileParam)} |
| 603 | taskName = fmt.Sprintf("Add package %s from dir %s to repo %s", fileParam, dirParam, name) |
| 604 | } |
| 605 | |
| 606 | resources := []string{string(repo.Key())} |
| 607 | resources = append(resources, sources...) |
| 608 | maybeRunTaskInBackground(c, taskName, resources, func(out aptly.Progress, _ *task.Detail) (*task.ProcessReturnValue, error) { |
| 609 | // Task: Create fresh factory and collection inside task after lock |
| 610 | taskCollectionFactory := context.NewCollectionFactory() |
| 611 | taskCollection := taskCollectionFactory.LocalRepoCollection() |
| 612 | |
| 613 | // Fresh load after lock acquired |
| 614 | repo, err := taskCollection.ByName(name) |
| 615 | if err != nil { |
| 616 | return &task.ProcessReturnValue{Code: http.StatusInternalServerError, Value: nil}, err |
| 617 | } |
| 618 | |
| 619 | err = taskCollection.LoadComplete(repo) |
| 620 | if err != nil { |
| 621 | return &task.ProcessReturnValue{Code: http.StatusInternalServerError, Value: nil}, err |
| 622 | } |
| 623 | |
| 624 | verifier := context.GetVerifier() |
| 625 | |
| 626 | var ( |
no test coverage detected