|
2 | 2 |
|
3 | 3 | import click |
4 | 4 |
|
| 5 | +from devchat.utils import rmtree |
| 6 | + |
5 | 7 |
|
6 | 8 | @click.command( |
7 | 9 | help="The 'command' argument is the name of the command to run or get information about." |
@@ -115,28 +117,6 @@ def run( |
115 | 117 | return |
116 | 118 |
|
117 | 119 |
|
118 | | -def __onerror(func, path, _1): |
119 | | - """ |
120 | | - Error handler for shutil.rmtree. |
121 | | -
|
122 | | - If the error is due to an access error (read only file) |
123 | | - it attempts to add write permission and then retries. |
124 | | -
|
125 | | - If the error is for another reason it re-raises the error. |
126 | | -
|
127 | | - Usage : shutil.rmtree(path, onerror=onerror) |
128 | | - """ |
129 | | - import os |
130 | | - import stat |
131 | | - |
132 | | - # Check if file access issue |
133 | | - if not os.access(path, os.W_OK): |
134 | | - # Try to change the file to be writable (remove read-only flag) |
135 | | - os.chmod(path, stat.S_IWUSR) |
136 | | - # Retry the function that failed |
137 | | - func(path) |
138 | | - |
139 | | - |
140 | 120 | def __make_files_writable(directory): |
141 | 121 | """ |
142 | 122 | Recursively make all files in the directory writable. |
@@ -180,9 +160,9 @@ def _clone_or_pull_git_repo(target_dir: str, repo_urls: List[Tuple[str, str]], z |
180 | 160 | bak_dir = target_dir + "_bak" |
181 | 161 | new_dir = target_dir + "_old" |
182 | 162 | if os.path.exists(new_dir): |
183 | | - shutil.rmtree(new_dir, onerror=__onerror) |
| 163 | + rmtree(new_dir) |
184 | 164 | if os.path.exists(bak_dir): |
185 | | - shutil.rmtree(bak_dir, onerror=__onerror) |
| 165 | + rmtree(bak_dir) |
186 | 166 | print(f"{target_dir} is already exists. Moved to {new_dir}") |
187 | 167 | clone_git_repo(bak_dir, repo_urls) |
188 | 168 | try: |
|
0 commit comments