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

Function apiMirrorsDrop

api/mirror.go:215–264  ·  view source on GitHub ↗

@Summary Delete Mirror @Description **Delete a mirror** @Tags Mirrors @Param name path string true "mirror name" @Param force query int true "force: 1 to enable" @Param _async query bool false "Run in background and return task object" @Produce json @Success 200 {object} task.ProcessReturnValue @Fai

(c *gin.Context)

Source from the content-addressed store, hash-verified

213// @Failure 500 {object} Error "Unable to delete"
214// @Router /api/mirrors/{name} [delete]
215func apiMirrorsDrop(c *gin.Context) {
216 name := c.Params.ByName("name")
217 force := c.Request.URL.Query().Get("force") == "1"
218
219 // Phase 1: Pre-task validation (shallow load for 404 check only)
220 collectionFactory := context.NewCollectionFactory()
221 mirrorCollection := collectionFactory.RemoteRepoCollection()
222
223 repo, err := mirrorCollection.ByName(name)
224 if err != nil {
225 AbortWithJSONError(c, 404, fmt.Errorf("unable to drop: %s", err))
226 return
227 }
228
229 resources := []string{string(repo.Key())}
230 taskName := fmt.Sprintf("Delete mirror %s", name)
231
232 maybeRunTaskInBackground(c, taskName, resources, func(_ aptly.Progress, _ *task.Detail) (*task.ProcessReturnValue, error) {
233 // Phase 2: Inside task lock - create fresh collections
234 taskCollectionFactory := context.NewCollectionFactory()
235 taskMirrorCollection := taskCollectionFactory.RemoteRepoCollection()
236 taskSnapshotCollection := taskCollectionFactory.SnapshotCollection()
237
238 // Fresh load after lock acquired
239 repo, err := taskMirrorCollection.ByName(name)
240 if err != nil {
241 return &task.ProcessReturnValue{Code: http.StatusInternalServerError, Value: nil}, fmt.Errorf("unable to drop: %v", err)
242 }
243
244 err = repo.CheckLock()
245 if err != nil {
246 return &task.ProcessReturnValue{Code: http.StatusInternalServerError, Value: nil}, fmt.Errorf("unable to drop: %v", err)
247 }
248
249 if !force {
250 // Fresh checks with current collections
251 snapshots := taskSnapshotCollection.ByRemoteRepoSource(repo)
252
253 if len(snapshots) > 0 {
254 return &task.ProcessReturnValue{Code: http.StatusForbidden, Value: nil}, fmt.Errorf("won't delete mirror with snapshots, use 'force=1' to override")
255 }
256 }
257
258 err = taskMirrorCollection.Drop(repo)
259 if err != nil {
260 return &task.ProcessReturnValue{Code: http.StatusInternalServerError, Value: nil}, fmt.Errorf("unable to drop: %v", err)
261 }
262 return &task.ProcessReturnValue{Code: http.StatusNoContent, Value: nil}, nil
263 })
264}
265
266// @Summary Get Mirror Info
267// @Description **Get mirror information by name**

Callers

nothing calls this directly

Calls 12

RemoteRepoCollectionMethod · 0.95
SnapshotCollectionMethod · 0.95
AbortWithJSONErrorFunction · 0.85
maybeRunTaskInBackgroundFunction · 0.85
NewCollectionFactoryMethod · 0.80
CheckLockMethod · 0.80
ByRemoteRepoSourceMethod · 0.80
GetMethod · 0.65
QueryMethod · 0.65
DropMethod · 0.65
ByNameMethod · 0.45
KeyMethod · 0.45

Tested by

no test coverage detected