Permalink
Browse files

Simplified File constructor.

  • Loading branch information...
1 parent 3d31d18 commit c37e13d69389b56d7531efffc31229356f7ff7ee @rcrowley committed Jan 19, 2010
Showing with 14 additions and 12 deletions.
  1. +14 −12 countd/commitlog/file.py
View
@@ -34,27 +34,29 @@ def __init__(self, index, flags, create=False):
pathname1 = "{0}/{1:010}".format(settings.DIRNAME, self.index)
pathname2 = "{0}/lock-{1:010}".format(settings.DIRNAME, self.index)
- # Try to lock the file at this index using a hardlink.
+ # Try to lock the commit log at this index using a hardlink.
try:
os.link(pathname1, pathname2)
- self.fd = os.open(pathname2, flags)
- # If it can't be done and the file exists, throw the error.
- # Otherwise, create and preallocate the file.
- # FIXME This is the single block of code that's not correct
- # Python 3.
+ # Couldn't lock the commit log so try to create it. If it can't be
+ # created, os.open will raise and OSError and the calling code must
+ # skip this commit log for now.
+ # FIXME This is not Python3-friendly.
except OSError, e:
if not create:
raise e
- try:
- s = os.stat(pathname1)
- except OSError:
- s = None
- if s is not None:
- raise e
self.fd = os.open(pathname2, flags | self.CREAT, self.CLEAN)
self.fill()
os.link(pathname2, pathname1)
+ return
+
+ # Try to open the commit log. If there is a permissions mismatch,
+ # unlock the file and re-raise the OSError.
+ try:
+ self.fd = os.open(pathname2, flags)
+ except OSError, e:
+ os.unlink("{0}/lock-{1:010}".format(settings.DIRNAME, self.index))
+ raise e
def __del__(self):
"""

0 comments on commit c37e13d

Please sign in to comment.