Merge pull request #250 from harshavardhana/pr_out_add_proper_path_prefix_to_be_delimited

This commit is contained in:
Harshavardhana 2015-03-04 00:57:00 -08:00
commit cb46c61be4
1 changed files with 14 additions and 14 deletions

View File

@ -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,8 +413,12 @@ func (storage *storage) ListObjects(bucket string, resources mstorage.BucketReso
} }
metadataList = append(metadataList, metadata) metadataList = append(metadataList, metadata)
case delimited != "": case delimited != "":
if delimited == resources.Delimiter {
resources.CommonPrefixes = appendUniq(resources.CommonPrefixes, resources.Prefix+delimited)
} else {
resources.CommonPrefixes = appendUniq(resources.CommonPrefixes, delimited) resources.CommonPrefixes = appendUniq(resources.CommonPrefixes, delimited)
} }
}
case strings.HasPrefix(name, resources.Prefix): case strings.HasPrefix(name, resources.Prefix):
metadata := mstorage.ObjectMetadata{ metadata := mstorage.ObjectMetadata{
Bucket: bucket, Bucket: bucket,