Skip to content
Snippets Groups Projects
Commit 721d7499 authored by Attila Farkas's avatar Attila Farkas
Browse files

Remove readonly files in .git directory

parent 23b5cdf8
No related branches found
No related tags found
2 merge requests!38Version 2.0.1,!37Resolve "CSC cannot overwrite old intermediate definition"
import os
from pathlib import Path
import shutil
import stat
from typing import Union, List, Dict
import jinja2
......@@ -57,6 +58,12 @@ class Writer:
output = template.render(data=data, ruby_variables=ruby_variables)
Writer._write_to_file(output_file, output)
@staticmethod
def _on_rmtree_error(func, path, exc_info):
"""On error during rmtree, try to make the file writable"""
os.chmod(path, stat.S_IWRITE)
os.unlink(path)
@staticmethod
def clone_git_repository(repository: str, location: Path, cloned_dir: str) -> None:
"""Clone a git repository to the provided location and removes .git
......@@ -74,7 +81,8 @@ class Writer:
raise RuntimeError(f"Could not clone repository: {repository}")
try:
shutil.rmtree(location.joinpath(cloned_dir).joinpath(".git"))
shutil.rmtree(location.joinpath(cloned_dir).joinpath(".git"),
onerror=Writer._on_rmtree_error)
except OSError:
pass
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment