Force flag for API repos delete. #116

This commit is contained in:
Andrey Smirnov
2014-10-10 17:18:47 +04:00
parent 22bcacf143
commit 53f7fef4cf
+4 -8
View File
@@ -110,13 +110,7 @@ func apiReposShow(c *gin.Context) {
// DELETE /api/repos/:name // DELETE /api/repos/:name
func apiReposDrop(c *gin.Context) { func apiReposDrop(c *gin.Context) {
var b struct { force := c.Request.URL.Query().Get("force") == "1"
Force bool
}
if !c.Bind(&b) {
return
}
collection := context.CollectionFactory().LocalRepoCollection() collection := context.CollectionFactory().LocalRepoCollection()
collection.Lock() collection.Lock()
@@ -142,11 +136,13 @@ func apiReposDrop(c *gin.Context) {
return return
} }
if !force {
snapshots := snapshotCollection.ByLocalRepoSource(repo) snapshots := snapshotCollection.ByLocalRepoSource(repo)
if len(snapshots) > 0 { if len(snapshots) > 0 {
c.Fail(409, fmt.Errorf("unable to drop, local repo has snapshots, use Force to override")) c.Fail(409, fmt.Errorf("unable to drop, local repo has snapshots, use ?force=1 to override"))
return return
} }
}
err = collection.Drop(repo) err = collection.Drop(repo)
if err != nil { if err != nil {