From 0e3a55252b04e8e81db7b0f5636fb6624824a5cb Mon Sep 17 00:00:00 2001 From: Marcin Juszkiewicz Date: Wed, 14 Sep 2022 15:49:48 +0200 Subject: Python 3.8+ has better shutil.copytree() doc says: > If dirs_exist_ok is false (the default) and dst already exists, a > FileExistsError is raised. If dirs_exist_ok is true, the copying > operation will continue if it encounters existing directories, and files > within the dst tree will be overwritten by corresponding files from the > src tree. So we do not have to copy dirs/files one by one and tell shutil.copytree() to handle everything. Change-Id: I97d9c8261351b8fd88f088c1463cc508e07792e7 --- kolla/image/build.py | 11 +---------- 1 file changed, 1 insertion(+), 10 deletions(-) diff --git a/kolla/image/build.py b/kolla/image/build.py index 546404ab5..b03bb55d7 100755 --- a/kolla/image/build.py +++ b/kolla/image/build.py @@ -744,16 +744,7 @@ class KollaWorker(object): ) def copy_dir(self, src, dest): - if not os.path.isdir(dest): - shutil.copytree(src, dest) - else: - for file in os.listdir(src): - src_path = os.path.join(src, file) - dest_path = os.path.join(dest, file) - if os.path.isdir(src_path): - self.copy_dir(src_path, dest_path) - else: - shutil.copy2(src_path, dest_path) + shutil.copytree(src, dest, dirs_exist_ok=True) def setup_working_dir(self): """Creates a working directory for use while building.""" -- cgit v1.2.3