File tree 4 files changed +38
-1
lines changed
4 files changed +38
-1
lines changed Original file line number Diff line number Diff line change @@ -107,6 +107,7 @@ Pierre-Jean Campigotto
107
107
Pierre-Luc Tessier Gagné
108
108
Prakhar Gurunani
109
109
Rahul Bangar
110
+ Robert Gomulka
110
111
Ronald Evers
111
112
Ronny Pfannschmidt
112
113
Ryuichi 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
1
3
import shutil
4
+ import stat
2
5
3
6
from tox import reporter
4
7
5
8
6
9
def ensure_empty_dir (path ):
7
10
if path .check ():
8
11
reporter .info (" removing {}" .format (path ))
9
- shutil .rmtree (str (path ), ignore_errors = True )
12
+ shutil .rmtree (str (path ), onerror = _remove_readonly )
10
13
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