Skip to content

Commit

Permalink
fix: Fixed append test failures (#84)
Browse files Browse the repository at this point in the history
* fix: Fixed append test failures

* Modify the handling of objects when they exist.
  • Loading branch information
abyss-w authored Aug 24, 2021
1 parent 45e51f6 commit 19bb7a0
Showing 1 changed file with 15 additions and 1 deletion.
16 changes: 15 additions & 1 deletion storage.go
Original file line number Diff line number Diff line change
Expand Up @@ -101,8 +101,19 @@ func (s *Storage) create(path string, opt pairStorageCreate) (o *Object) {
func (s *Storage) createAppend(ctx context.Context, path string, opt pairStorageCreateAppend) (o *Object, err error) {
rp := s.getAbsPath(path)

// `AppendObject` with position 0 will overwrite the existing object, so there's no need to check the object exists or not.
// We should set offset to 0 whether the object exists or not.
var offset int64 = 0

// If the object exists, we should delete it.
headInput := &service.HeadObjectInput{}
_, err = s.bucket.HeadObjectWithContext(ctx, rp, headInput)
if err == nil {
_, err = s.bucket.DeleteObject(rp)
if err != nil {
return nil, err
}
}

input := &service.AppendObjectInput{
Position: &offset,
}
Expand Down Expand Up @@ -654,6 +665,9 @@ func (s *Storage) writeAppend(ctx context.Context, o *Object, r io.Reader, size
offset = *output.XQSNextAppendPosition
}

// We should reset the offset after calling `AppendObject` to prevent the offset being changed.
o.SetAppendOffset(offset)

return size, nil
}

Expand Down

0 comments on commit 19bb7a0

Please sign in to comment.