Retry rmtree on windows

The dryrun on patch 1 shows that after a retry we are actually able to download the chrome binary.
https://ci.chromium.org/p/devtools-frontend/builders/try/dtf_presubmit_win64/b8886927360883830992

https://logs.chromium.org/logs/devtools-frontend/buildbucket/cr-buildbucket.appspot.com/8886927360883830992/+/steps/gclient_runhooks/0/stdout

The second patch improves the feedback, but we cannot see the initial problem manifesting anymore. We were dealing with a flaky bug anyway.


Bug: chromium:1057642
Change-Id: Icb74acf3ec742b6880a521edcde442cd984dd8d5
Reviewed-on: https://chromium-review.googlesource.com/c/devtools/devtools-frontend/+/2083313
Reviewed-by: Paul Lewis <[email protected]>
Reviewed-by: Tim van der Lippe <[email protected]>
Commit-Queue: Liviu Rau <[email protected]>
diff --git a/scripts/deps/download_chromium.py b/scripts/deps/download_chromium.py
index 0c7364c..d77033c 100644
--- a/scripts/deps/download_chromium.py
+++ b/scripts/deps/download_chromium.py
@@ -10,6 +10,7 @@
 import argparse
 import os
 import shutil
+import stat
 import sys
 import urllib
 import zipfile
@@ -24,6 +25,17 @@
     return parser.parse_args(cli_args)
 
 
+def handleAccessDeniedOnWindows(func, path, exc):
+    if not os.name == 'nt':
+        raise exc
+    if not os.access(path, os.W_OK):
+        # Is the error an access error ?
+        print("Retrying due to access error: %s ..." % exc)
+        os.chmod(path, stat.S_IWUSR)
+        func(path)
+    else:
+        raise exc
+
 def download_and_extract(options):
     BUILD_NUMBER_FILE = os.path.join(options.target, 'build_number')
     EXPECTED_BINARY = os.path.join(options.target, options.path_to_binary)
@@ -37,7 +49,7 @@
 
     # Remove previous download
     if os.path.exists(options.target):
-        shutil.rmtree(options.target)
+        shutil.rmtree(options.target, ignore_errors=False, onerror=handleAccessDeniedOnWindows)
 
     # Download again and save build number
     filehandle, headers = urllib.urlretrieve(options.url)