瀏覽代碼

Avoid double close when file has already gone away in abort().

Jelmer Vernooij 15 年之前
父節點
當前提交
da2ae3d634
共有 2 個文件被更改,包括 8 次插入0 次删除
  1. 1 0
      dulwich/file.py
  2. 7 0
      dulwich/tests/test_file.py

+ 1 - 0
dulwich/file.py

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

+ 7 - 0
dulwich/tests/test_file.py

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