-
Notifications
You must be signed in to change notification settings - Fork 0
/
yum-history-user.patch
150 lines (133 loc) · 5.31 KB
/
yum-history-user.patch
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
commit 6c08159323f1a81f76ee2cb8aaa9f916fde0d710
Author: James Antill <[email protected]>
Date: Mon Mar 22 14:21:11 2010 -0400
Don't traceback when we can't open the history DB (non-root users by default
now), BZ 575917.
Provide a .readable interface for callers to check.
diff --git a/yum/history.py b/yum/history.py
index 2707cac..3ef5f74 100644
--- a/yum/history.py
+++ b/yum/history.py
@@ -178,6 +178,7 @@ class YumHistory:
self.conf = yum.misc.GenericHolder()
self.conf.db_path = os.path.normpath(root + '/' + db_path)
self.conf.writable = False
+ self.conf.readable = True
if not os.path.exists(self.conf.db_path):
try:
@@ -214,7 +215,15 @@ class YumHistory:
def _get_cursor(self):
if self._conn is None:
- self._conn = sqlite.connect(self._db_file)
+ if not self.conf.readable:
+ return None
+
+ try:
+ self._conn = sqlite.connect(self._db_file)
+ except sqlite.OperationalError:
+ self.conf.readable = False
+ return None
+
return self._conn.cursor()
def _commit(self):
return self._conn.commit()
@@ -291,6 +300,8 @@ class YumHistory:
def trans_with_pid(self, pid):
cur = self._get_cursor()
+ if cur is None:
+ return None
res = executeSQL(cur,
"""INSERT INTO trans_with_pkgs
(tid, pkgtupid)
@@ -302,6 +313,8 @@ class YumHistory:
if not hasattr(self, '_tid') or state is None:
return # Not configured to run
cur = self._get_cursor()
+ if cur is None:
+ return # Should never happen, due to above
res = executeSQL(cur,
"""INSERT INTO trans_data_pkgs
(tid, pkgtupid, state)
@@ -313,6 +326,8 @@ class YumHistory:
return # Not configured to run
cur = self._get_cursor()
+ if cur is None:
+ return # Should never happen, due to above
res = executeSQL(cur,
"""UPDATE trans_data_pkgs SET done = ?
WHERE tid = ? AND pkgtupid = ? AND state = ?
@@ -322,6 +337,8 @@ class YumHistory:
def beg(self, rpmdb_version, using_pkgs, txmbrs):
cur = self._get_cursor()
+ if cur is None:
+ return
res = executeSQL(cur,
"""INSERT INTO trans_beg
(timestamp, rpmdb_version, loginuid)
@@ -343,6 +360,8 @@ class YumHistory:
def _log_errors(self, errors):
cur = self._get_cursor()
+ if cur is None:
+ return
for error in errors:
error = to_unicode(error)
executeSQL(cur,
@@ -356,6 +375,8 @@ class YumHistory:
return # Not configured to run
cur = self._get_cursor()
+ if cur is None:
+ return # Should never happen, due to above
for error in msg.split('\n'):
error = to_unicode(error)
executeSQL(cur,
@@ -387,7 +408,11 @@ class YumHistory:
def end(self, rpmdb_version, return_code, errors=None):
assert return_code or not errors
+ if not hasattr(self, '_tid'):
+ return # Failed at beg() time
cur = self._get_cursor()
+ if cur is None:
+ return # Should never happen, due to above
res = executeSQL(cur,
"""INSERT INTO trans_end
(tid, timestamp, rpmdb_version, return_code)
@@ -444,6 +469,8 @@ class YumHistory:
""" Return a list of the last transactions, note that this includes
partial transactions (ones without an end transaction). """
cur = self._get_cursor()
+ if cur is None:
+ return []
sql = """SELECT tid,
trans_beg.timestamp AS beg_ts,
trans_beg.rpmdb_version AS beg_rv,
@@ -551,6 +578,10 @@ class YumHistory:
packages al. la. "yum list". Returns transaction ids. """
# Search packages ... kind of sucks that it's search not list, pkglist?
+ cur = self._get_cursor()
+ if cur is None:
+ return set()
+
data = _setupHistorySearchSQL(patterns, ignore_case)
(need_full, patterns, fields, names) = data
@@ -559,7 +590,6 @@ class YumHistory:
for row in self._yieldSQLDataList(patterns, fields, ignore_case):
pkgtupids.add(row[0])
- cur = self._get_cursor()
sql = """SELECT tid FROM trans_data_pkgs WHERE pkgtupid IN """
sql += "(%s)" % ",".join(['?'] * len(pkgtupids))
params = list(pkgtupids)
commit d1f047afc6bd2c7afe5f2db74f190015a7894af7
Author: James Antill <[email protected]>
Date: Wed May 5 01:14:50 2010 -0400
Catch both kinds of exceptions, on sqlite opens (RHEL-5 needs this, for one)
diff --git a/yum/history.py b/yum/history.py
index 7e0f399..cba6bf3 100644
--- a/yum/history.py
+++ b/yum/history.py
@@ -223,7 +223,7 @@ class YumHistory:
try:
self._conn = sqlite.connect(self._db_file)
- except sqlite.OperationalError:
+ except (sqlite.OperationalError, sqlite.DatabaseError):
self.conf.readable = False
return None