On Fri, 06 Jan 2017 23:49:50 -0500 Emanuel Bronshtein <[email protected]> wrote:
> #2 - apktool.yml file created by apktool is shown as file from APK & contain input filenames (might be unrelated to files content) With the attached patch, input filenames are removed from apktool.yml and the file is renamed to "APK metadata". It is still compared as a file, though. Let me know if this is a problem. Thanks, Maria Glukhova
From 7b20889378b71317bb2b2e099d870237ff9b749a Mon Sep 17 00:00:00 2001 From: Maria Glukhova <[email protected]> Date: Mon, 9 Jan 2017 02:36:47 +0300 Subject: [PATCH] Remove archive name from apktool.yml and rename it. --- diffoscope/comparators/apk.py | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/diffoscope/comparators/apk.py b/diffoscope/comparators/apk.py index 3cb1905..636cfff 100644 --- a/diffoscope/comparators/apk.py +++ b/diffoscope/comparators/apk.py @@ -31,6 +31,18 @@ from .utils.archive import Archive logger = logging.getLogger(__name__) +def filter_apk_metadata(filepath, archive_name): + new_filename = os.path.join(os.path.split(filepath)[0], "APK metadata") + logger.debug("Moving APK metadata from %s to %s", filepath, new_filename) + with open(filepath) as f: + with open(new_filename, "w") as f_out: + for line in f: + if not re.match(r'^apkFileName: %s' % os.path.basename(archive_name), line): + f_out.write(line) + os.remove(filepath) + return new_filename + + class ApkContainer(Archive): @property def path(self): @@ -53,6 +65,10 @@ class ApkContainer(Archive): for root, _, files in os.walk(self._unpacked): for f in files: abspath = os.path.join(root, f) + # apktool.yml is a file created by apktool and containing metadata information. + # Rename it to clarify. + if os.path.basename(abspath) == "apktool.yml": + abspath = filter_apk_metadata(abspath, os.path.basename(self.source.name)) relpath = abspath[len(self._unpacked)+1:] self._members.append(relpath) -- 2.11.0

