Skip to content

Commit 348839c

Browse files
author
Richard Jones
committed
postgres backend open doesn't hide corruption in schema [SF#956375]
*dbm-style backends nuke() method now clear id counters
1 parent a019d52 commit 348839c

File tree

8 files changed

+41
-16
lines changed

8 files changed

+41
-16
lines changed

CHANGES.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,10 @@ Feature:
2929
- relaxed hyperlinking in web interface (accept "issue123" or "Issue 123")
3030
- record journaltag lookup ("fixes" sf bug 998140)
3131

32+
Fixed:
33+
- postgres backend open doesn't hide corruption in schema (sf bug 956375)
34+
- *dbm-style backends nuke() method now clear id counters
35+
3236

3337
2004-??-?? 0.7.7
3438
Fixed:

roundup/admin.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
# BASIS, AND THERE IS NO OBLIGATION WHATSOEVER TO PROVIDE MAINTENANCE,
1717
# SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
1818
#
19-
# $Id: admin.py,v 1.78 2004-07-28 05:00:30 richard Exp $
19+
# $Id: admin.py,v 1.79 2004-10-08 05:37:44 richard Exp $
2020

2121
'''Administration commands for maintaining Roundup trackers.
2222
'''
@@ -453,9 +453,14 @@ def do_initialise(self, tracker_home, args):
453453
if ok.strip().lower() != 'y':
454454
return 0
455455

456+
backend = tracker.get_backend_name()
457+
456458
# nuke it
457459
tracker.nuke()
458460

461+
# re-write the backend select file
462+
init.write_select_db(tracker_home, backend)
463+
459464
# GO
460465
tracker.init(password.Password(adminpw))
461466

roundup/backends/back_anydbm.py

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
# BASIS, AND THERE IS NO OBLIGATION WHATSOEVER TO PROVIDE MAINTENANCE,
1616
# SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
1717
#
18-
#$Id: back_anydbm.py,v 1.172 2004-09-29 07:09:13 a1s Exp $
18+
#$Id: back_anydbm.py,v 1.173 2004-10-08 05:37:44 richard Exp $
1919
'''This module defines a backend that saves the hyperdatabase in a
2020
database chosen by anydbm. It is guaranteed to always be available in python
2121
versions >2.1.1 (the dumbdbm fallback in 2.1.1 and earlier has several
@@ -46,12 +46,12 @@
4646
def db_exists(config):
4747
# check for the user db
4848
for db in 'nodes.user nodes.user.db'.split():
49-
if os.path.exists(os.path.join(config.TRACKER_HOME, 'db', db)):
49+
if os.path.exists(os.path.join(config.DATABASE, db)):
5050
return 1
5151
return 0
5252

5353
def db_nuke(config):
54-
shutil.rmtree(os.path.join(config.TRACKER_HOME, 'db'))
54+
shutil.rmtree(config.DATABASE)
5555

5656
#
5757
# Now the database
@@ -185,6 +185,12 @@ def clear(self):
185185
os.remove(path)
186186
elif os.path.exists(path+'.db'): # dbm appends .db
187187
os.remove(path+'.db')
188+
# reset id sequences
189+
path = os.path.join(os.getcwd(), self.dir, '_ids')
190+
if os.path.exists(path):
191+
os.remove(path)
192+
elif os.path.exists(path+'.db'): # dbm appends .db
193+
os.remove(path+'.db')
188194

189195
def getclassdb(self, classname, mode='r'):
190196
''' grab a connection to the class db that will be used for

roundup/backends/back_bsddb.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
# BASIS, AND THERE IS NO OBLIGATION WHATSOEVER TO PROVIDE MAINTENANCE,
1616
# SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
1717
#
18-
#$Id: back_bsddb.py,v 1.32 2004-07-27 01:59:28 richard Exp $
18+
#$Id: back_bsddb.py,v 1.33 2004-10-08 05:37:44 richard Exp $
1919
'''This module defines a backend that saves the hyperdatabase in BSDDB.
2020
'''
2121
__docformat__ = 'restructuredtext'
@@ -27,10 +27,10 @@
2727
from back_anydbm import Database, Class, FileClass, IssueClass
2828

2929
def db_exists(config):
30-
return os.path.exists(os.path.join(config.TRACKER_HOME, 'db', 'nodes.user'))
30+
return os.path.exists(os.path.join(config.DATABASE, 'nodes.user'))
3131

3232
def db_nuke(config):
33-
shutil.rmtree(os.path.join(config.TRACKER_HOME, 'db'))
33+
shutil.rmtree(config.DATABASE)
3434

3535
#
3636
# Now the database
@@ -46,6 +46,8 @@ def clear(self):
4646
bsddb.btopen(db, 'n')
4747
db = os.path.join(self.dir, 'journals.%s'%cn)
4848
bsddb.btopen(db, 'n')
49+
# reset id sequences
50+
os.remove(os.path.join(os.getcwd(), self.dir, '_ids'))
4951

5052
def getclassdb(self, classname, mode='r'):
5153
''' grab a connection to the class db that will be used for

roundup/backends/back_bsddb3.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
# BASIS, AND THERE IS NO OBLIGATION WHATSOEVER TO PROVIDE MAINTENANCE,
1616
# SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
1717
#
18-
#$Id: back_bsddb3.py,v 1.26 2004-07-27 01:59:28 richard Exp $
18+
#$Id: back_bsddb3.py,v 1.27 2004-10-08 05:37:44 richard Exp $
1919
'''This module defines a backend that saves the hyperdatabase in BSDDB3.
2020
'''
2121
__docformat__ = 'restructuredtext'
@@ -27,10 +27,10 @@
2727
from back_anydbm import Database, Class, FileClass, IssueClass
2828

2929
def db_exists(config):
30-
return os.path.exists(os.path.join(config.TRACKER_HOME, 'db', 'nodes.user'))
30+
return os.path.exists(os.path.join(config.DATABASE, 'nodes.user'))
3131

3232
def db_nuke(config):
33-
shutil.rmtree(os.path.join(config.TRACKER_HOME, 'db'))
33+
shutil.rmtree(config.DATABASE)
3434

3535
#
3636
# Now the database
@@ -48,6 +48,8 @@ def clear(self):
4848
except os.error, error:
4949
if error.errno != errno.ENOENT:
5050
raise
51+
# reset id sequences
52+
os.remove(os.path.join(os.getcwd(), self.dir, '_ids'))
5153

5254
def getclassdb(self, classname, mode='r'):
5355
''' grab a connection to the class db that will be used for

roundup/backends/back_postgresql.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,9 @@ def open_connection(self):
102102

103103
try:
104104
self.load_dbschema()
105-
except:
105+
except psycopg.ProgrammingError, message:
106+
if '"schema" does not exist' not in str(message):
107+
raise
106108
self.rollback()
107109
self.init_dbschema()
108110
self.sql("CREATE TABLE schema (schema TEXT)")

roundup/backends/back_sqlite.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# $Id: back_sqlite.py,v 1.33 2004-10-07 06:30:20 richard Exp $
1+
# $Id: back_sqlite.py,v 1.34 2004-10-08 05:37:44 richard Exp $
22
'''Implements a backend for SQLite.
33
44
See https://pysqlite.sourceforge.net/ for pysqlite info
@@ -17,10 +17,10 @@
1717
import sqlite
1818

1919
def db_exists(config):
20-
return os.path.exists(os.path.join(config.TRACKER_HOME, 'db', 'db'))
20+
return os.path.exists(os.path.join(config.DATABASE, 'db'))
2121

2222
def db_nuke(config):
23-
shutil.rmtree(os.path.join(config.TRACKER_HOME, 'db'))
23+
shutil.rmtree(config.DATABASE)
2424

2525
class Database(rdbms_common.Database):
2626
# char to use for positional arguments

roundup/instance.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
# BASIS, AND THERE IS NO OBLIGATION WHATSOEVER TO PROVIDE MAINTENANCE,
1616
# SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
1717
#
18-
# $Id: instance.py,v 1.23 2004-09-29 07:26:17 a1s Exp $
18+
# $Id: instance.py,v 1.24 2004-10-08 05:37:44 richard Exp $
1919

2020
'''Tracker handling (open tracker).
2121
@@ -39,11 +39,15 @@ def __init__(self, tracker_home):
3939
self.cgi_actions = {}
4040
self.templating_utils = {}
4141

42-
def get_backend(self):
42+
def get_backend_name(self):
4343
o = __builtins__['open']
4444
f = o(os.path.join(self.tracker_home, 'db', 'backend_name'))
4545
name = f.readline().strip()
4646
f.close()
47+
return name
48+
49+
def get_backend(self):
50+
name = self.get_backend_name()
4751
return getattr(backends, name)
4852

4953
def open(self, name):

0 commit comments

Comments
 (0)