Skip to content

Commit c12d86b

Browse files
sdispatershawegit
andcommitted
Fix permission errors when adding/removing git dependencies on Windows
Co-authored-by: shawegit <[email protected]> Co-authored-by: Sébastien Eustace <[email protected]>
1 parent fa728d0 commit c12d86b

File tree

4 files changed

+23
-4
lines changed

4 files changed

+23
-4
lines changed

CHANGELOG.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,12 @@
11
# Change Log
22

3+
## [Unreleased]
4+
5+
### Fixed
6+
7+
- Fixed permission errors when adding/removing git dependencies on Windows.
8+
9+
310
## [0.12.7] - 2018-11-08
411

512
### Fixed

poetry/installation/pip_installer.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
from poetry.config import Config
88
from poetry.utils.helpers import get_http_basic_auth
9+
from poetry.utils.helpers import safe_rmtree
910

1011

1112
try:
@@ -97,7 +98,7 @@ def remove(self, package):
9798
if package.source_type == "git":
9899
src_dir = self._env.path / "src" / package.name
99100
if src_dir.exists():
100-
shutil.rmtree(str(src_dir))
101+
safe_rmtree(str(src_dir))
101102

102103
try:
103104
self.run("uninstall", package.name, "-y")
@@ -208,7 +209,7 @@ def install_git(self, package):
208209

209210
src_dir = self._env.path / "src" / package.name
210211
if src_dir.exists():
211-
shutil.rmtree(str(src_dir))
212+
safe_rmtree(str(src_dir))
212213

213214
src_dir.parent.mkdir(exist_ok=True)
214215

poetry/puzzle/provider.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@
3232
from poetry.utils._compat import PY35
3333
from poetry.utils._compat import Path
3434
from poetry.utils.helpers import parse_requires
35-
from poetry.utils.toml_file import TomlFile
35+
from poetry.utils.helpers import safe_rmtree
3636
from poetry.utils.env import Env
3737
from poetry.utils.env import EnvCommandError
3838
from poetry.utils.setup_reader import SetupReader
@@ -196,7 +196,7 @@ def search_for_vcs(self, dependency): # type: (VCSDependency) -> List[Package]
196196
except Exception:
197197
raise
198198
finally:
199-
shutil.rmtree(tmp_dir.as_posix())
199+
safe_rmtree(str(tmp_dir))
200200

201201
return [package]
202202

poetry/utils/helpers.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
1+
import os
12
import re
23
import shutil
4+
import stat
35
import tempfile
46

57
from contextlib import contextmanager
@@ -89,3 +91,12 @@ def get_http_basic_auth(
8991
return repo_auth["username"], repo_auth.get("password")
9092

9193
return None
94+
95+
96+
def _on_rm_error(func, path, exc_info):
97+
os.chmod(path, stat.S_IWRITE)
98+
func(path)
99+
100+
101+
def safe_rmtree(path):
102+
shutil.rmtree(path, onerror=_on_rm_error)

0 commit comments

Comments
 (0)