Implement custom "rmtree"; resolve issue with Windows and .git

This commit is contained in:
Ivan Kravets
2016-08-05 18:43:20 +03:00
parent c64354ebcc
commit db267513ca
6 changed files with 29 additions and 24 deletions

View File

@@ -17,12 +17,14 @@ import functools
import json
import os
import re
import stat
import subprocess
import sys
from glob import glob
from os.path import (abspath, basename, dirname, expanduser, isdir, isfile,
join, splitdrive)
from platform import system, uname
from shutil import rmtree
from threading import Thread
from platformio import __apiip__, __apiurl__, __version__, exception
@@ -454,3 +456,12 @@ def where_is_program(program, envpath=None):
def pepver_to_semver(pepver):
return re.sub(r"(\.\d+)\.?(dev|a|b|rc|post)", r"\1-\2", pepver, 1)
def rmtree_(path):
def _onerror(_, name, __):
os.chmod(name, stat.S_IWRITE)
os.remove(name)
return rmtree(path, onerror=_onerror)