From 2a1657f99a63a0e278b90c7ca9cc36f68be4969a Mon Sep 17 00:00:00 2001 From: "(no author)" <(no author)@cd1c1023-2f26-0410-ae45-c471fc1f0318> Date: Sun, 6 Jan 2008 13:44:50 +0000 Subject: [PATCH] - added additional check to client database reliability - added /etc/portage/bashrc used in 3.5 Loop 1 git-svn-id: http://svn.sabayonlinux.org/projects/entropy/trunk@1012 cd1c1023-2f26-0410-ae45-c471fc1f0318 --- client/equo | 2 +- conf/etc-portage-bashrc | 5 ++++ libraries/databaseTools.py | 50 +++++++++++++++++++++++--------------- 3 files changed, 37 insertions(+), 20 deletions(-) create mode 100644 conf/etc-portage-bashrc diff --git a/client/equo b/client/equo index dad6933cc..9a40e0fca 100644 --- a/client/equo +++ b/client/equo @@ -304,7 +304,7 @@ try: thread.kill() sys.exit(rc) except exceptionTools.SystemDatabaseError: - print_error(darkred(" * ")+red("Installed Packages Database not found. Please generate it (at least!)")) + print_error(darkred(" * ")+red("Installed Packages Database not found or is corrupted. Please generate it using 'equo database' tools")) sys.exit(100) except SystemExit: pass diff --git a/conf/etc-portage-bashrc b/conf/etc-portage-bashrc new file mode 100644 index 000000000..dd3101244 --- /dev/null +++ b/conf/etc-portage-bashrc @@ -0,0 +1,5 @@ +post_pkg_postrm() { + if [ "$SKIP_EQUO_SYNC" != "1" ]; then + equo database gentoosync + fi +} diff --git a/libraries/databaseTools.py b/libraries/databaseTools.py index 9b11e37bb..4feff7737 100644 --- a/libraries/databaseTools.py +++ b/libraries/databaseTools.py @@ -48,6 +48,9 @@ def openClientDatabase(xcache = True, generate = False, indexing = True): raise exceptionTools.SystemDatabaseError("SystemDatabaseError: system database not found. Either does not exist or corrupted.") else: conn = etpDatabase(readOnly = False, dbFile = etpConst['etpdatabaseclientfilepath'], clientDatabase = True, dbname = 'client', xcache = xcache, indexing = indexing) + # validate database + if not generate: + conn.validateDatabase() if (not etpConst['dbconfigprotect']): # config protect not prepared if (not generate): @@ -3170,25 +3173,34 @@ class etpDatabase(TextInterface): def switchBranch(self, idpackage, tobranch): - mycat = self.retrieveCategory(idpackage) - myname = self.retrieveName(idpackage) - myslot = self.retrieveSlot(idpackage) - mybranch = self.retrieveBranch(idpackage) - mydownload = self.retrieveDownloadURL(idpackage) - import re - out = re.subn('/'+mybranch+'/','/'+tobranch+'/',mydownload) - newdownload = out[0] - - # remove package with the same key+slot and tobranch if exists - match = self.atomMatch(mycat+"/"+myname, matchSlot = myslot, matchBranches = (tobranch,)) - if match[0] != -1: - self.removePackage(match[0]) - - # now switch selected idpackage to the new branch - self.cursor.execute('UPDATE baseinfo SET branch = (?) WHERE idpackage = (?)', (tobranch,idpackage,)) - self.cursor.execute('UPDATE extrainfo SET download = (?) WHERE idpackage = (?)', (newdownload,idpackage,)) - self.commitChanges() - + mycat = self.retrieveCategory(idpackage) + myname = self.retrieveName(idpackage) + myslot = self.retrieveSlot(idpackage) + mybranch = self.retrieveBranch(idpackage) + mydownload = self.retrieveDownloadURL(idpackage) + import re + out = re.subn('/'+mybranch+'/','/'+tobranch+'/',mydownload) + newdownload = out[0] + + # remove package with the same key+slot and tobranch if exists + match = self.atomMatch(mycat+"/"+myname, matchSlot = myslot, matchBranches = (tobranch,)) + if match[0] != -1: + self.removePackage(match[0]) + + # now switch selected idpackage to the new branch + self.cursor.execute('UPDATE baseinfo SET branch = (?) WHERE idpackage = (?)', (tobranch,idpackage,)) + self.cursor.execute('UPDATE extrainfo SET download = (?) WHERE idpackage = (?)', (newdownload,idpackage,)) + self.commitChanges() + + def validateDatabase(self): + self.cursor.execute('select name from SQLITE_MASTER where type = (?) and name = (?)', ("table","baseinfo")) + rslt = self.cursor.fetchone() + if rslt == None: + raise exceptionTools.SystemDatabaseError("SystemDatabaseError: table baseinfo not found. Either does not exist or corrupted.") + self.cursor.execute('select name from SQLITE_MASTER where type = (?) and name = (?)', ("table","extrainfo")) + rslt = self.cursor.fetchone() + if rslt == None: + raise exceptionTools.SystemDatabaseError("SystemDatabaseError: table extrainfo not found. Either does not exist or corrupted.") ########################################################