Alex Deymo | aea4c1c | 2015-08-19 20:24:43 -0700 | [diff] [blame] | 1 | // |
| 2 | // Copyright (C) 2015 The Android Open Source Project |
| 3 | // |
| 4 | // Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | // you may not use this file except in compliance with the License. |
| 6 | // You may obtain a copy of the License at |
| 7 | // |
| 8 | // http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | // |
| 10 | // Unless required by applicable law or agreed to in writing, software |
| 11 | // distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | // See the License for the specific language governing permissions and |
| 14 | // limitations under the License. |
| 15 | // |
Sen Jiang | 8cc502d | 2015-08-10 10:04:54 -0700 | [diff] [blame] | 16 | |
| 17 | #include "update_engine/payload_generator/blob_file_writer.h" |
| 18 | |
Alex Deymo | 39910dc | 2015-11-09 17:04:30 -0800 | [diff] [blame] | 19 | #include "update_engine/common/utils.h" |
Sen Jiang | 8cc502d | 2015-08-10 10:04:54 -0700 | [diff] [blame] | 20 | |
| 21 | namespace chromeos_update_engine { |
| 22 | |
Alex Vakulenko | 3f39d5c | 2015-10-13 09:27:13 -0700 | [diff] [blame] | 23 | off_t BlobFileWriter::StoreBlob(const brillo::Blob& blob) { |
Sen Jiang | 8cc502d | 2015-08-10 10:04:54 -0700 | [diff] [blame] | 24 | base::AutoLock auto_lock(blob_mutex_); |
| 25 | if (!utils::PWriteAll(blob_fd_, blob.data(), blob.size(), *blob_file_size_)) |
| 26 | return -1; |
| 27 | |
| 28 | off_t result = *blob_file_size_; |
| 29 | *blob_file_size_ += blob.size(); |
| 30 | |
| 31 | stored_blobs_++; |
| 32 | if (total_blobs_ > 0 && |
| 33 | (10 * (stored_blobs_ - 1) / total_blobs_) != |
| 34 | (10 * stored_blobs_ / total_blobs_)) { |
| 35 | LOG(INFO) << (100 * stored_blobs_ / total_blobs_) |
| 36 | << "% complete " << stored_blobs_ << "/" << total_blobs_ |
| 37 | << " ops (output size: " << *blob_file_size_ << ")"; |
| 38 | } |
| 39 | return result; |
| 40 | } |
| 41 | |
| 42 | void BlobFileWriter::SetTotalBlobs(size_t total_blobs) { |
| 43 | total_blobs_ = total_blobs; |
Sen Jiang | af1575f | 2015-11-09 13:34:16 -0800 | [diff] [blame] | 44 | stored_blobs_ = 0; |
Sen Jiang | 8cc502d | 2015-08-10 10:04:54 -0700 | [diff] [blame] | 45 | } |
| 46 | |
| 47 | } // namespace chromeos_update_engine |