Skip to content

Commit 0827e61

Browse files
author
Justus Pendleton
committed
destroy blobfiles if they exist
Fixes [SF#1654132]
1 parent 5e630d6 commit 0827e61

File tree

4 files changed

+37
-10
lines changed

4 files changed

+37
-10
lines changed

roundup/backends/back_anydbm.py

Lines changed: 4 additions & 6 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.206 2007-09-11 21:33:30 jpend Exp $
18+
#$Id: back_anydbm.py,v 1.207 2007-09-16 06:51:48 jpend 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
@@ -377,6 +377,7 @@ def destroynode(self, classname, nodeid):
377377

378378
# add the destroy commit action
379379
self.transactions.append((self.doDestroyNode, (classname, nodeid)))
380+
self.transactions.append((FileStorage.destroy, (self, classname, nodeid)))
380381

381382
def serialise(self, classname, node):
382383
'''Copy the node contents, converting non-marshallable data into
@@ -718,9 +719,6 @@ def doDestroyNode(self, classname, nodeid):
718719
if db.has_key(nodeid):
719720
del db[nodeid]
720721

721-
# return the classname, nodeid so we reindex this content
722-
return (classname, nodeid)
723-
724722
def rollback(self):
725723
''' Reverse all actions from the current transaction.
726724
'''
@@ -1522,7 +1520,7 @@ def getnodeids(self, db=None, retired=None):
15221520
must_close = False
15231521
if db is None:
15241522
db = self.db.getclassdb(self.classname)
1525-
must_close = True
1523+
must_close = True
15261524
try:
15271525
res = res + db.keys()
15281526

@@ -1561,7 +1559,7 @@ def _filter(self, search_matches, filterspec, proptree,
15611559
15621560
The filter must match all properties specificed. If the property
15631561
value to match is a list:
1564-
1562+
15651563
1. String properties must match all elements in the list, and
15661564
2. Other properties must match any of the elements in the list.
15671565
"""

roundup/backends/blobfiles.py

Lines changed: 18 additions & 1 deletion
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: blobfiles.py,v 1.21 2007-09-12 16:15:40 jpend Exp $
18+
#$Id: blobfiles.py,v 1.22 2007-09-16 06:51:48 jpend Exp $
1919
'''This module exports file storage for roundup backends.
2020
Files are stored into a directory hierarchy.
2121
'''
@@ -163,4 +163,21 @@ def rollbackStoreFile(self, classname, nodeid, property, **databases):
163163
name += '.tmp'
164164
os.remove(name)
165165

166+
def isStoreFile(self, classname, nodeid):
167+
'''See if there is actually any FileStorage for this node.
168+
Is there a better way than using self.filename?
169+
'''
170+
try:
171+
fname = self.filename(classname, nodeid)
172+
return True
173+
except IOError:
174+
return False
175+
176+
def destroy(self, classname, nodeid):
177+
'''If there is actually FileStorage for this node
178+
remove it from the filesystem
179+
'''
180+
if self.isStoreFile(classname, nodeid):
181+
os.remove(self.filename(classname, nodeid))
182+
166183
# vim: set filetype=python ts=4 sw=4 et si

roundup/backends/rdbms_common.py

Lines changed: 4 additions & 1 deletion
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: rdbms_common.py,v 1.189 2007-09-11 21:33:30 jpend Exp $
18+
#$Id: rdbms_common.py,v 1.190 2007-09-16 06:51:48 jpend Exp $
1919
""" Relational database (SQL) backend common code.
2020
2121
Basics:
@@ -1025,6 +1025,9 @@ def destroynode(self, classname, nodeid):
10251025
sql = 'delete from %s__journal where nodeid=%s'%(classname, self.arg)
10261026
self.sql(sql, (nodeid,))
10271027

1028+
# cleanup any blob filestorage when we commit
1029+
self.transactions.append((FileStorage.destroy, (self, classname, nodeid)))
1030+
10281031
def hasnode(self, classname, nodeid):
10291032
""" Determine if the database has a given node.
10301033
"""

test/db_test_base.py

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,9 @@
1515
# BASIS, AND THERE IS NO OBLIGATION WHATSOEVER TO PROVIDE MAINTENANCE,
1616
# SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
1717
#
18-
# $Id: db_test_base.py,v 1.89 2007-09-03 17:14:09 jpend Exp $
18+
# $Id: db_test_base.py,v 1.90 2007-09-16 06:51:48 jpend Exp $
1919

20-
import unittest, os, shutil, errno, imp, sys, time, pprint, sets, base64
20+
import unittest, os, shutil, errno, imp, sys, time, pprint, sets, base64, os.path
2121

2222
from roundup.hyperdb import String, Password, Link, Multilink, Date, \
2323
Interval, DatabaseError, Boolean, Number, Node
@@ -548,6 +548,15 @@ def testTransactions(self):
548548
name2 = self.db.user.get('1', 'username')
549549
self.assertEqual(name1, name2)
550550

551+
def testDestroyBlob(self):
552+
# destroy an uncommitted blob
553+
f1 = self.db.file.create(content='hello', type="text/plain")
554+
self.db.commit()
555+
fn = self.db.filename('file', f1)
556+
self.db.file.destroy(f1)
557+
self.db.commit()
558+
self.assertEqual(os.path.exists(fn), False)
559+
551560
def testDestroyNoJournalling(self):
552561
self.innerTestDestroy(klass=self.db.session)
553562

0 commit comments

Comments
 (0)