Skip to content

Commit 551d6d1

Browse files
authored
Fix directory deletion to handle read-only files
1 parent 12778bb commit 551d6d1

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

dev/cleanup.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,19 @@
11
import os
22
import shutil
33
import fnmatch
4+
import stat
5+
6+
def remove_readonly(func, path, excinfo):
7+
os.chmod(path, stat.S_IWRITE)
8+
func(path)
49

510
def delete_dirs(dirs):
611
for dir in dirs:
712
for root, dirnames, filenames in os.walk('.'):
813
for dirname in fnmatch.filter(dirnames, dir):
914
dir_path = os.path.join(root, dirname)
1015
try:
11-
shutil.rmtree(dir_path)
16+
shutil.rmtree(dir_path, onerror=remove_readonly)
1217
print(f"Deleted directory: {dir_path}")
1318
except FileNotFoundError:
1419
print(f"Directory not found: {dir_path}")
@@ -29,7 +34,7 @@ def delete_files(files):
2934
print(f"Error while deleting file: {file_path}. Error: {str(e)}")
3035

3136
# List of directories to delete
32-
dirs_to_delete = ["__pycache__", "build", "*.egg-info", "dist", "htmlcov"]
37+
dirs_to_delete = ["__pycache__", "build", "*.egg-info", "dist"]
3338

3439
# List of files to delete
3540
files_to_delete = ["*.tmp"]

0 commit comments

Comments
 (0)