Skip to content

Commit 98d1077

Browse files
committed
Fix issue2550510
1 parent e9b4eda commit 98d1077

File tree

1 file changed

+37
-27
lines changed

1 file changed

+37
-27
lines changed

roundup/backends/blobfiles.py

Lines changed: 37 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,9 @@
1515
# BASIS, AND THERE IS NO OBLIGATION WHATSOEVER TO PROVIDE MAINTENANCE,
1616
# SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
1717
#
18-
#$Id: blobfiles.py,v 1.24 2008-02-07 00:57:59 richard Exp $
19-
'''This module exports file storage for roundup backends.
18+
"""This module exports file storage for roundup backends.
2019
Files are stored into a directory hierarchy.
21-
'''
20+
"""
2221
__docformat__ = 'restructuredtext'
2322

2423
import os
@@ -232,14 +231,28 @@ def _tempfile(self, filename):
232231

233232
return filename + self.tempext
234233

234+
def _editInProgress(self, classname, nodeid, property):
235+
"""Return true if the file indicated is being edited.
236+
237+
returns -- True if the current transaction includes an edit to
238+
the file indicated."""
239+
240+
for method, args in self.transactions:
241+
if (method == self.doStoreFile and
242+
args == (classname, nodeid, property)):
243+
return True
244+
245+
return False
246+
247+
235248
def filename(self, classname, nodeid, property=None, create=0):
236-
'''Determine what the filename for the given node and optionally
249+
"""Determine what the filename for the given node and optionally
237250
property is.
238251
239252
Try a variety of different filenames - the file could be in the
240253
usual place, or it could be in a temp file pre-commit *or* it
241254
could be in an old-style, backwards-compatible flat directory.
242-
'''
255+
"""
243256
filename = os.path.join(self.dir, 'files', classname,
244257
self.subdirFilename(classname, nodeid, property))
245258
# If the caller is going to create the file, return the
@@ -252,13 +265,10 @@ def filename(self, classname, nodeid, property=None, create=0):
252265

253266
# If an edit to this file is in progress, then return the name
254267
# of the temporary file containing the edited content.
255-
for method, args in self.transactions:
256-
if (method == self.doStoreFile and
257-
args == (classname, nodeid, property)):
258-
# There is an edit in progress for this file.
259-
if not os.path.exists(tempfile):
260-
raise IOError('content file for %s not found'%tempfile)
261-
return tempfile
268+
if self._editInProgress(classname, nodeid, property):
269+
if not os.path.exists(tempfile):
270+
raise IOError('content file for %s not found'%tempfile)
271+
return tempfile
262272

263273
if os.path.exists(filename):
264274
return filename
@@ -295,10 +305,10 @@ def filename(self, classname, nodeid, property=None, create=0):
295305
raise IOError('content file for %s not found'%filename)
296306

297307
def storefile(self, classname, nodeid, property, content):
298-
'''Store the content of the file in the database. The property may be
308+
"""Store the content of the file in the database. The property may be
299309
None, in which case the filename does not indicate which property
300310
is being saved.
301-
'''
311+
"""
302312
# determine the name of the file to write to
303313
name = self.filename(classname, nodeid, property, create=1)
304314

@@ -310,7 +320,7 @@ def storefile(self, classname, nodeid, property, content):
310320
name = self._tempfile(name)
311321

312322
# make sure we don't register the rename action more than once
313-
if not os.path.exists(name):
323+
if not self._editInProgress(classname, nodeid, property):
314324
# save off the rename action
315325
self.transactions.append((self.doStoreFile, (classname, nodeid,
316326
property)))
@@ -321,8 +331,8 @@ def storefile(self, classname, nodeid, property, content):
321331
open(name, 'wb').write(content)
322332

323333
def getfile(self, classname, nodeid, property):
324-
'''Get the content of the file in the database.
325-
'''
334+
"""Get the content of the file in the database.
335+
"""
326336
filename = self.filename(classname, nodeid, property)
327337

328338
f = open(filename, 'rb')
@@ -333,14 +343,14 @@ def getfile(self, classname, nodeid, property):
333343
f.close()
334344

335345
def numfiles(self):
336-
'''Get number of files in storage, even across subdirectories.
337-
'''
346+
"""Get number of files in storage, even across subdirectories.
347+
"""
338348
files_dir = os.path.join(self.dir, 'files')
339349
return files_in_dir(files_dir)
340350

341351
def doStoreFile(self, classname, nodeid, property, **databases):
342-
'''Store the file as part of a transaction commit.
343-
'''
352+
"""Store the file as part of a transaction commit.
353+
"""
344354
# determine the name of the file to write to
345355
name = self.filename(classname, nodeid, property, 1)
346356

@@ -364,28 +374,28 @@ def doStoreFile(self, classname, nodeid, property, **databases):
364374
return (classname, nodeid)
365375

366376
def rollbackStoreFile(self, classname, nodeid, property, **databases):
367-
'''Remove the temp file as a part of a rollback
368-
'''
377+
"""Remove the temp file as a part of a rollback
378+
"""
369379
# determine the name of the file to delete
370380
name = self.filename(classname, nodeid, property)
371381
if not name.endswith(self.tempext):
372382
name += self.tempext
373383
os.remove(name)
374384

375385
def isStoreFile(self, classname, nodeid):
376-
'''See if there is actually any FileStorage for this node.
386+
"""See if there is actually any FileStorage for this node.
377387
Is there a better way than using self.filename?
378-
'''
388+
"""
379389
try:
380390
fname = self.filename(classname, nodeid)
381391
return True
382392
except IOError:
383393
return False
384394

385395
def destroy(self, classname, nodeid):
386-
'''If there is actually FileStorage for this node
396+
"""If there is actually FileStorage for this node
387397
remove it from the filesystem
388-
'''
398+
"""
389399
if self.isStoreFile(classname, nodeid):
390400
os.remove(self.filename(classname, nodeid))
391401

0 commit comments

Comments
 (0)