summaryrefslogtreecommitdiff
path: root/scripts/update_payload/applier.py
diff options
context:
space:
mode:
authorGilad Arnold <garnold@chromium.org>2013-05-23 16:13:38 -0700
committerChromeBot <chrome-bot@google.com>2013-05-24 11:36:49 -0700
commite5fdf189ce3a4628f02a0bd5e09694bf7b815cdf (patch)
tree5a3a186031be7d878a309eda61ac01ff97b8d820 /scripts/update_payload/applier.py
parent7a7edfd034e37663337049ccb0aa59467f3b8fd1 (diff)
paycheck: truncate partitions resulting from applying a payload
Since the correctness of the result only encompasses the filesystem (or otherwise "meaningful data") on the target partition, it is desirable to actually get rid of whatever is past that point. There are different reasons for the presence of such extra space in delta updates, including remnants from a source partition that served as baseline for a delta update, or scratch space used by MOVE operations for breaking cycles. We make truncation the default behavior, although it can be suppressed by passing the right flag (truncate_to_expected_size=False). Note that this change is necessary for comparing the results of applying a payload to the partitions as they are extracted from a target image, which is to be attempted during payload generation. This also fixes tiny gpylint complaints. BUG=chromium:241283 TEST=Emitted partition files truncated as expected Change-Id: Ibb71e4f2305ec41224afdc503168ae02c312f6fe Reviewed-on: https://gerrit.chromium.org/gerrit/56532 Tested-by: Gilad Arnold <garnold@chromium.org> Commit-Queue: Gilad Arnold <garnold@chromium.org> Reviewed-by: Gilad Arnold <garnold@chromium.org>
Diffstat (limited to 'scripts/update_payload/applier.py')
-rw-r--r--scripts/update_payload/applier.py13
1 files changed, 12 insertions, 1 deletions
diff --git a/scripts/update_payload/applier.py b/scripts/update_payload/applier.py
index f5ae6b73..52a70f91 100644
--- a/scripts/update_payload/applier.py
+++ b/scripts/update_payload/applier.py
@@ -192,18 +192,23 @@ class PayloadApplier(object):
"""
- def __init__(self, payload, bsdiff_in_place=True):
+ def __init__(self, payload, bsdiff_in_place=True,
+ truncate_to_expected_size=True):
"""Initialize the applier.
Args:
payload: the payload object to check
bsdiff_in_place: whether to perform BSDIFF operation in-place (optional)
+ truncate_to_expected_size: whether to truncate the resulting partitions
+ to their expected sizes, as specified in the
+ payload (optional)
"""
assert payload.is_init, 'uninitialized update payload'
self.payload = payload
self.block_size = payload.manifest.block_size
self.bsdiff_in_place = bsdiff_in_place
+ self.truncate_to_expected_size = truncate_to_expected_size
def _ApplyReplaceOperation(self, op, op_name, out_data, part_file, part_size):
"""Applies a REPLACE{,_BZ} operation.
@@ -430,6 +435,12 @@ class PayloadApplier(object):
with open(new_part_file_name, 'r+b') as new_part_file:
self._ApplyOperations(operations, base_name, new_part_file,
new_part_info.size)
+ # Truncate the result, if so instructed.
+ if self.truncate_to_expected_size:
+ new_part_file.seek(0, 2)
+ if new_part_file.tell() > new_part_info.size:
+ new_part_file.seek(new_part_info.size)
+ new_part_file.truncate()
# Verify the resulting partition.
with open(new_part_file_name, 'rb') as new_part_file: