update_payload: Remove 'buffer' in applier.py
'memoryview' replaces 'buffer' in python3, but not all the signatures are the
same in both functions. The output of memoryview has to be converted to bytes,
but buffer's doesn't. This difference could cause the script to fail when
using python2.
Set the type of multiple strings to byte.
BUG=chromium:1027199
TEST=cros_generate_update_payload --image ~/trunk/src/build/images/eve/R80-12705.0.2019_11_23_1521-a1/chromiumos_image.bin --src_image ~/trunk/src/build/images/eve/R80-12705.0.2019_11_23_1521-a1/chromiumos_image.bin --output ~/delete/ttt2 --check
TEST=cros_workon_make update_payload --test
TEST=tryjob. Note: tryjob fails because tryjob runs without the updates to the sdk from this CL. see chromium:1028178
Change-Id: Ic05892d1e26f12e33a661b590039821329379042
Reviewed-on: https://chromium-review.googlesource.com/c/aosp/platform/system/update_engine/+/1933128
Tested-by: Andrew Lassalle <andrewlassalle@chromium.org>
Reviewed-by: Amin Hassani <ahassani@chromium.org>
Reviewed-by: Mike Frysinger <vapier@chromium.org>
Auto-Submit: Andrew Lassalle <andrewlassalle@chromium.org>
diff --git a/scripts/update_payload/applier.py b/scripts/update_payload/applier.py
index 7eaa07a..ce1998f 100644
--- a/scripts/update_payload/applier.py
+++ b/scripts/update_payload/applier.py
@@ -52,9 +52,6 @@
from update_payload import common
from update_payload.error import PayloadError
-# buffer is not supported in python3, but memoryview has the same functionality
-if sys.version_info.major >= 3:
- buffer = memoryview # pylint: disable=invalid-name, redefined-builtin
#
# Helper functions.
#
@@ -146,10 +143,8 @@
if not data_length:
raise PayloadError('%s: more write extents than data' % ex_name)
write_length = min(data_length, ex.num_blocks * block_size)
-
file_obj.seek(ex.start_block * block_size)
- data_view = buffer(data, data_offset, write_length)
- file_obj.write(data_view)
+ file_obj.write(data[data_offset:(data_offset + write_length)])
data_offset += write_length
data_length -= write_length
@@ -283,7 +278,7 @@
# Pad with zeros if necessary.
if data_end > data_length:
padding = data_end - data_length
- out_data += '\0' * padding
+ out_data += b'\0' * padding
self.payload.payload_file.seek(start_block * block_size)
part_file.seek(start_block * block_size)
@@ -314,7 +309,7 @@
# pylint: disable=unused-variable
for ex, ex_name in common.ExtentIter(op.dst_extents, base_name):
part_file.seek(ex.start_block * block_size)
- part_file.write('\0' * (ex.num_blocks * block_size))
+ part_file.write(b'\0' * (ex.num_blocks * block_size))
def _ApplySourceCopyOperation(self, op, op_name, old_part_file,
new_part_file):
@@ -424,7 +419,7 @@
# Pad with zeros past the total output length.
if pad_len:
new_part_file.seek(pad_off)
- new_part_file.write('\0' * pad_len)
+ new_part_file.write(b'\0' * pad_len)
else:
# Gather input raw data and write to a temp file.
input_part_file = old_part_file if old_part_file else new_part_file
@@ -467,7 +462,7 @@
# Write output back to partition, with padding.
unaligned_out_len = len(out_data) % block_size
if unaligned_out_len:
- out_data += '\0' * (block_size - unaligned_out_len)
+ out_data += b'\0' * (block_size - unaligned_out_len)
_WriteExtents(new_part_file, out_data, op.dst_extents, block_size,
'%s.dst_extents' % op_name)