|
|
@ -173,6 +173,23 @@ func appendUniq(slice []string, i string) []string { |
|
|
|
return append(slice, i) |
|
|
|
return append(slice, i) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
func (memory memoryDriver) filterDelimiterPrefix(keys []string, key, delimitedName string, resources drivers.BucketResourcesMetadata) (drivers.BucketResourcesMetadata, []string) { |
|
|
|
|
|
|
|
switch true { |
|
|
|
|
|
|
|
case key == resources.Prefix: |
|
|
|
|
|
|
|
keys = appendUniq(keys, key) |
|
|
|
|
|
|
|
// DelimitedName - requires resources.Prefix as it was trimmed off earlier in the flow
|
|
|
|
|
|
|
|
case key == resources.Prefix+delimitedName: |
|
|
|
|
|
|
|
keys = appendUniq(keys, key) |
|
|
|
|
|
|
|
case delimitedName != "": |
|
|
|
|
|
|
|
if delimitedName == resources.Delimiter { |
|
|
|
|
|
|
|
resources.CommonPrefixes = appendUniq(resources.CommonPrefixes, resources.Prefix+delimitedName) |
|
|
|
|
|
|
|
} else { |
|
|
|
|
|
|
|
resources.CommonPrefixes = appendUniq(resources.CommonPrefixes, delimitedName) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
return resources, keys |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// ListObjects - list objects from memory
|
|
|
|
// ListObjects - list objects from memory
|
|
|
|
func (memory memoryDriver) ListObjects(bucket string, resources drivers.BucketResourcesMetadata) ([]drivers.ObjectMetadata, drivers.BucketResourcesMetadata, error) { |
|
|
|
func (memory memoryDriver) ListObjects(bucket string, resources drivers.BucketResourcesMetadata) ([]drivers.ObjectMetadata, drivers.BucketResourcesMetadata, error) { |
|
|
|
if _, ok := memory.bucketdata[bucket]; ok == false { |
|
|
|
if _, ok := memory.bucketdata[bucket]; ok == false { |
|
|
@ -183,7 +200,7 @@ func (memory memoryDriver) ListObjects(bucket string, resources drivers.BucketRe |
|
|
|
for key := range memory.objectdata { |
|
|
|
for key := range memory.objectdata { |
|
|
|
switch true { |
|
|
|
switch true { |
|
|
|
// Prefix absent, delimit object key based on delimiter
|
|
|
|
// Prefix absent, delimit object key based on delimiter
|
|
|
|
case resources.Delimiter != "" && resources.Prefix == "": |
|
|
|
case resources.IsDelimiterSet(): |
|
|
|
delimitedName := delimiter(key, resources.Delimiter) |
|
|
|
delimitedName := delimiter(key, resources.Delimiter) |
|
|
|
switch true { |
|
|
|
switch true { |
|
|
|
case delimitedName == "" || delimitedName == key: |
|
|
|
case delimitedName == "" || delimitedName == key: |
|
|
@ -192,31 +209,20 @@ func (memory memoryDriver) ListObjects(bucket string, resources drivers.BucketRe |
|
|
|
resources.CommonPrefixes = appendUniq(resources.CommonPrefixes, delimitedName) |
|
|
|
resources.CommonPrefixes = appendUniq(resources.CommonPrefixes, delimitedName) |
|
|
|
} |
|
|
|
} |
|
|
|
// Prefix present, delimit object key with prefix key based on delimiter
|
|
|
|
// Prefix present, delimit object key with prefix key based on delimiter
|
|
|
|
case resources.Delimiter != "" && resources.Prefix != "" && strings.HasPrefix(key, resources.Prefix): |
|
|
|
case resources.IsDelimiterPrefixSet(): |
|
|
|
trimmedName := strings.TrimPrefix(key, resources.Prefix) |
|
|
|
if strings.HasPrefix(key, resources.Prefix) { |
|
|
|
delimitedName := delimiter(trimmedName, resources.Delimiter) |
|
|
|
trimmedName := strings.TrimPrefix(key, resources.Prefix) |
|
|
|
switch true { |
|
|
|
delimitedName := delimiter(trimmedName, resources.Delimiter) |
|
|
|
case key == resources.Prefix: |
|
|
|
resources, keys = memory.filterDelimiterPrefix(keys, key, delimitedName, resources) |
|
|
|
keys = appendUniq(keys, key) |
|
|
|
|
|
|
|
// DelimitedName - requires resources.Prefix as it was trimmed off earlier in the flow
|
|
|
|
|
|
|
|
case key == resources.Prefix+delimitedName: |
|
|
|
|
|
|
|
keys = appendUniq(keys, key) |
|
|
|
|
|
|
|
case delimitedName != "": |
|
|
|
|
|
|
|
if delimitedName == resources.Delimiter { |
|
|
|
|
|
|
|
resources.CommonPrefixes = appendUniq(resources.CommonPrefixes, resources.Prefix+delimitedName) |
|
|
|
|
|
|
|
} else { |
|
|
|
|
|
|
|
resources.CommonPrefixes = appendUniq(resources.CommonPrefixes, delimitedName) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
// Prefix present, nothing to delimit
|
|
|
|
// Prefix present, nothing to delimit
|
|
|
|
case resources.Delimiter == "" && resources.Prefix != "" && strings.HasPrefix(key, resources.Prefix): |
|
|
|
case resources.IsPrefixSet(): |
|
|
|
keys = appendUniq(keys, key) |
|
|
|
keys = appendUniq(keys, key) |
|
|
|
// Prefix and delimiter absent
|
|
|
|
// Prefix and delimiter absent
|
|
|
|
case resources.Prefix == "" && resources.Delimiter == "": |
|
|
|
case resources.IsDefault(): |
|
|
|
keys = appendUniq(keys, key) |
|
|
|
keys = appendUniq(keys, key) |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
sort.Strings(keys) |
|
|
|
sort.Strings(keys) |
|
|
|
for _, key := range keys { |
|
|
|
for _, key := range keys { |
|
|
|
if len(results) == resources.Maxkeys { |
|
|
|
if len(results) == resources.Maxkeys { |
|
|
|