Add chmod to gradle_dists to ensure dist folders are writable

Change-Id: Id7fe01b1a73fe3e5b52f7336f37efc25a4c87f47
Reviewed-on: https://flutter-review.googlesource.com/c/recipes/+/81620
Reviewed-by: John McDole <codefu@google.com>
Commit-Queue: Matt Boetger <boetger@google.com>
diff --git a/recipe_modules/flutter_deps/api.py b/recipe_modules/flutter_deps/api.py
index fe1893a..d9b8605 100644
--- a/recipe_modules/flutter_deps/api.py
+++ b/recipe_modules/flutter_deps/api.py
@@ -443,6 +443,13 @@
           pkgs.add_package(f'flutter/gradle_dists/{clean_version}', 'latest')
       if pkgs.packages:
         self.m.cipd.ensure(gradle_wrapper_dists_dir, pkgs)
+        if self.m.path.exists(gradle_wrapper_dists_dir):
+          path_str = str(gradle_wrapper_dists_dir)
+          if self.m.platform.is_win:
+            path_str = '\\\\?\\' + path_str
+          self.m.file.chmod(
+              'Make Gradle dists writable', path_str, '755', recursive=True
+          )
 
   def firebase(self, env, env_prefixes, version='latest'):
     """Installs firebase binary.
diff --git a/recipe_modules/flutter_deps/examples/full.expected/gradle_cache_exists.json b/recipe_modules/flutter_deps/examples/full.expected/gradle_cache_exists.json
index 5b31198..3d3a395 100644
--- a/recipe_modules/flutter_deps/examples/full.expected/gradle_cache_exists.json
+++ b/recipe_modules/flutter_deps/examples/full.expected/gradle_cache_exists.json
@@ -561,6 +561,25 @@
       "RECIPE_MODULE[recipe_engine::file]/resources/fileutil.py",
       "--json-output",
       "/path/to/tmp/json",
+      "chmod",
+      "[CACHE]/gradle/wrapper/dists",
+      "--mode",
+      "755",
+      "--recursive"
+    ],
+    "infra_step": true,
+    "name": "Gradle Wrapper dependency.Make Gradle dists writable",
+    "~followup_annotations": [
+      "@@@STEP_NEST_LEVEL@1@@@"
+    ]
+  },
+  {
+    "cmd": [
+      "vpython3",
+      "-u",
+      "RECIPE_MODULE[recipe_engine::file]/resources/fileutil.py",
+      "--json-output",
+      "/path/to/tmp/json",
       "ensure-directory",
       "--mode",
       "0o777",
diff --git a/recipe_modules/flutter_deps/examples/full.expected/gradle_cache_exists_win.json b/recipe_modules/flutter_deps/examples/full.expected/gradle_cache_exists_win.json
index 3d0c54d..113f208 100644
--- a/recipe_modules/flutter_deps/examples/full.expected/gradle_cache_exists_win.json
+++ b/recipe_modules/flutter_deps/examples/full.expected/gradle_cache_exists_win.json
@@ -561,6 +561,25 @@
       "RECIPE_MODULE[recipe_engine::file]\\resources\\fileutil.py",
       "--json-output",
       "/path/to/tmp/json",
+      "chmod",
+      "\\\\?\\[CACHE]\\gradle\\wrapper\\dists",
+      "--mode",
+      "755",
+      "--recursive"
+    ],
+    "infra_step": true,
+    "name": "Gradle Wrapper dependency.Make Gradle dists writable",
+    "~followup_annotations": [
+      "@@@STEP_NEST_LEVEL@1@@@"
+    ]
+  },
+  {
+    "cmd": [
+      "vpython3",
+      "-u",
+      "RECIPE_MODULE[recipe_engine::file]\\resources\\fileutil.py",
+      "--json-output",
+      "/path/to/tmp/json",
       "ensure-directory",
       "--mode",
       "0o777",