Avoid double close when file has already gone away in abort().
authorJelmer Vernooij <jelmer@samba.org>
Fri, 16 Apr 2010 17:59:52 +0000 (19:59 +0200)
committerJelmer Vernooij <jelmer@samba.org>
Fri, 16 Apr 2010 17:59:52 +0000 (19:59 +0200)
dulwich/file.py
dulwich/tests/test_file.py

index 3ba72298fff86ee9600dc5fa1e1fa4c7f62c5269..5545dd4c394656a8f3e3d326d28432de4ceffd4a 100644 (file)
@@ -143,6 +143,7 @@ class _GitFile(object):
             # The file may have been removed already, which is ok.
             if e.errno != errno.ENOENT:
                 raise
+            self._closed = True
 
     def close(self):
         """Close this file, saving the lockfile over the original.
index e9ab720838e3e7c2441aff36b9db0b4715af5448..4dcbf05b98801839f6f992535ae0fe2c661b611a 100644 (file)
@@ -188,3 +188,10 @@ class GitFileTests(unittest.TestCase):
             f.abort()
         except (IOError, OSError):
             self.fail()
+
+    def test_abort_close_removed(self):
+        foo = self.path('foo')
+        f = GitFile(foo, 'wb')
+        os.remove(foo+".lock")
+        f.abort()
+        self.assertTrue(f._closed)