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

Function apiFilesDeleteFile

api/files.go:347–368  ·  view source on GitHub ↗

@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)

Source from the content-addressed store, hash-verified

345// @Failure 500 {object} Error "Internal Server Error"
346// @Router /api/files/{dir}/{name} [delete]
347func 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}

Callers

nothing calls this directly

Calls 7

SanitizePathFunction · 0.92
verifyDirFunction · 0.85
verifyPathFunction · 0.85
AbortWithJSONErrorFunction · 0.85
UploadPathMethod · 0.80
RemoveMethod · 0.65
ByNameMethod · 0.45

Tested by

no test coverage detected