blob_file_writer.cc revision 8cc502dacbccdab96824d42287f230ce04004784
1// Copyright 2015 The Chromium OS Authors. All rights reserved.
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5#include "update_engine/payload_generator/blob_file_writer.h"
6
7#include "update_engine/utils.h"
8
9namespace chromeos_update_engine {
10
11off_t BlobFileWriter::StoreBlob(const chromeos::Blob& blob) {
12  base::AutoLock auto_lock(blob_mutex_);
13  if (!utils::PWriteAll(blob_fd_, blob.data(), blob.size(), *blob_file_size_))
14    return -1;
15
16  off_t result = *blob_file_size_;
17  *blob_file_size_ += blob.size();
18
19  stored_blobs_++;
20  if (total_blobs_ > 0 &&
21      (10 * (stored_blobs_ - 1) / total_blobs_) !=
22      (10 * stored_blobs_ / total_blobs_)) {
23    LOG(INFO) << (100 * stored_blobs_ / total_blobs_)
24              << "% complete " << stored_blobs_ << "/" << total_blobs_
25              << " ops (output size: " << *blob_file_size_ << ")";
26  }
27  return result;
28}
29
30void BlobFileWriter::SetTotalBlobs(size_t total_blobs) {
31  total_blobs_ = total_blobs;
32}
33
34}  // namespace chromeos_update_engine
35