From 3eb353cdb0d62223b539820ad54a705687038a23 Mon Sep 17 00:00:00 2001 From: Tao Bao Date: Mon, 22 May 2017 23:16:32 -0700 Subject: [PATCH] Fix the symlink detection when signing TF.zip. We used to check for 'attr >> 16 == 0xa1ff' (i.e. 0o120777) to detect symlinks in the input target_files zip (TF.zip). This becomes broken after we switch to soong_zip, which packs symlinks with 0o120700. This CL fixes the issue by using stat.S_ISLNK() instead. Note that we don't need to stage the files with the exact permission bits as in the input TF.zip. Because this part is covered by mkbootfs by using the canned or the compiled-in fs_config - as long as the files/directories are accessible and the symlinks are created. Bug: 38455129 Test: sign_target_files_apks.py on bullhead TF.zip. Check the checksums in SYSTEM/bin/install-recovery.sh. Change-Id: I51c1fc9a257fb3f18c16c2ed71528abaa6f7d9c9 (cherry picked from commit 406050bdb6b9615536538f41078145cf6925e3d2) --- tools/releasetools/sign_target_files_apks.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/tools/releasetools/sign_target_files_apks.py b/tools/releasetools/sign_target_files_apks.py index 394ad0a88..2e0b44dac 100755 --- a/tools/releasetools/sign_target_files_apks.py +++ b/tools/releasetools/sign_target_files_apks.py @@ -93,6 +93,7 @@ import errno import os import re import shutil +import stat import subprocess import tempfile import zipfile @@ -191,6 +192,9 @@ def ProcessTargetFiles(input_tf_zip, output_tf_zip, misc_info, # tmpdir will only be used to regenerate the recovery-from-boot patch. tmpdir = tempfile.mkdtemp() + # We're not setting the permissions precisely as in attr, because that work + # will be handled by mkbootfs (using the values from the canned or the + # compiled-in fs_config). def write_to_temp(fn, attr, data): fn = os.path.join(tmpdir, fn) if fn.endswith("/"): @@ -201,7 +205,7 @@ def ProcessTargetFiles(input_tf_zip, output_tf_zip, misc_info, if d and not os.path.exists(d): os.makedirs(d) - if attr >> 16 == 0xa1ff: + if stat.S_ISLNK(attr >> 16): os.symlink(data, fn) else: with open(fn, "wb") as f: