Home | History | Annotate | Download | only in payload_generator
      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 
     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 &&
     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;
     44   stored_blobs_ = 0;
     45 }
     46 
     47 }  // namespace chromeos_update_engine
     48