diff options
author | Kelvin Zhang <zhangkelvin@google.com> | 2021-05-07 15:06:39 +0000 |
---|---|---|
committer | Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com> | 2021-05-07 15:06:39 +0000 |
commit | 70a2cda2632defdffdfed765f09e2788dc199555 (patch) | |
tree | 0b7e82bc63ca825711d8836e8cf51d8232971281 /common/utils.h | |
parent | 27578a724282f105467c941c472a90e4b271c86d (diff) | |
parent | 5465b60e7b004ced480da2d6f5b47d49b3ca1611 (diff) |
Fix verity discarded bug am: 9105f4baeb am: 15242fd179 am: 5465b60e7b
Original change: https://android-review.googlesource.com/c/platform/system/update_engine/+/1686865
Change-Id: I3012b932910d78275c91559a3b3ddcb1032746e3
Diffstat (limited to 'common/utils.h')
-rw-r--r-- | common/utils.h | 8 |
1 files changed, 7 insertions, 1 deletions
diff --git a/common/utils.h b/common/utils.h index 5f6e4757..59f236ef 100644 --- a/common/utils.h +++ b/common/utils.h @@ -399,13 +399,19 @@ class ScopedTempFile { // If |open_fd| is true, a writable file descriptor will be opened for this // file. - explicit ScopedTempFile(const std::string& pattern, bool open_fd = false) { + // If |truncate_size| is non-zero, truncate file to that size on creation. + explicit ScopedTempFile(const std::string& pattern, + bool open_fd = false, + size_t truncate_size = 0) { CHECK(utils::MakeTempFile(pattern, &path_, open_fd ? &fd_ : nullptr)); unlinker_.reset(new ScopedPathUnlinker(path_)); if (open_fd) { CHECK_GE(fd_, 0); fd_closer_.reset(new ScopedFdCloser(&fd_)); } + if (truncate_size > 0) { + CHECK_EQ(0, truncate(path_.c_str(), truncate_size)); + } } virtual ~ScopedTempFile() = default; |