File tree Expand file tree Collapse file tree 4 files changed +38
-1
lines changed Expand file tree Collapse file tree 4 files changed +38
-1
lines changed Original file line number Diff line number Diff line change @@ -107,6 +107,7 @@ Pierre-Jean Campigotto
107107Pierre-Luc Tessier Gagné
108108Prakhar Gurunani
109109Rahul Bangar
110+ Robert Gomulka
110111Ronald Evers
111112Ronny Pfannschmidt
112113Ryuichi Ohori
Original file line number Diff line number Diff line change 1+ Remove read-only files in ``ensure_empty_dir ``.
Original file line number Diff line number Diff line change 1+ import errno
2+ import os
13import shutil
4+ import stat
25
36from tox import reporter
47
58
69def ensure_empty_dir (path ):
710 if path .check ():
811 reporter .info (" removing {}" .format (path ))
9- shutil .rmtree (str (path ), ignore_errors = True )
12+ shutil .rmtree (str (path ), onerror = _remove_readonly )
1013 path .ensure (dir = 1 )
14+
15+
16+ def _remove_readonly (func , path , exc_info ):
17+ """Clear the readonly bit and reattempt the removal."""
18+ if isinstance (exc_info [1 ], OSError ):
19+ if exc_info [1 ].errno == errno .EACCES :
20+ try :
21+ os .chmod (path , stat .S_IWRITE )
22+ func (path )
23+ except Exception :
24+ # when second attempt fails, ignore the problem
25+ # to maintain some level of backward compatibility
26+ pass
Original file line number Diff line number Diff line change 1+ import os
2+ from stat import S_IREAD
3+
4+ from tox .util .path import ensure_empty_dir
5+
6+
7+ def test_remove_read_only (tmpdir ):
8+ nested_dir = tmpdir / "nested_dir"
9+ nested_dir .mkdir ()
10+
11+ # create read-only file
12+ read_only_file = nested_dir / "tmpfile.txt"
13+ with open (str (read_only_file ), "w" ):
14+ pass
15+ os .chmod (str (read_only_file ), S_IREAD )
16+
17+ ensure_empty_dir (nested_dir )
18+
19+ assert not os .listdir (str (nested_dir ))
You can’t perform that action at this time.
0 commit comments