Commit 34b88faf authored by Barry Warsaw's avatar Barry Warsaw

CommitLog.__init__(): Use an unlink flag to record what the behavior

should be on close.  By default, we unlink the file unless we were
passed a file-like object, in which case we don't unlink by default
(because the client owns the file).

close(): Only close the file if the file isn't already closed.  Only
unlink if the default unlink flag is true, or we're explicitly told to
unlink via the argument.  This should fix the logfile turd problem.
parent b5684ba7
...@@ -121,6 +121,7 @@ class CommitLog: ...@@ -121,6 +121,7 @@ class CommitLog:
# BAW: is our filename unique enough? Are we opening it up with too # BAW: is our filename unique enough? Are we opening it up with too
# much or too little security? # much or too little security?
self._unlink = 1
if file is None: if file is None:
# Create the file from scratch. We know the file has to be in the # Create the file from scratch. We know the file has to be in the
# init state, so just go ahead and write the appropriate header. # init state, so just go ahead and write the appropriate header.
...@@ -161,6 +162,7 @@ class CommitLog: ...@@ -161,6 +162,7 @@ class CommitLog:
# log. Read the file's header and initialize our state from it. # log. Read the file's header and initialize our state from it.
self._fp = file self._fp = file
self._readhead() self._readhead()
self._unlink = 0
def get_filename(self): def get_filename(self):
return self._fp.name return self._fp.name
...@@ -266,14 +268,16 @@ class CommitLog: ...@@ -266,14 +268,16 @@ class CommitLog:
def next(self): def next(self):
raise NotImplementedError raise NotImplementedError
def close(self, unlink=0): def close(self, unlink=1):
"""Close the file. """Close the file.
If unlink is true, delete the underlying file object too. If unlink is true, delete the underlying file object too.
""" """
if self._fp:
self._fp.close() self._fp.close()
if unlink: if unlink or self._unlink:
os.unlink(self._fp.name) os.unlink(self._fp.name)
self._fp = None
def __del__(self): def __del__(self):
# Unsafe, and file preserving close # Unsafe, and file preserving close
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment