blob_file_writer.cc 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  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. #include "update_engine/payload_generator/blob_file_writer.h"
  17. #include "update_engine/common/utils.h"
  18. namespace chromeos_update_engine {
  19. off_t BlobFileWriter::StoreBlob(const brillo::Blob& blob) {
  20. base::AutoLock auto_lock(blob_mutex_);
  21. if (!utils::PWriteAll(blob_fd_, blob.data(), blob.size(), *blob_file_size_))
  22. return -1;
  23. off_t result = *blob_file_size_;
  24. *blob_file_size_ += blob.size();
  25. stored_blobs_++;
  26. if (total_blobs_ > 0 && (10 * (stored_blobs_ - 1) / total_blobs_) !=
  27. (10 * stored_blobs_ / total_blobs_)) {
  28. LOG(INFO) << (100 * stored_blobs_ / total_blobs_) << "% complete "
  29. << stored_blobs_ << "/" << total_blobs_
  30. << " ops (output size: " << *blob_file_size_ << ")";
  31. }
  32. return result;
  33. }
  34. void BlobFileWriter::SetTotalBlobs(size_t total_blobs) {
  35. total_blobs_ = total_blobs;
  36. stored_blobs_ = 0;
  37. }
  38. } // namespace chromeos_update_engine