Skip to content

Commit bee4ce5

Browse files
committed
Fix logic error in binary detection
The `get_base_bin()` function in `default_common.py` iterates through all of the entries in base.yml and for each entry checks the existence of each 'path' value in order to locate a valid binary. When the first binary path is located, Tern should break out of both loops and return the found binary value. However, due to a logic oversight Tern was only breaking out of the first loop which meant the function continued to look for valid binary paths, even after one was found. For most base OSes this is not an issue because additional binary paths will not exist. For certain base OSes like photon, however, this was problematic because both `tdnf` and `rpm` binary paths exist even though only the `tdnf` binary actually works for package metadata collection. This commit adds code to break out of the second loop once a valid binary is found. Resolves #1156 Signed-off-by: Rose Judge <[email protected]>
1 parent dd8a062 commit bee4ce5

File tree

1 file changed

+4
-0
lines changed

1 file changed

+4
-0
lines changed

tern/analyze/default/default_common.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,12 +54,16 @@ def get_base_bin(first_layer):
5454
image and looking for known binaries there. Assume that the layer has
5555
already been unpacked with the filesystem'''
5656
binary = ''
57+
found = False
5758
cwd = first_layer.get_untar_dir()
5859
for key, value in command_lib.command_lib['base'].items():
5960
for path in value['path']:
6061
if os.path.exists(os.path.join(cwd, path)):
6162
binary = key
63+
found = True
6264
break
65+
if found:
66+
break
6367
return binary
6468

6569

0 commit comments

Comments
 (0)