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

Function showPackages

api/api.go:236–327  ·  view source on GitHub ↗

Common piece of code to show list of packages, with searching & details if requested

(c *gin.Context, reflist *deb.PackageRefList, collectionFactory *deb.CollectionFactory)

Source from the content-addressed store, hash-verified

234// Common piece of code to show list of packages,
235// with searching & details if requested
236func showPackages(c *gin.Context, reflist *deb.PackageRefList, collectionFactory *deb.CollectionFactory) {
237 result := []*deb.Package{}
238
239 list, err := deb.NewPackageListFromRefList(reflist, collectionFactory.PackageCollection(), nil)
240 if err != nil {
241 AbortWithJSONError(c, 404, err)
242 return
243 }
244
245 queryS := c.Request.URL.Query().Get("q")
246 if queryS != "" {
247 q, err := query.Parse(c.Request.URL.Query().Get("q"))
248 if err != nil {
249 AbortWithJSONError(c, 400, err)
250 return
251 }
252
253 withDeps := c.Request.URL.Query().Get("withDeps") == "1"
254 architecturesList := []string{}
255
256 if withDeps {
257 if len(context.ArchitecturesList()) > 0 {
258 architecturesList = context.ArchitecturesList()
259 } else {
260 architecturesList = list.Architectures(false)
261 }
262
263 sort.Strings(architecturesList)
264
265 if len(architecturesList) == 0 {
266 AbortWithJSONError(c, 400, fmt.Errorf("unable to determine list of architectures, please specify explicitly"))
267 return
268 }
269 }
270
271 list.PrepareIndex()
272
273 list, err = list.Filter(deb.FilterOptions{
274 Queries: []deb.PackageQuery{q},
275 WithDependencies: withDeps,
276 Source: nil,
277 DependencyOptions: context.DependencyOptions(),
278 Architectures: architecturesList,
279 })
280 if err != nil {
281 AbortWithJSONError(c, 500, fmt.Errorf("unable to search: %s", err))
282 return
283 }
284 }
285
286 // filter packages by version
287 if c.Request.URL.Query().Get("maximumVersion") == "1" {
288 list.PrepareIndex()
289 _ = list.ForEach(func(p *deb.Package) error {
290 versionQ, err := query.Parse(fmt.Sprintf("Name (%s), $Version (<= %s)", p.Name, p.Version))
291 if err != nil {
292 fmt.Println("filter packages by version, query string parse err: ", err)
293 _ = c.AbortWithError(500, fmt.Errorf("unable to parse %s maximum version query string: %s", p.Name, err))

Callers 3

apiReposPackagesShowFunction · 0.85
apiPackagesFunction · 0.85

Calls 15

ParseFunction · 0.92
AbortWithJSONErrorFunction · 0.85
PackageCollectionMethod · 0.80
ArchitecturesListMethod · 0.80
ArchitecturesMethod · 0.80
PrepareIndexMethod · 0.80
FilterMethod · 0.80
DependencyOptionsMethod · 0.80
GetMethod · 0.65
QueryMethod · 0.65
RemoveMethod · 0.65

Tested by

no test coverage detected