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
diff --git a/tools/releasetools/common.py b/tools/releasetools/common.py
index edd4366..f04dfb7 100644
--- a/tools/releasetools/common.py
+++ b/tools/releasetools/common.py
@@ -3238,7 +3238,9 @@
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):