Skip to content

Commit 970462d

Browse files
committed
stats_engine: Skip non-existant source files
1 parent 0b89750 commit 970462d

File tree

1 file changed

+12
-2
lines changed

1 file changed

+12
-2
lines changed

stats_engine.py

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -133,8 +133,13 @@ def collect_stats(kernel_repo, cve_patch):
133133

134134
# check which lines of the patch have been added already
135135
for file in patch_added_lines:
136+
file_path = kernel_repo + '/' + file
137+
# just skip nonexisting files
138+
if not os.path.exists(file_path):
139+
continue
140+
136141
fp_contents = [line.rstrip('\n') for line in
137-
open(kernel_repo + '/' + file, 'r') if line.strip()]
142+
open(file_path, 'r') if line.strip()]
138143

139144
# we need this array so we can check the above block
140145
all_added = []
@@ -181,8 +186,13 @@ def collect_stats(kernel_repo, cve_patch):
181186
actually_added_lines += len(added)
182187

183188
for file in patch_removed_lines:
189+
file_path = kernel_repo + '/' + file
190+
# just skip nonexisting files
191+
if not os.path.exists(file_path):
192+
continue
193+
184194
fp_contents = [line.rstrip('\n') for line in
185-
open(kernel_repo + '/' + file, 'r') if line.strip()]
195+
open(file_path, 'r') if line.strip()]
186196

187197
for i in range(0, len(fp_contents)):
188198
lines = fp_contents[i:i+2]

0 commit comments

Comments
 (0)