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

Function apiFilesListFiles

api/files.go:266–301  ·  view source on GitHub ↗

@Summary List Files @Description **Show uploaded files in upload directory** @Description @Description **Example:** @Description ``` @Description $ curl http://localhost:8080/api/files/aptly-0.9 @Description ["aptly_0.9~dev+217+ge5d646c_i386.deb"] @Description ``` @Tags Files @Produce json @Param

(c *gin.Context)

Source from the content-addressed store, hash-verified

264// @Failure 500 {object} Error "Internal Server Error"
265// @Router /api/files/{dir} [get]
266func apiFilesListFiles(c *gin.Context) {
267 if !verifyDir(c) {
268 return
269 }
270
271 list := []string{}
272 listLock := &sync.Mutex{}
273 root := filepath.Join(context.UploadPath(), utils.SanitizePath(c.Params.ByName("dir")))
274
275 err := filepath.Walk(root, func(path string, _ os.FileInfo, err error) error {
276 if err != nil {
277 return err
278 }
279
280 if path == root {
281 return nil
282 }
283
284 listLock.Lock()
285 defer listLock.Unlock()
286 list = append(list, filepath.Base(path))
287
288 return nil
289 })
290
291 if err != nil {
292 if os.IsNotExist(err) {
293 AbortWithJSONError(c, 404, err)
294 } else {
295 AbortWithJSONError(c, 500, err)
296 }
297 return
298 }
299
300 c.JSON(200, list)
301}
302
303// @Summary Delete Directory
304// @Description **Delete upload directory and uploaded files within**

Callers

nothing calls this directly

Calls 5

SanitizePathFunction · 0.92
verifyDirFunction · 0.85
AbortWithJSONErrorFunction · 0.85
UploadPathMethod · 0.80
ByNameMethod · 0.45

Tested by

no test coverage detected