浏览代码

do os.fsync like recommended in the python docs (gets a fileno, not file object, also do a flush first)

Thomas Waldmann 10 年之前
父节点
当前提交
74768511e1
共有 2 个文件被更改,包括 3 次插入2 次删除
  1. 1 1
      attic/helpers.py
  2. 2 1
      attic/repository.py

+ 1 - 1
attic/helpers.py

@@ -481,7 +481,7 @@ def write_msgpack(filename, d):
     with open(filename + '.tmp', 'wb') as fd:
         msgpack.pack(d, fd)
         fd.flush()
-        os.fsync(fd)
+        os.fsync(fd.fileno())
     os.rename(filename + '.tmp', filename)
 
 

+ 2 - 1
attic/repository.py

@@ -577,6 +577,7 @@ class LoggedIO(object):
         if self._write_fd:
             self.segment += 1
             self.offset = 0
-            os.fsync(self._write_fd)
+            self._write_fd.flush()
+            os.fsync(self._write_fd.fileno())
             self._write_fd.close()
             self._write_fd = None