1#!/usr/bin/env python3 2# 3# SPDX-License-Identifier: GPL-2.0-only 4# 5# Allow copying of $1 to $2 but if files in $1 disappear during the copy operation, 6# don't error. 7# Also don't error if $1 disappears. 8# 9 10import sys 11import os 12import shutil 13 14def copytree(src, dst, symlinks=False, ignore=None): 15 """Based on shutil.copytree""" 16 names = os.listdir(src) 17 try: 18 os.makedirs(dst) 19 except OSError: 20 # Already exists 21 pass 22 errors = [] 23 for name in names: 24 srcname = os.path.join(src, name) 25 dstname = os.path.join(dst, name) 26 try: 27 d = dstname 28 if os.path.isdir(dstname): 29 d = os.path.join(dstname, os.path.basename(srcname)) 30 if os.path.exists(d): 31 continue 32 try: 33 os.link(srcname, dstname) 34 except OSError: 35 shutil.copy2(srcname, dstname) 36 # catch the Error from the recursive copytree so that we can 37 # continue with other files 38 except shutil.Error as err: 39 errors.extend(err.args[0]) 40 except EnvironmentError as why: 41 errors.append((srcname, dstname, str(why))) 42 try: 43 shutil.copystat(src, dst) 44 except OSError as why: 45 errors.extend((src, dst, str(why))) 46 if errors: 47 raise shutil.Error(errors) 48 49try: 50 copytree(sys.argv[1], sys.argv[2]) 51except shutil.Error: 52 pass 53except OSError: 54 pass 55