From cc758d9609114ba2ad8011f02f1dc890a7b7225e Mon Sep 17 00:00:00 2001 From: Kelvin Zhang Date: Fri, 6 Sep 2024 14:45:41 -0700 Subject: [PATCH] Create parent directories before writing to output target files Sometimes the output path's parent directory doesn't exist yet, causing a failure in open() syscall. Test: sign_target_files_apks solios-target_files-12328286.zip solis_signed.zip Bug: 364967828 Change-Id: I85f91ca5d1321c1ba763cac058eb28acc7f48e70 --- tools/releasetools/common.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/tools/releasetools/common.py b/tools/releasetools/common.py index edd436617d..f04dfb703d 100644 --- a/tools/releasetools/common.py +++ b/tools/releasetools/common.py @@ -3238,7 +3238,9 @@ class File(object): return t def WriteToDir(self, d): - with open(os.path.join(d, self.name), "wb") as fp: + output_path = os.path.join(d, self.name) + os.makedirs(os.path.dirname(output_path), exist_ok=True) + with open(output_path, "wb") as fp: fp.write(self.data) def AddToZip(self, z, compression=None):