@Summary Include Directory @Description Allows automatic processing of .changes file controlling package upload (uploaded using File Upload API) to the local repository. i.e. Exposes repo include command in api. @Tags Repos @Param name path string true "Repository name" @Param dir path string true "
(c *gin.Context)
| 914 | // @Failure 404 {object} Error "Not Found" |
| 915 | // @Router /api/repos/{name}/include/{dir} [post] |
| 916 | func apiReposIncludePackageFromDir(c *gin.Context) { |
| 917 | forceReplace := c.Request.URL.Query().Get("forceReplace") == "1" |
| 918 | noRemoveFiles := c.Request.URL.Query().Get("noRemoveFiles") == "1" |
| 919 | acceptUnsigned := c.Request.URL.Query().Get("acceptUnsigned") == "1" |
| 920 | ignoreSignature := c.Request.URL.Query().Get("ignoreSignature") == "1" |
| 921 | |
| 922 | repoTemplateString := c.Params.ByName("name") |
| 923 | collectionFactory := context.NewCollectionFactory() |
| 924 | |
| 925 | if !verifyDir(c) { |
| 926 | return |
| 927 | } |
| 928 | |
| 929 | var sources []string |
| 930 | var taskName string |
| 931 | dirParam := utils.SanitizePath(c.Params.ByName("dir")) |
| 932 | fileParam := utils.SanitizePath(c.Params.ByName("file")) |
| 933 | if fileParam != "" && !verifyPath(fileParam) { |
| 934 | AbortWithJSONError(c, 400, fmt.Errorf("wrong file")) |
| 935 | return |
| 936 | } |
| 937 | |
| 938 | if fileParam == "" { |
| 939 | taskName = fmt.Sprintf("Include packages from changes files in dir %s to repo matching template %s", dirParam, repoTemplateString) |
| 940 | sources = []string{filepath.Join(context.UploadPath(), dirParam)} |
| 941 | } else { |
| 942 | taskName = fmt.Sprintf("Include packages from changes file %s from dir %s to repo matching template %s", fileParam, dirParam, repoTemplateString) |
| 943 | sources = []string{filepath.Join(context.UploadPath(), dirParam, fileParam)} |
| 944 | } |
| 945 | |
| 946 | repoTemplate, err := template.New("repo").Parse(repoTemplateString) |
| 947 | if err != nil { |
| 948 | AbortWithJSONError(c, 400, fmt.Errorf("error parsing repo template: %s", err)) |
| 949 | return |
| 950 | } |
| 951 | |
| 952 | var resources []string |
| 953 | if len(repoTemplate.Root.Nodes) > 1 { |
| 954 | resources = append(resources, task.AllLocalReposResourcesKey) |
| 955 | } else { |
| 956 | // repo template string is simple text so only use resource key of specific repository |
| 957 | repo, err := collectionFactory.LocalRepoCollection().ByName(repoTemplateString) |
| 958 | if err != nil { |
| 959 | AbortWithJSONError(c, 404, err) |
| 960 | return |
| 961 | } |
| 962 | |
| 963 | resources = append(resources, string(repo.Key())) |
| 964 | } |
| 965 | resources = append(resources, sources...) |
| 966 | |
| 967 | maybeRunTaskInBackground(c, taskName, resources, func(out aptly.Progress, _ *task.Detail) (*task.ProcessReturnValue, error) { |
| 968 | // Task: Create fresh factory and collection inside task after lock |
| 969 | taskCollectionFactory := context.NewCollectionFactory() |
| 970 | |
| 971 | var ( |
| 972 | err error |
| 973 | verifier = context.GetVerifier() |
no test coverage detected