Skip to content

Commit 73a1a78

Browse files
Eduard Čubaj-mracek
authored andcommitted
[transformer] fix obsoleting packages problem caused by DB inconsistency
TRANS_DATA transformation used wrong PACKAGE_DATA ID for binding what caused, that multiple packages were tagged as Obsoleting.
1 parent cd88a63 commit 73a1a78

File tree

2 files changed

+31
-19
lines changed

2 files changed

+31
-19
lines changed

dnf/base.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -377,7 +377,7 @@ def fill_sack(self, load_system_repo=True, load_available_repos=True):
377377
self._plugins.run_sack()
378378
return self._sack
379379

380-
def _finalize_base(self):
380+
def _finalize_base(self):
381381
if not self._trans_success:
382382
for pkg, reason in self._revert_reason:
383383
self.history.set_reason(pkg, reason)

dnf/db/swdb_transformer.py

Lines changed: 30 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -66,9 +66,15 @@ def BIND_ENV_GROUP(cursor, eid, name_id):
6666

6767

6868
# YUMDB
69-
def get_yumdb_packages(cursor, yumdb_path, pid_to_pdid, repo_fn):
69+
def get_yumdb_packages(cursor, yumdb_path, repo_fn):
7070
""" Insert additional data from yumdb info SWDB """
7171

72+
# prepare pid to pdid dictionary
73+
cursor.execute("SELECT PD_ID, P_ID FROM PACKAGE_DATA")
74+
pid_to_pdid = {}
75+
for row in cursor:
76+
pid_to_pdid[row[1]] = row[0]
77+
7278
# load whole yumdb into dictionary structure
7379
pkgs = {}
7480
for path, dirs, files in os.walk(yumdb_path):
@@ -286,12 +292,6 @@ def bind_repo(cursor, name):
286292
record_PD[0] = actualPID
287293
PACKAGE_DATA_INSERT(cursor, record_PD) # insert last record
288294

289-
# integrity optimalization
290-
cursor.execute('SELECT P_ID FROM PACKAGE WHERE P_ID NOT IN (SELECT P_ID FROM PACKAGE_DATA)')
291-
tmp_row = cursor.fetchall()
292-
for row in tmp_row:
293-
cursor.execute("INSERT INTO PACKAGE_DATA VALUES(null,?,'','','','','')", (row[0],))
294-
295295
# save changes
296296
database.commit()
297297

@@ -301,34 +301,46 @@ def bind_repo(cursor, name):
301301
for row in cursor:
302302
pid_to_pdid[row[1]] = row[0]
303303

304-
obsoleting_pdids = []
304+
obsoleting_pkgs = []
305305

306306
# trans_data construction
307307
h_cursor.execute('SELECT tid, pkgtupid, done, state FROM trans_data_pkgs')
308308
for row in h_cursor:
309-
data = [''] * len(TRANS_DATA)
310309
state = row[3]
311-
pdid = pid_to_pdid.get(int(row[1]), 0)
312-
313-
# skip empty rows
314-
if not pdid:
315-
continue
310+
pid = int(row[1])
311+
tid = int(row[0])
316312

317313
# handle Obsoleting packages - save it as separate attribute
318314
if state == 'Obsoleting':
319-
obsoleting_pdids.append(pdid)
315+
obsoleting_pkgs.append((tid, pid))
320316
continue
321317

318+
data = [''] * len(TRANS_DATA)
319+
pdid = pid_to_pdid.get(pid, 0)
320+
321+
if not pdid:
322+
# create new entry
323+
cursor.execute("INSERT INTO PACKAGE_DATA VALUES (null,?,'','','','','')", (pid,))
324+
cursor.execute('SELECT last_insert_rowid()')
325+
pdid = cursor.fetchone()[0]
326+
else:
327+
# use this entry and delete it from the DB
328+
del pid_to_pdid[pid]
329+
322330
# insert trans_data record
323331
data[TRANS_DATA.index('state')] = bind_state(cursor, state)
324332
data[TRANS_DATA.index('PD_ID')] = pdid
325333
data[TRANS_DATA.index('done')] = 1 if row[2] == 'TRUE' else 0
326334
data[0] = row[0]
327335
cursor.execute('INSERT INTO TRANS_DATA VALUES (null,?,?,?,?,?,?,?)', data)
328336

337+
update_cmd = """UPDATE TRANS_DATA SET obsoleting=1 WHERE TD_ID IN (
338+
SELECT TD_ID FROM PACKAGE_DATA JOIN TRANS_DATA using (PD_ID)
339+
WHERE T_ID=? and P_ID=?)"""
340+
329341
# set flag for Obsoleting PD_IDs
330-
for pdid in obsoleting_pdids:
331-
cursor.execute('UPDATE TRANS_DATA SET obsoleting=1 WHERE PD_ID=?', (pdid,))
342+
for keys in obsoleting_pkgs:
343+
cursor.execute(update_cmd, keys)
332344

333345
# save changes
334346
database.commit()
@@ -374,7 +386,7 @@ def bind_repo(cursor, name):
374386
cursor.execute('UPDATE TRANS_DATA SET reason=? WHERE TD_ID=?', (t_reason, row[0]))
375387

376388
# fetch additional data from yumdb
377-
get_yumdb_packages(cursor, yumdb_path, pid_to_pdid, bind_repo)
389+
get_yumdb_packages(cursor, yumdb_path, bind_repo)
378390

379391
# contruction of OUTPUT
380392
h_cursor.execute('SELECT * FROM trans_script_stdout')

0 commit comments

Comments
 (0)