| 320 | @win_only |
| 321 | def rmtree(path): |
| 322 | def error_handler(func, handling_path, execinfo): |
| 323 | e = execinfo[1] |
| 324 | if e.winerror == ERRORS['PATH_NOT_FOUND']: |
| 325 | handling_path = "\\\\?\\" + handling_path # handle path over 256 symbols |
| 326 | if os.path.exists(path): |
| 327 | return func(handling_path) |
| 328 | if e.winerror == ERRORS['ACCESS_DENIED']: |
| 329 | try: |
| 330 | # removing of r/w directory with read-only files in it yields ACCESS_DENIED |
| 331 | # which is not an insuperable obstacle https://bugs.python.org/issue19643 |
| 332 | os.chmod(handling_path, stat.S_IWRITE) |
| 333 | except OSError: |
| 334 | pass |
| 335 | else: |
| 336 | # propagate true last error if this attempt fails |
| 337 | return func(handling_path) |
| 338 | raise e |
| 339 | |
| 340 | shutil.rmtree(path, onerror=error_handler) |
| 341 | |