yifengyou / rpms / yum

Forked from rpms/yum 3 years ago
Clone

Blame SOURCES/BZ-1095157-traceback-when-empty-history.patch

d2a170
commit 1c557629752d26dca86948c5e933d8f31448818d
d2a170
Author: Valentina Mukhamedzhanova <vmukhame@redhat.com>
d2a170
Date:   Thu Apr 17 16:15:22 2014 +0200
d2a170
d2a170
    Fix traceback when the history dir is empty. BZ 875610
d2a170
d2a170
diff --git a/yum/history.py b/yum/history.py
d2a170
index 3f20128..2f423d9 100644
d2a170
--- a/yum/history.py
d2a170
+++ b/yum/history.py
d2a170
@@ -697,7 +697,9 @@ class YumHistory:
d2a170
             break
d2a170
 
d2a170
         if self._db_file is None:
d2a170
-            self._create_db_file()
d2a170
+            if not self._create_db_file():
d2a170
+                # Couldn't create a db file
d2a170
+                return
d2a170
         
d2a170
         # make an addon path for where we're going to stick 
d2a170
         # random additional history info - probably from plugins and what-not
d2a170
@@ -1603,8 +1605,10 @@ class YumHistory:
d2a170
             if os.path.exists(_db_file + '-journal'):
d2a170
                 os.rename(_db_file  + '-journal', _db_file + '-journal.old')
d2a170
         self._db_file = _db_file
d2a170
+        if not self.conf.writable:
d2a170
+            return False
d2a170
         
d2a170
-        if self.conf.writable and not os.path.exists(self._db_file):
d2a170
+        if not os.path.exists(self._db_file):
d2a170
             # make them default to 0600 - sysadmin can change it later
d2a170
             # if they want
d2a170
             fo = os.open(self._db_file, os.O_CREAT, 0600)
d2a170
@@ -1659,6 +1663,7 @@ class YumHistory:
d2a170
         for op in self._update_ops_3:
d2a170
             cur.execute(op)
d2a170
         self._commit()
d2a170
+        return True
d2a170
 
d2a170
 # Pasted from sqlitesack
d2a170
 _FULL_PARSE_QUERY_BEG = """
d2a170
commit 8c6cd83a4825155d1ee9ddcd29b023682944e3e6
d2a170
Author: Valentina Mukhamedzhanova <vmukhame@redhat.com>
d2a170
Date:   Wed Mar 12 15:41:30 2014 +0100
d2a170
d2a170
    Fix traceback when history files don't exist and user is not root.
d2a170
d2a170
diff --git a/yum/history.py b/yum/history.py
d2a170
index 6f60f54..3f20128 100644
d2a170
--- a/yum/history.py
d2a170
+++ b/yum/history.py
d2a170
@@ -668,6 +668,7 @@ class YumHistory:
d2a170
 
d2a170
         self.releasever = releasever
d2a170
 
d2a170
+        self._db_file = None
d2a170
         if not os.path.exists(self.conf.db_path):
d2a170
             try:
d2a170
                 os.makedirs(self.conf.db_path)
d2a170
@@ -680,7 +681,6 @@ class YumHistory:
d2a170
                 self.conf.writable = True
d2a170
 
d2a170
         DBs = glob.glob('%s/history-*-*-*.sqlite' % self.conf.db_path)
d2a170
-        self._db_file = None
d2a170
         for d in reversed(sorted(DBs)):
d2a170
             fname = os.path.basename(d)
d2a170
             fname = fname[len("history-"):-len(".sqlite")]
d2a170
diff --git a/yumcommands.py b/yumcommands.py
d2a170
index 4e72a71..75b3ce2 100644
d2a170
--- a/yumcommands.py
d2a170
+++ b/yumcommands.py
d2a170
@@ -3051,7 +3051,7 @@ class HistoryCommand(YumCommand):
d2a170
         if extcmds and extcmds[0] in ('repeat', 'redo', 'undo', 'rollback', 'new'):
d2a170
             checkRootUID(base)
d2a170
             checkGPGKey(base)
d2a170
-        elif not os.access(base.history._db_file, os.R_OK):
d2a170
+        elif not (base.history._db_file and os.access(base.history._db_file, os.R_OK)):
d2a170
             base.logger.critical(_("You don't have access to the history DB."))
d2a170
             raise cli.CliError
d2a170