| 244 | } |
| 245 | |
| 246 | Status Sync() override { |
| 247 | if (!outfile_) { |
| 248 | return errors::FailedPrecondition( |
| 249 | "The internal temporary file is not writable."); |
| 250 | } |
| 251 | if (!sync_needed_) { |
| 252 | return Status::OK(); |
| 253 | } |
| 254 | Aws::S3::Model::PutObjectRequest putObjectRequest; |
| 255 | putObjectRequest.WithBucket(bucket_.c_str()).WithKey(object_.c_str()); |
| 256 | long offset = outfile_->tellp(); |
| 257 | outfile_->seekg(0); |
| 258 | putObjectRequest.SetBody(outfile_); |
| 259 | putObjectRequest.SetContentLength(offset); |
| 260 | auto putObjectOutcome = this->s3_client_->PutObject(putObjectRequest); |
| 261 | outfile_->clear(); |
| 262 | outfile_->seekp(offset); |
| 263 | if (!putObjectOutcome.IsSuccess()) { |
| 264 | return errors::Unknown(putObjectOutcome.GetError().GetExceptionName(), |
| 265 | ": ", putObjectOutcome.GetError().GetMessage()); |
| 266 | } |
| 267 | return Status::OK(); |
| 268 | } |
| 269 | |
| 270 | private: |
| 271 | string bucket_; |