MCPcopy Create free account
hub / github.com/aptly-dev/aptly / get

Method get

s3/server_test.go:378–452  ·  view source on GitHub ↗

GET on a bucket lists the objects in the bucket. http://docs.amazonwebservices.com/AmazonS3/latest/API/RESTBucketGET.html

(a *action)

Source from the content-addressed store, hash-verified

376// GET on a bucket lists the objects in the bucket.
377// http://docs.amazonwebservices.com/AmazonS3/latest/API/RESTBucketGET.html
378func (r bucketResource) get(a *action) interface{} {
379 if r.bucket == nil {
380 fatalError(404, "NoSuchBucket", "The specified bucket does not exist")
381 }
382 delimiter := a.req.Form.Get("delimiter")
383 marker := a.req.Form.Get("marker")
384 maxKeys := -1
385 if s := a.req.Form.Get("max-keys"); s != "" {
386 i, err := strconv.Atoi(s)
387 if err != nil || i < 0 {
388 fatalError(400, "invalid value for max-keys", "%q", s)
389 }
390 maxKeys = i
391 }
392 prefix := a.req.Form.Get("prefix")
393 a.w.Header().Set("Content-Type", "application/xml")
394
395 if a.req.Method == "HEAD" {
396 return nil
397 }
398
399 var objs orderedObjects
400
401 // first get all matching objects and arrange them in alphabetical order.
402 for name, obj := range r.bucket.objects {
403 if strings.HasPrefix(name, prefix) {
404 objs = append(objs, obj)
405 }
406 }
407 sort.Sort(objs)
408
409 if maxKeys <= 0 {
410 maxKeys = 1000
411 }
412 resp := &ListResp{
413 Name: r.bucket.name,
414 Prefix: prefix,
415 Delimiter: delimiter,
416 Marker: marker,
417 MaxKeys: maxKeys,
418 }
419
420 var prefixes []CommonPrefix
421 for _, obj := range objs {
422 if !strings.HasPrefix(obj.name, prefix) {
423 continue
424 }
425 name := obj.name
426 isPrefix := false
427 if delimiter != "" {
428 if i := strings.Index(obj.name[len(prefix):], delimiter); i >= 0 {
429 name = obj.name[:len(prefix)+i+len(delimiter)]
430 if prefixes != nil && prefixes[len(prefixes)-1].Prefix == name {
431 continue
432 }
433 isPrefix = true
434 }
435 }

Callers

nothing calls this directly

Calls 5

fatalErrorFunction · 0.85
s3KeyMethod · 0.80
GetMethod · 0.65
HasPrefixMethod · 0.65
SetMethod · 0.45

Tested by

no test coverage detected