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

Function apiReposEdit

api/repos.go:219–284  ·  view source on GitHub ↗

@Summary Update Repository @Description **Update local repository meta information** @Tags Repos @Param name path string true "Repository name to modify" @Consume json @Param request body reposEditParams true "Parameters" @Produce json @Success 200 {object} deb.LocalRepo "msg" @Failure 404 {object}

(c *gin.Context)

Source from the content-addressed store, hash-verified

217// @Failure 500 {object} Error "Internal Server Error"
218// @Router /api/repos/{name} [put]
219func apiReposEdit(c *gin.Context) {
220 var b reposEditParams
221 if c.Bind(&b) != nil {
222 return
223 }
224 // Load shallowly for 404 check and resource key.
225 // Mutation and duplicate check happen inside the task for atomicity.
226 collectionFactory := context.NewCollectionFactory()
227 collection := collectionFactory.LocalRepoCollection()
228
229 name := c.Params.ByName("name")
230 repo, err := collection.ByName(name)
231 if err != nil {
232 AbortWithJSONError(c, 404, err)
233 return
234 }
235
236 if b.Name != nil && *b.Name != name {
237 if _, err = collection.ByName(*b.Name); err == nil {
238 AbortWithJSONError(c, 409, fmt.Errorf("unable to rename: local repo %q already exists", *b.Name))
239 return
240 }
241 }
242
243 resources := []string{string(repo.Key())}
244 taskName := fmt.Sprintf("Edit repository %s", name)
245
246 maybeRunTaskInBackground(c, taskName, resources, func(_ aptly.Progress, _ *task.Detail) (*task.ProcessReturnValue, error) {
247 // Task: Create fresh collection inside task after lock
248 taskCollectionFactory := context.NewCollectionFactory()
249 taskCollection := taskCollectionFactory.LocalRepoCollection()
250
251 // Fresh load after lock acquired
252 repo, err := taskCollection.ByName(name)
253 if err != nil {
254 return &task.ProcessReturnValue{Code: http.StatusNotFound, Value: nil}, err
255 }
256
257 // Check and update ATOMIC (inside lock)
258 if b.Name != nil && *b.Name != name {
259 _, err := taskCollection.ByName(*b.Name)
260 if err == nil {
261 // already exists
262 return &task.ProcessReturnValue{Code: http.StatusConflict, Value: nil},
263 fmt.Errorf("local repo with name %q already exists", *b.Name)
264 }
265 repo.Name = *b.Name
266 }
267 if b.Comment != nil {
268 repo.Comment = *b.Comment
269 }
270 if b.DefaultDistribution != nil {
271 repo.DefaultDistribution = *b.DefaultDistribution
272 }
273 if b.DefaultComponent != nil {
274 repo.DefaultComponent = *b.DefaultComponent
275 }
276

Callers

nothing calls this directly

Calls 7

LocalRepoCollectionMethod · 0.95
AbortWithJSONErrorFunction · 0.85
maybeRunTaskInBackgroundFunction · 0.85
NewCollectionFactoryMethod · 0.80
UpdateMethod · 0.65
ByNameMethod · 0.45
KeyMethod · 0.45

Tested by

no test coverage detected