Merge pull request #161 from peixian/fix-gcs-object-info

GetInfo now properly retrieves info for composed objects
This commit is contained in:
Marius 2017-12-01 15:01:33 +01:00 committed by GitHub
commit ef64437ccc
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
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)
names := make([]string, 0)
loop:
for {
objAttrs, err := it.Next()
if err == iterator.Done {
@ -342,19 +343,27 @@ func (service *GCSService) FilterObjects(params GCSFilterParams) ([]string, erro
return nil, err
}
if strings.HasSuffix(objAttrs.Name, "info") {
continue
}
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
// know the object name we are working with is in the format
// [uid]_tmp_[recursion_lvl]_[chunk_idx]. The only time we filter
// these temporary objects is on a delete operation so we can just
// 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)
continue
}
if len(split) != 2 {
default:
err := errors.New("Invalid filter format for object name")
return nil, err
}
@ -370,7 +379,6 @@ func (service *GCSService) FilterObjects(params GCSFilterParams) ([]string, erro
names[idx] = objAttrs.Name
}
return names, nil
}

View File

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

View File

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