summaryrefslogtreecommitdiffstats
path: root/plugins
diff options
context:
space:
mode:
authorMartin Sivak <msivak@redhat.com>2008-03-19 14:35:09 +0100
committerMartin Sivak <msivak@redhat.com>2008-03-19 14:35:09 +0100
commit7d143881709efb6aaceec40734133c8df11bb95e (patch)
tree6494b81fa56549bff8cc65076aa52afb58a989c8 /plugins
parentc90e1d23cdd09c3cc6acd0aa2e4ecc2ce433b629 (diff)
downloadfirstaidkit-7d143881709efb6aaceec40734133c8df11bb95e.tar.gz
firstaidkit-7d143881709efb6aaceec40734133c8df11bb95e.tar.xz
firstaidkit-7d143881709efb6aaceec40734133c8df11bb95e.zip
Staled locks handling in rpm lowlevel plugin
Diffstat (limited to 'plugins')
-rw-r--r--plugins/plugin_rpm_lowlevel/__init__.py7
-rw-r--r--plugins/plugin_rpm_lowlevel/issue_locks.py73
2 files changed, 79 insertions, 1 deletions
diff --git a/plugins/plugin_rpm_lowlevel/__init__.py b/plugins/plugin_rpm_lowlevel/__init__.py
index a7f80ea..0dcad57 100644
--- a/plugins/plugin_rpm_lowlevel/__init__.py
+++ b/plugins/plugin_rpm_lowlevel/__init__.py
@@ -22,6 +22,7 @@ from pyfirstaidkit.reporting import PLUGIN,TASK
from pyfirstaidkit import Config
from issue_packages import Packages
+from issue_locks import Locks
class RPMLowlevelPlugin(IssuesPlugin):
"""This plugin provides lowlevel checks for RPM database."""
@@ -34,7 +35,7 @@ class RPMLowlevelPlugin(IssuesPlugin):
version = "0.0.1"
author = "Martin Sivak"
- issue_tests = [Packages]
+ issue_tests = [Packages, Locks]
set_flags = ["rpm_lowlevel"]
@classmethod
@@ -46,15 +47,19 @@ class RPMLowlevelPlugin(IssuesPlugin):
self.rpm = None
def prepare(self):
+ self.backup = self._backups.getBackup(self.__class__.__name__+" -- "+self.name)
IssuesPlugin.prepare(self)
def backup(self):
+ self.backup.backupPath(path = Config.system.root+"/var/lib/rpm", name="rpm")
self._result=ReturnSuccess
def restore(self):
+ self.backup.restorePath(path = Config.system.root+"/var/lib/rpm", name="rpm")
self._result=ReturnSuccess
def clean(self):
+ self._backups.closeBackup(self.backup._id)
self._result=ReturnSuccess
def get_plugin():
diff --git a/plugins/plugin_rpm_lowlevel/issue_locks.py b/plugins/plugin_rpm_lowlevel/issue_locks.py
new file mode 100644
index 0000000..b0a652d
--- /dev/null
+++ b/plugins/plugin_rpm_lowlevel/issue_locks.py
@@ -0,0 +1,73 @@
+# File name: issue_filesystem.py
+# Date: 2008/03/14
+# Author: Martin Sivak <msivak at redhat dot com>
+#
+# Copyright (C) Red Hat 2008
+#
+# This program is free software; you can redistribute it and/or
+# modify it under the terms of the GNU General Public License as
+# published by the Free Software Foundation; either version 2 of the
+# License, or (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful, but
+# WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+# General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# in a file called COPYING along with this program; if not, write to
+# the Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA
+# 02139, USA.
+
+from pyfirstaidkit.issue import Issue
+from pyfirstaidkit.reporting import TASK
+from pyfirstaidkit.utils import spawnvch
+from pyfirstaidkit.configuration import Config
+import os.path
+import re
+
+class Locks(Issue):
+ name = "Staled RPM locks"
+ description = "The database is still lockes, but it shouldn't be. Probably a result of some unexpectedly aborted rpm operation."
+
+ def __init__(self, *args, **kwargs):
+ Issue.__init__(self, *args, **kwargs)
+
+ def detect(self):
+ result = Issue.detect(self)
+ if result is not None:
+ return result
+
+ path = Config.system.root+"/var/lib/rpm/"
+ self.locks = []
+
+ def walkfunc(arg, dirname, fnames):
+ for f in fnames:
+ if f[:4]=="__db" and os.path.isfile(os.path.join(dirname, f)):
+ arg.append(os.path.join(dirname, f))
+
+ os.path.walk(path, walkfunc, self.locks)
+
+ if len(self.locks)==0:
+ self._happened = False
+ else:
+ self._happened = True
+
+ self._detected = True
+ return True
+
+ def fix(self):
+ result = Issue.fix(self)
+ if result is not None:
+ return result
+
+ for f in self.locks:
+ os.unlink(f)
+
+ self._fixed = True
+ return True
+
+ def reset(self):
+ Issue.reset(self)
+ self.locks = []
+