blob: 8225df47c7abca9118e67f6f259662a773330666 [file] [log] [blame]
Alex Deymoaea4c1c2015-08-19 20:24:43 -07001//
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 Jiang8cc502d2015-08-10 10:04:54 -070016
17#include "update_engine/payload_generator/blob_file_writer.h"
18
Alex Deymo39910dc2015-11-09 17:04:30 -080019#include "update_engine/common/utils.h"
Sen Jiang8cc502d2015-08-10 10:04:54 -070020
21namespace chromeos_update_engine {
22
Alex Vakulenko3f39d5c2015-10-13 09:27:13 -070023off_t BlobFileWriter::StoreBlob(const brillo::Blob& blob) {
Sen Jiang8cc502d2015-08-10 10:04:54 -070024 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
42void BlobFileWriter::SetTotalBlobs(size_t total_blobs) {
43 total_blobs_ = total_blobs;
Sen Jiangaf1575f2015-11-09 13:34:16 -080044 stored_blobs_ = 0;
Sen Jiang8cc502d2015-08-10 10:04:54 -070045}
46
47} // namespace chromeos_update_engine