Only try to remove symlink or delete the directory is the path exists(it will not exist when build for the first time)

This commit is contained in:
amzn-sj
2021-04-26 15:57:47 -07:00
parent 6c6bd09ee5
commit 745d5585e1
+9 -8
View File
@@ -312,14 +312,15 @@ def create_link(src:pathlib.Path, tgt:pathlib.Path, copy):
tgt = pathlib.Path(tgt)
if copy:
# Remove the exist target
if tgt.is_symlink():
tgt.unlink()
else:
def remove_readonly(func, path, _):
"Clear the readonly bit and reattempt the removal"
os.chmod(path, stat.S_IWRITE)
func(path)
shutil.rmtree(tgt, onerror=remove_readonly)
if tgt.exists():
if tgt.is_symlink():
tgt.unlink()
else:
def remove_readonly(func, path, _):
"Clear the readonly bit and reattempt the removal"
os.chmod(path, stat.S_IWRITE)
func(path)
shutil.rmtree(tgt, onerror=remove_readonly)
logging.debug(f'Copying from {src} to {tgt}')
shutil.copytree(str(src), str(tgt), symlinks=False)