diff --git a/prepare-repodb.py b/prepare-repodb.py index 470e8e4..f0371b7 100755 --- a/prepare-repodb.py +++ b/prepare-repodb.py @@ -146,25 +146,40 @@ SELECT packages.id AS package_id, packages.name AS package_name, packages.nvra, for file_link in package_files_links: pkg_id = file_link[0] pkg_name = file_link[1] + pkg_nvra = file_link[2] object_id = file_link[3] - target_path = os.path.normpath(file_link[5]) target_obj_id = None - tofile = dbc.execute(""" -SELECT id FROM package_files WHERE path = ? AND package_id = ? -""", [target_path, pkg_id]).fetchone() - if tofile: - target_obj_id = tofile[0] - if not target_obj_id: - # Just two level of dependency recursion - TODO: Full depth recursion? + target_path = os.path.normpath(file_link[5]) + target_paths = {} + target_paths[target_path] = True + while target_path != '': + new_target_path = None tofile = dbc.execute(""" -SELECT id FROM package_files WHERE path = ? AND package_id IN ( +SELECT id, link_to_path FROM package_files WHERE path = ? AND package_id = ? +""", [target_path, pkg_id]).fetchone() + if tofile: + target_obj_id = tofile[0] + new_target_path = tofile[1] + if not target_obj_id: + # Just two level of dependency recursion - TODO: Full depth recursion? + tofile = dbc.execute(""" +SELECT id, link_to_path FROM package_files WHERE path = ? AND package_id IN ( SELECT dep_package_id FROM requires WHERE package_id = ? UNION SELECT dep_package_id FROM requires WHERE package_id IN (SELECT dep_package_id FROM requires WHERE package_id = ?) ) """, [target_path, pkg_id, pkg_id]).fetchone() - if tofile: - target_obj_id = tofile[0] + if tofile: + target_obj_id = tofile[0] + new_target_path = tofile[1] + if new_target_path is None: + break + target_path = os.path.normpath(new_target_path) + if target_path in target_paths: + print 'Link loop detected! %s: %s -> %s' % (pkg_nvra, file_link[5], target_path) + target_obj_id = None + break + target_paths[target_path] = True if target_obj_id: dbc.execute(""" @@ -229,11 +244,12 @@ def process_repodir_obj_symbols(dbc, repodir_id, repodir_name, repodir_depends): # EXPLAIN QUERY PLAN dbc.execute(""" INSERT INTO obj_symbols_res(obj_sym_id, dep_obj_sym_id, res_type) -SELECT sos.id, tos.id, 1 FROM packages CROSS JOIN package_files CROSS JOIN obj_symbols sos CROSS JOIN - so_needed CROSS JOIN so_needed_res CROSS JOIN obj_symbols tos - WHERE packages.repodir_id = ? AND packages.id = package_files.package_id AND package_files.id = sos.obj_file_id AND +SELECT sos.id, tos.id, 1 FROM packages CROSS JOIN package_files spf CROSS JOIN obj_symbols sos CROSS JOIN + so_needed CROSS JOIN so_needed_res CROSS JOIN package_files tpf CROSS JOIN obj_symbols tos + WHERE packages.repodir_id = ? AND packages.id = spf.package_id AND spf.id = sos.obj_file_id AND sos.sym_type = 0 AND sos.obj_file_id = so_needed.obj_file_id AND so_needed.id = so_needed_res.so_needed_id AND - so_needed_res.res_type = 1 AND so_needed_res.dep_obj_file_id = tos.obj_file_id AND + so_needed_res.res_type = 1 AND so_needed_res.dep_obj_file_id = tpf.id AND + (tos.obj_file_id = tpf.id OR tos.obj_file_id = tpf.link_to_file_id) AND tos.sym_type = 1 AND tos.name = sos.name """, [repodir_id]) print 'Searching symbols resolutions (2)...'