Forráskód Böngészése

Don't magically delete lockfiles on IOError/OSError.

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.
Dave Borowitz 15 éve
szülő
commit
d6d8b583fa
2 módosított fájl, 2 hozzáadás és 39 törlés
  1. 2 13
      dulwich/file.py
  2. 0 26
      dulwich/tests/test_file.py

+ 2 - 13
dulwich/file.py

@@ -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.

+ 0 - 26
dulwich/tests/test_file.py

@@ -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()