@Summary Delete File @Description **Delete a uploaded file in upload directory** @Description @Description **Example:** @Description ``` @Description $ curl -X DELETE http://localhost:8080/api/files/aptly-0.9/aptly_0.9~dev+217+ge5d646c_i386.deb @Description {} @Description ``` @Tags Files @Produce
(c *gin.Context)
| 345 | // @Failure 500 {object} Error "Internal Server Error" |
| 346 | // @Router /api/files/{dir}/{name} [delete] |
| 347 | func apiFilesDeleteFile(c *gin.Context) { |
| 348 | if !verifyDir(c) { |
| 349 | return |
| 350 | } |
| 351 | |
| 352 | dir := utils.SanitizePath(c.Params.ByName("dir")) |
| 353 | name := utils.SanitizePath(c.Params.ByName("name")) |
| 354 | if !verifyPath(name) { |
| 355 | AbortWithJSONError(c, 400, fmt.Errorf("wrong file")) |
| 356 | return |
| 357 | } |
| 358 | |
| 359 | err := os.Remove(filepath.Join(context.UploadPath(), dir, name)) |
| 360 | if err != nil { |
| 361 | if err1, ok := err.(*os.PathError); !ok || !os.IsNotExist(err1.Err) { |
| 362 | AbortWithJSONError(c, 500, err) |
| 363 | return |
| 364 | } |
| 365 | } |
| 366 | |
| 367 | c.JSON(200, gin.H{}) |
| 368 | } |
nothing calls this directly
no test coverage detected