GetInfo now properly retrieves the object size

This commit is contained in:
Peixian Wang 2017-11-28 09:28:37 -05:00
parent 6f9b66f3ad
commit bbb0fd5ec7
No known key found for this signature in database
GPG Key ID: 09E0BB614965D829
3 changed files with 22 additions and 9 deletions

View File

@ -333,6 +333,7 @@ func (service *GCSService) FilterObjects(params GCSFilterParams) ([]string, erro
it := bkt.Objects(service.Ctx, &q) it := bkt.Objects(service.Ctx, &q)
names := make([]string, 0) names := make([]string, 0)
loop:
for { for {
objAttrs, err := it.Next() objAttrs, err := it.Next()
if err == iterator.Done { if err == iterator.Done {
@ -342,19 +343,27 @@ func (service *GCSService) FilterObjects(params GCSFilterParams) ([]string, erro
return nil, err return nil, err
} }
if strings.HasSuffix(objAttrs.Name, "info") {
continue
}
split := strings.Split(objAttrs.Name, "_") split := strings.Split(objAttrs.Name, "_")
// If the object name does not split on "_", we have a composed object.
// If the object name splits on "_" in to four pieces we // If the object name splits on "_" in to four pieces we
// know the object name we are working with is in the format // know the object name we are working with is in the format
// [uid]_tmp_[recursion_lvl]_[chunk_idx]. The only time we filter // [uid]_tmp_[recursion_lvl]_[chunk_idx]. The only time we filter
// these temporary objects is on a delete operation so we can just // these temporary objects is on a delete operation so we can just
// append and continue without worrying about index order // append and continue without worrying about index order
if len(split) == 4 {
switch len(split) {
case 1:
names = []string{objAttrs.Name}
break loop
case 2:
case 4:
names = append(names, objAttrs.Name) names = append(names, objAttrs.Name)
continue continue
} default:
if len(split) != 2 {
err := errors.New("Invalid filter format for object name") err := errors.New("Invalid filter format for object name")
return nil, err return nil, err
} }
@ -370,7 +379,6 @@ func (service *GCSService) FilterObjects(params GCSFilterParams) ([]string, erro
names[idx] = objAttrs.Name names[idx] = objAttrs.Name
} }
return names, nil return names, nil
} }

View File

@ -126,7 +126,7 @@ func (store GCSStore) GetInfo(id string) (tusd.FileInfo, error) {
return info, err return info, err
} }
prefix := fmt.Sprintf("%s_", id) prefix := fmt.Sprintf("%s", id)
filterParams := GCSFilterParams{ filterParams := GCSFilterParams{
Bucket: store.Bucket, Bucket: store.Bucket,
Prefix: prefix, Prefix: prefix,

View File

@ -103,7 +103,7 @@ func TestGetInfo(t *testing.T) {
filterParams := gcsstore.GCSFilterParams{ filterParams := gcsstore.GCSFilterParams{
Bucket: store.Bucket, Bucket: store.Bucket,
Prefix: fmt.Sprintf("%s_", mockID), Prefix: fmt.Sprintf("%s", mockID),
} }
mockObjectParams0 := gcsstore.GCSObjectParams{ mockObjectParams0 := gcsstore.GCSObjectParams{
@ -230,6 +230,11 @@ func TestFinishUpload(t *testing.T) {
Prefix: fmt.Sprintf("%s_", mockID), Prefix: fmt.Sprintf("%s_", mockID),
} }
filterParams2 := gcsstore.GCSFilterParams{
Bucket: store.Bucket,
Prefix: fmt.Sprintf("%s", mockID),
}
composeParams := gcsstore.GCSComposeParams{ composeParams := gcsstore.GCSComposeParams{
Bucket: store.Bucket, Bucket: store.Bucket,
Destination: mockID, Destination: mockID,
@ -268,7 +273,7 @@ func TestFinishUpload(t *testing.T) {
objectParams := gcsstore.GCSObjectParams{ objectParams := gcsstore.GCSObjectParams{
Bucket: store.Bucket, Bucket: store.Bucket,
ID: mockID, ID: fmt.Sprintf("%s", mockID),
} }
metadata := map[string]string{ metadata := map[string]string{
@ -280,7 +285,7 @@ func TestFinishUpload(t *testing.T) {
service.EXPECT().ComposeObjects(composeParams).Return(nil), service.EXPECT().ComposeObjects(composeParams).Return(nil),
service.EXPECT().DeleteObjectsWithFilter(filterParams).Return(nil), service.EXPECT().DeleteObjectsWithFilter(filterParams).Return(nil),
service.EXPECT().ReadObject(infoParams).Return(r, nil), service.EXPECT().ReadObject(infoParams).Return(r, nil),
service.EXPECT().FilterObjects(filterParams).Return(mockPartials, nil), service.EXPECT().FilterObjects(filterParams2).Return(mockPartials, nil),
service.EXPECT().GetObjectSize(mockObjectParams0).Return(size, nil), service.EXPECT().GetObjectSize(mockObjectParams0).Return(size, nil),
service.EXPECT().GetObjectSize(mockObjectParams1).Return(size, nil), service.EXPECT().GetObjectSize(mockObjectParams1).Return(size, nil),
service.EXPECT().GetObjectSize(mockObjectParams2).Return(size, nil), service.EXPECT().GetObjectSize(mockObjectParams2).Return(size, nil),