浏览代码

Fix incorrect read/write handling in "object_store.py".

When using C stdio library, the stream must be flushed or repositioned before
switching from write operations to read operations or vv. This applies to
CPython as well since "File objects are implemented using C’s stdio package".
http://docs.python.org/library/stdtypes.html#file-objects

See also http://bugs.python.org/issue3207.

DiskObjectStore._complete_thin_pack() didn't follow these rules which made the
test

  dulwich.tests.test_object_store.DiskObjectStoreTests:test_add_thin_pack

fail with

  IOError: [Errno 0] Error

on Windows.
Risto Kankkunen 13 年之前
父节点
当前提交
0553f7723b
共有 1 个文件被更改,包括 6 次插入0 次删除
  1. 6 0
      dulwich/object_store.py

+ 6 - 0
dulwich/object_store.py

@@ -471,9 +471,15 @@ class DiskObjectStore(PackBasedObjectStore):
         f.seek(0)
         write_pack_header(f, len(entries) + len(indexer.ext_refs()))
 
+        # Must flush before reading (http://bugs.python.org/issue3207)
+        f.flush()
+
         # Rescan the rest of the pack, computing the SHA with the new header.
         new_sha = compute_file_sha(f, end_ofs=-20)
 
+        # Must reposition before writing (http://bugs.python.org/issue3207)
+        f.seek(0, os.SEEK_CUR)
+
         # Complete the pack.
         for ext_sha in indexer.ext_refs():
             assert len(ext_sha) == 20