Add proper path prefix to be delimited

master
Harshavardhana 10 years ago
parent df135d7307
commit e400e85639
  1. 28
      pkg/storage/fs/fs.go

@ -17,6 +17,7 @@
package fs package fs
import ( import (
"bufio"
"bytes" "bytes"
"encoding/json" "encoding/json"
"io" "io"
@ -332,17 +333,12 @@ func (p *Path) getAllFiles(path string, fl os.FileInfo, err error) error {
} }
func delimiter(path, delimiter string) string { func delimiter(path, delimiter string) string {
delimited := "" readBuffer := bytes.NewBufferString(path)
if !strings.Contains(path, delimiter) { reader := bufio.NewReader(readBuffer)
return delimited stringReader := strings.NewReader(delimiter)
} delimited, _ := stringReader.ReadByte()
index := strings.Index(path, delimiter) delimitedStr, _ := reader.ReadString(delimited)
if index == -1 { return delimitedStr
return delimited
}
delimitedIndex := index + len(delimiter)
delimited = path[:delimitedIndex]
return delimited
} }
type ByObjectKey []mstorage.ObjectMetadata type ByObjectKey []mstorage.ObjectMetadata
@ -391,7 +387,7 @@ func (storage *storage) ListObjects(bucket string, resources mstorage.BucketReso
case resources.Delimiter != "" && resources.Prefix == "": case resources.Delimiter != "" && resources.Prefix == "":
delimited := delimiter(name, resources.Delimiter) delimited := delimiter(name, resources.Delimiter)
switch true { switch true {
case delimited == "": case delimited == file.Name():
metadata := mstorage.ObjectMetadata{ metadata := mstorage.ObjectMetadata{
Bucket: bucket, Bucket: bucket,
Key: name, Key: name,
@ -407,7 +403,7 @@ func (storage *storage) ListObjects(bucket string, resources mstorage.BucketReso
_internal := strings.TrimPrefix(name, resources.Prefix) _internal := strings.TrimPrefix(name, resources.Prefix)
delimited := delimiter(_internal, resources.Delimiter) delimited := delimiter(_internal, resources.Delimiter)
switch true { switch true {
case delimited == "": case delimited == file.Name():
metadata := mstorage.ObjectMetadata{ metadata := mstorage.ObjectMetadata{
Bucket: bucket, Bucket: bucket,
Key: _internal, Key: _internal,
@ -417,7 +413,11 @@ func (storage *storage) ListObjects(bucket string, resources mstorage.BucketReso
} }
metadataList = append(metadataList, metadata) metadataList = append(metadataList, metadata)
case delimited != "": case delimited != "":
resources.CommonPrefixes = appendUniq(resources.CommonPrefixes, delimited) if delimited == resources.Delimiter {
resources.CommonPrefixes = appendUniq(resources.CommonPrefixes, resources.Prefix+delimited)
} else {
resources.CommonPrefixes = appendUniq(resources.CommonPrefixes, delimited)
}
} }
case strings.HasPrefix(name, resources.Prefix): case strings.HasPrefix(name, resources.Prefix):
metadata := mstorage.ObjectMetadata{ metadata := mstorage.ObjectMetadata{

Loading…
Cancel
Save