• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 //
16 
17 #include "update_engine/payload_generator/blob_file_writer.h"
18 
19 #include "update_engine/common/utils.h"
20 
21 namespace chromeos_update_engine {
22 
StoreBlob(const brillo::Blob & blob)23 off_t BlobFileWriter::StoreBlob(const brillo::Blob& blob) {
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 && (10 * (stored_blobs_ - 1) / total_blobs_) !=
33                               (10 * stored_blobs_ / total_blobs_)) {
34     LOG(INFO) << (100 * stored_blobs_ / total_blobs_) << "% complete "
35               << stored_blobs_ << "/" << total_blobs_
36               << " ops (output size: " << *blob_file_size_ << ")";
37   }
38   return result;
39 }
40 
SetTotalBlobs(size_t total_blobs)41 void BlobFileWriter::SetTotalBlobs(size_t total_blobs) {
42   total_blobs_ = total_blobs;
43   stored_blobs_ = 0;
44 }
45 
46 }  // namespace chromeos_update_engine
47