Skip to content
This repository was archived by the owner on Aug 7, 2025. It is now read-only.

Commit 84097fd

Browse files
committed
Don't alter a list we're iterating through
Fix a couple of places where we're trying to remove files from the files list while we're iterating through it -- replicate the change elsewhere to keep a temporary list of the files to remove, then iterate through *that* list after iterating through the global files list.
1 parent c2cd51b commit 84097fd

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

patchfilter.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -98,9 +98,13 @@ def zap_entire_file_end(filename):
9898
global files
9999
global files_chunks
100100
global files_header
101+
files_to_remove = list()
101102
for file in files:
102103
if file.endswith(filename):
103-
files.remove(file)
104+
# Don't modify the original list while iterating over it
105+
files_to_remove.append(file)
106+
for file in files_to_remove:
107+
files.remove(file)
104108

105109
def zap_line_in_file_substring(filename, match):
106110
global header
@@ -186,7 +190,7 @@ def zap_empty_chunks():
186190
files_to_remove = list()
187191
for file in files:
188192
if file not in files_chunks:
189-
files.remove(file)
193+
files_to_remove.append(file)
190194
continue
191195
to_remove = list()
192196
for chunk in files_chunks[file]:

0 commit comments

Comments
 (0)