Don't magically delete lockfiles on IOError/OSError.
authorDave Borowitz <dborowitz@google.com>
Fri, 22 Jan 2010 23:44:34 +0000 (15:44 -0800)
committerDave Borowitz <dborowitz@google.com>
Tue, 9 Feb 2010 17:45:03 +0000 (09:45 -0800)
The docstring already says the only way to guarantee that lockfiles
will be deleted is close them in a finally block, so the extra magic
is redundant.

dulwich/file.py
dulwich/tests/test_file.py

index ec67ad9cb8580ff09d51e69d9dbba86e082e8c21..24fe35f83cb912d73d12ae5f441a482ee14df606 100644 (file)
@@ -68,7 +68,7 @@ class _GitFile(object):
 
     All writes to a file foo will be written into foo.lock in the same
     directory, and the lockfile will be renamed to overwrite the original file
-    on close. The lockfile is automatically removed upon filesystem error.
+    on close.
 
     :note: You *must* call close() or abort() on a _GitFile for the lock to be
         released. Typically this will happen in a finally block.
@@ -86,18 +86,7 @@ class _GitFile(object):
         self._file = os.fdopen(fd, mode, bufsize)
 
         for method in self.PROXY_METHODS:
-            setattr(self, method,
-                    self._safe_method(getattr(self._file, method)))
-
-    def _safe_method(self, file_method):
-        # note that built-in file methods have no kwargs
-        def do_safe_method(*args):
-            try:
-                return file_method(*args)
-            except (OSError, IOError):
-                self.abort()
-                raise
-        return do_safe_method
+            setattr(self, method, getattr(self._file, method))
 
     def abort(self):
         """Close and discard the lockfile without overwriting the target.
index ad1e0fbc6b808feaa05971a626baf9bc6a845e0b..43ab075564f5726b882326c7eac29a466f5ed568 100644 (file)
@@ -113,29 +113,3 @@ class GitFileTests(unittest.TestCase):
         new_orig_f = open(foo, 'rb')
         self.assertEquals(new_orig_f.read(), 'foo contents')
         new_orig_f.close()
-
-    def test_safe_method(self):
-        foo = self.path('foo')
-        foo_lock = '%s.lock' % foo
-
-        f = GitFile(foo, 'wb')
-        f.write('new contents')
-
-        def error_method(x):
-            f._test = x
-            raise IOError('fake IO error')
-
-        try:
-            f._safe_method(error_method)('test value')
-            fail()
-        except IOError, e:
-            # error is re-raised
-            self.assertEquals('fake IO error', e.message)
-
-        # method got correct args
-        self.assertEquals('test value', f._test)
-        self.assertFalse(os.path.exists(foo_lock))
-
-        new_orig_f = open(foo, 'rb')
-        self.assertEquals(new_orig_f.read(), 'foo contents')
-        new_orig_f.close()