From 2a3bbb508520a620409e606a0c3e758a8987d5f6 Mon Sep 17 00:00:00 2001 From: Mike Schuchardt Date: Wed, 28 Apr 2021 12:10:06 -0700 Subject: scripts: Switch from mkpath to makedirs distutils.dir_util.mkpath will not re-create a directory if it has been removed with shutil.rmtree because it caches the filesystem under the hood. This was causing the clone retry to fail on the second iteration every time. Switch to using os.makedirs for equivalent functionality without the cache. --- scripts/update_deps.py | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) (limited to 'scripts') diff --git a/scripts/update_deps.py b/scripts/update_deps.py index ea21c9fb..ffd928f6 100755 --- a/scripts/update_deps.py +++ b/scripts/update_deps.py @@ -242,7 +242,6 @@ from __future__ import print_function import argparse import json -import distutils.dir_util import os.path import subprocess import sys @@ -275,6 +274,12 @@ def on_rm_error( func, path, exc_info): os.chmod( path, stat.S_IWRITE ) os.unlink( path ) +def make_or_exist_dirs(path): + "Wrapper for os.makedirs that tolerates the directory already existing" + # Could use os.makedirs(path, exist_ok=True) if we drop python2 + if not os.path.isdir(path): + os.makedirs(path) + def command_output(cmd, directory, fail_ok=False): """Runs a command in a directory and returns its standard output stream. @@ -346,7 +351,7 @@ class GoodRepo(object): def Clone(self, retries=10, retry_seconds=60): print('Cloning {n} into {d}'.format(n=self.name, d=self.repo_dir)) for retry in range(retries): - distutils.dir_util.mkpath(self.repo_dir) + make_or_exist_dirs(self.repo_dir) try: command_output(['git', 'clone', self.url, '.'], self.repo_dir) # If we get here, we didn't raise an error @@ -426,7 +431,7 @@ class GoodRepo(object): shutil.rmtree(self.install_dir) # Create and change to build directory - distutils.dir_util.mkpath(self.build_dir) + make_or_exist_dirs(self.build_dir) os.chdir(self.build_dir) cmake_cmd = [ @@ -665,7 +670,7 @@ def main(): save_cwd = os.getcwd() # Create working "top" directory if needed - distutils.dir_util.mkpath(args.dir) + make_or_exist_dirs(args.dir) abs_top_dir = os.path.abspath(args.dir) repos = GetGoodRepos(args) -- cgit v1.2.3