cleaner code

This commit is contained in:
chrislu 2022-08-20 17:51:30 -07:00
parent 9f50b310a0
commit e3f40d538d

View file

@ -127,29 +127,29 @@ func (s3sink *S3Sink) CreateEntry(key string, entry *filer_pb.Entry, signatures
parts := make([]*s3.CompletedPart, len(chunkViews)) parts := make([]*s3.CompletedPart, len(chunkViews))
var wg sync.WaitGroup if len(parts) > 0 {
for chunkIndex, chunk := range chunkViews { var wg sync.WaitGroup
partId := chunkIndex + 1 for chunkIndex, chunk := range chunkViews {
wg.Add(1) partId := chunkIndex + 1
go func(chunk *filer.ChunkView, index int) { wg.Add(1)
defer wg.Done() go func(chunk *filer.ChunkView, index int) {
if part, uploadErr := s3sink.uploadPart(key, uploadId, partId, chunk); uploadErr != nil { defer wg.Done()
err = uploadErr if part, uploadErr := s3sink.uploadPart(key, uploadId, partId, chunk); uploadErr != nil {
glog.Errorf("uploadPart: %v", uploadErr) err = uploadErr
} else { glog.Errorf("uploadPart: %v", uploadErr)
parts[index] = part } else {
} parts[index] = part
}(chunk, chunkIndex) }
} }(chunk, chunkIndex)
wg.Wait() }
wg.Wait()
// for small files } else if len(entry.Content) > 0 {
if len(entry.Content) > 0 { // for small files
parts = make([]*s3.CompletedPart, 1)
if part, uploadErr := s3sink.doUploadPart(key, uploadId, 1, bytes.NewReader(entry.Content)); uploadErr != nil { if part, uploadErr := s3sink.doUploadPart(key, uploadId, 1, bytes.NewReader(entry.Content)); uploadErr != nil {
err = uploadErr err = uploadErr
glog.Errorf("uploadPart: %v", uploadErr) glog.Errorf("uploadPart: %v", uploadErr)
} else { } else {
parts = make([]*s3.CompletedPart, 1)
parts[0] = part parts[0] = part
} }
} }