From 21a5ec6090db11ba04906f9f11a14467742bc670 Mon Sep 17 00:00:00 2001 From: Alexander Lakhin Date: Thu, 6 Feb 2014 20:03:04 +0400 Subject: [PATCH] Adjust links resolution for implicitly provided directories --- fill-repodb.py | 19 +++++++++++++++++++ prepare-repodb.py | 9 +++++++-- 2 files changed, 26 insertions(+), 2 deletions(-) diff --git a/fill-repodb.py b/fill-repodb.py index 332067f..f25d008 100755 --- a/fill-repodb.py +++ b/fill-repodb.py @@ -325,6 +325,7 @@ def process_package_worker(num, queue_in, generator, gen_lock, db_struct, repodi (pkg_file_paths, pkg_file_names, pkg_file_sizes, pkg_file_modes) = \ (hdr['RPMTAG_FILEPATHS'], hdr['RPMTAG_BASENAMES'], hdr['RPMTAG_FILESIZES'], hdr['RPMTAG_FILEMODES']) files_list = data['package_files'] + files_dirs = {} obj_so_files_idx = [] for i in xrange(0, len(pkg_file_paths)): file_name = pkg_file_names[i] @@ -340,7 +341,11 @@ def process_package_worker(num, queue_in, generator, gen_lock, db_struct, repodi None #mark FILE_REC_LINK_IDX = 7 ]) if pkg_file_modes[i] & RPMFILEMODE_DIRECTORY != 0: + files_dirs[file_path] = False continue + dir_name = os.path.dirname(file_path) + if dir_name not in files_dirs: + files_dirs[dir_name] = True if os.path.splitext(file_name)[1] in \ ['.debug', '.xz', '.conf', '.py', '.c', '.h', '.hpp', '.png', '.cc', '.cpp', '.sh', '.java', '.pl', '.patch', '.desktop']: @@ -352,6 +357,20 @@ def process_package_worker(num, queue_in, generator, gen_lock, db_struct, repodi (pkg_file_modes[i] & RPMFILEMODE_EXECUTE) != 0: obj_so_files_idx.append(len(files_list) - 1) + for fdir in sorted(files_dirs.keys()): + if files_dirs[fdir]: + # Add parent directories as implicit files # TODO: recursive processing? + pkg_file_id = generate_new_id(generator, gen_lock) + files_list.append([pkg_file_id, #FILE_REC_ID_IDX = 0 + pkg_id, + os.path.basename(fdir), + fdir, #FILE_REC_PATH_IDX = 3 + 0, + -1, # special mode + None, #link_to_path FILE_REC_LINK_IDX = 6 + None #mark FILE_REC_LINK_IDX = 7 + ]) + if obj_so_files_idx: pkg_temp_dir = os.path.join(temp_dir, os.path.basename(pkg)) os.makedirs(pkg_temp_dir) diff --git a/prepare-repodb.py b/prepare-repodb.py index d5fef8b..470e8e4 100755 --- a/prepare-repodb.py +++ b/prepare-repodb.py @@ -155,9 +155,14 @@ SELECT id FROM package_files WHERE path = ? AND package_id = ? if tofile: target_obj_id = tofile[0] if not target_obj_id: + # Just two level of dependency recursion - TODO: Full depth recursion? tofile = dbc.execute(""" -SELECT id FROM package_files WHERE path = ? AND package_id IN (SELECT dep_package_id FROM requires WHERE package_id = ?) -""", [target_path, pkg_id]).fetchone() +SELECT id 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]