Merge pull request #161 from peixian/fix-gcs-object-info
GetInfo now properly retrieves info for composed objects
This commit is contained in:
commit
ef64437ccc
|
@ -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
|
||||
|
||||
}
|
||||
|
|
|
@ -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,
|
||||
|
|
|
@ -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),
|
||||
|
|
Loading…
Reference in New Issue