Ensure file permissions are writable before attempting to sign.

Test: Manually using USE_BAZEL=1 use_rbe m dist (fixes a build error).
Change-Id: I1aac185f12ac430514c975103547ce211ea6c99e
diff --git a/tools/releasetools/add_img_to_target_files.py b/tools/releasetools/add_img_to_target_files.py
index d836d65..5f35d78 100644
--- a/tools/releasetools/add_img_to_target_files.py
+++ b/tools/releasetools/add_img_to_target_files.py
@@ -51,6 +51,7 @@
 import os
 import shlex
 import shutil
+import stat
 import sys
 import uuid
 import zipfile
@@ -330,6 +331,9 @@
 
   # AVB-sign the image as needed.
   if OPTIONS.info_dict.get("avb_enable") == "true":
+    # Signing requires +w
+    os.chmod(img.name, os.stat(img.name).st_mode | stat.S_IWUSR)
+
     avbtool = OPTIONS.info_dict["avb_avbtool"]
     part_size = OPTIONS.info_dict["dtbo_size"]
     # The AVB hash footer will be replaced if already present.