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

Function apiReposDrop

api/repos.go:321–366  ·  view source on GitHub ↗

@Summary Delete Repository @Description Drop/delete a repo @Description Cannot drop repos that are published. @Description Needs force=1 to drop repos used as source by other repos. @Tags Repos @Param name path string true "Repository name" @Param _async query bool false "Run in background and retur

(c *gin.Context)

Source from the content-addressed store, hash-verified

319// @Failure 404 {object} Error "Repo Conflict"
320// @Router /api/repos/{name} [delete]
321func apiReposDrop(c *gin.Context) {
322 force := c.Request.URL.Query().Get("force") == "1"
323 name := c.Params.ByName("name")
324
325 // Load shallowly for 404 check, resource key, and task name.
326 // Full checks (published/snapshots) happen inside the task.
327 collectionFactory := context.NewCollectionFactory()
328 collection := collectionFactory.LocalRepoCollection()
329
330 repo, err := collection.ByName(name)
331 if err != nil {
332 AbortWithJSONError(c, 404, err)
333 return
334 }
335
336 resources := []string{string(repo.Key())}
337 taskName := fmt.Sprintf("Delete repo %s", name)
338 maybeRunTaskInBackground(c, taskName, resources, func(_ aptly.Progress, _ *task.Detail) (*task.ProcessReturnValue, error) {
339 // Task: Create fresh collections inside task after lock acquired
340 taskCollectionFactory := context.NewCollectionFactory()
341 taskCollection := taskCollectionFactory.LocalRepoCollection()
342 taskSnapshotCollection := taskCollectionFactory.SnapshotCollection()
343 taskPublishedCollection := taskCollectionFactory.PublishedRepoCollection()
344
345 // Re-read repo with fresh collection after lock
346 repo, err := taskCollection.ByName(name)
347 if err != nil {
348 return &task.ProcessReturnValue{Code: http.StatusConflict, Value: nil}, fmt.Errorf("unable to drop: %s", err)
349 }
350
351 // Check with fresh collections
352 published := taskPublishedCollection.ByLocalRepo(repo)
353 if len(published) > 0 {
354 return &task.ProcessReturnValue{Code: http.StatusConflict, Value: nil}, fmt.Errorf("unable to drop, local repo is published")
355 }
356
357 if !force {
358 snapshots := taskSnapshotCollection.ByLocalRepoSource(repo)
359 if len(snapshots) > 0 {
360 return &task.ProcessReturnValue{Code: http.StatusConflict, Value: nil}, fmt.Errorf("unable to drop, local repo has snapshots, use ?force=1 to override")
361 }
362 }
363
364 return &task.ProcessReturnValue{Code: http.StatusOK, Value: gin.H{}}, taskCollection.Drop(repo)
365 })
366}
367
368// @Summary List Repo Packages
369// @Description **Return a list of packages present in the repo**

Callers

nothing calls this directly

Calls 13

LocalRepoCollectionMethod · 0.95
SnapshotCollectionMethod · 0.95
AbortWithJSONErrorFunction · 0.85
maybeRunTaskInBackgroundFunction · 0.85
NewCollectionFactoryMethod · 0.80
ByLocalRepoMethod · 0.80
ByLocalRepoSourceMethod · 0.80
GetMethod · 0.65
QueryMethod · 0.65
DropMethod · 0.65
ByNameMethod · 0.45

Tested by

no test coverage detected