This repository was archived by the owner on Jun 15, 2023. It is now read-only.
File tree Expand file tree Collapse file tree 1 file changed +17
-3
lines changed Expand file tree Collapse file tree 1 file changed +17
-3
lines changed Original file line number Diff line number Diff line change 17
17
# Documentation build script for AWS Sphinx documentation on GitHub.
18
18
# ------------------------------------------------------------------
19
19
20
- import sys , os
20
+ import sys , os , stat , errno
21
21
import subprocess
22
22
import shutil
23
23
42
42
SOURCE_DIR = 'doc_source'
43
43
44
44
45
+ def handle_remove_readonly (func , path , excinfo ):
46
+ """Handler for shutil.rmtree() failure
47
+
48
+ If the removal failed because of Access denied error due to a R/O file, change the file's
49
+ permissions to R/W and retry the removal operation.
50
+ """
51
+
52
+ if excinfo [1 ].errno == errno .EACCES :
53
+ os .chmod (path , stat .S_IRWXU | stat .S_IRWXG | stat .S_IRWXO ) # 0777
54
+ func (path )
55
+ else :
56
+ raise excinfo [0 ]
57
+
58
+
45
59
def check_and_remove_dir (dir_name ):
46
60
"""Check to see if the named directory exists. If it does, then remove it.
47
61
Throw an exception if the directory can't be removed."""
48
62
49
63
if os .path .exists (dir_name ):
50
64
print ("Removing directory: " + dir_name )
51
65
try :
52
- shutil .rmtree (dir_name )
53
- except :
66
+ shutil .rmtree (dir_name , onerror = handle_remove_readonly )
67
+ except Exception as e :
54
68
print ("Couldn't remove " + dir_name )
55
69
print ("Remove this directory before building!" )
56
70
sys .exit (1 )
You can’t perform that action at this time.
0 commit comments