浏览代码

Compose platform_base from the platform-specific functionality

Noticed while working on the windows branch.
Marian Beermann 9 年之前
父节点
当前提交
2d90bb2c55
共有 1 个文件被更改,包括 16 次插入2 次删除
  1. 16 2
      src/borg/platform_base.py

+ 16 - 2
src/borg/platform_base.py

@@ -1,5 +1,17 @@
 import os
 import os
 
 
+"""
+platform base module
+====================
+
+Contains platform API implementations based on what Python itself provides. More specific
+APIs are stubs in this module.
+
+When functions in this module use platform APIs themselves they access the public
+platform API: that way platform APIs provided by the platform-specific support module
+are correctly composed into the base functionality.
+"""
+
 API_VERSION = 3
 API_VERSION = 3
 
 
 fdatasync = getattr(os, 'fdatasync', os.fsync)
 fdatasync = getattr(os, 'fdatasync', os.fsync)
@@ -80,16 +92,18 @@ class SyncFile:
         Synchronize file contents. Everything written prior to sync() must become durable before anything written
         Synchronize file contents. Everything written prior to sync() must become durable before anything written
         after sync().
         after sync().
         """
         """
+        from .. import platform
         self.fd.flush()
         self.fd.flush()
-        fdatasync(self.fileno)
+        platform.fdatasync(self.fileno)
         if hasattr(os, 'posix_fadvise'):
         if hasattr(os, 'posix_fadvise'):
             os.posix_fadvise(self.fileno, 0, 0, os.POSIX_FADV_DONTNEED)
             os.posix_fadvise(self.fileno, 0, 0, os.POSIX_FADV_DONTNEED)
 
 
     def close(self):
     def close(self):
         """sync() and close."""
         """sync() and close."""
+        from .. import platform
         self.sync()
         self.sync()
         self.fd.close()
         self.fd.close()
-        sync_dir(os.path.dirname(self.fd.name))
+        platform.sync_dir(os.path.dirname(self.fd.name))
 
 
 
 
 def swidth(s):
 def swidth(s):