【问题标题】:Is it possible to force a sync of a Windows Network Share?是否可以强制同步 Windows 网络共享?
【发布时间】:2015-05-02 16:28:47
【问题描述】:

我有一个用 Python 编写的服务器,它只是将请求的文件从内部存储复制到 Windows 网络共享:

import shutil
import os.path

class RPCServer(SimpleXMLRPCServer):
    def fetchFile(self, targetDir, fileName):
        try:
            shutil.copy(
                os.path.join(server_path, fileName)
                os.path.join(targetDir, fileName)
            )
            f = open(filepath, 'a')
            f.flush()
            os.fsync(f.fileno())
            f.close()
            return os.path.join(targetDir, fileName)
        except Exception, e:
            return ''

当客户端在 RPC 调用返回后尝试打开文件时,有时会失败,说文件不可用:

class RCPClient():
    def fetchFile(self, fileName):
        filepath = server.fetchFile(targetDir, filename)
        f = open(filePath) # Exception here

怎么会?服务器中的 fsync 不能确保文件可用吗?有没有办法在客户端同步网络共享上的文件夹?

【问题讨论】:

    标签: python smb


    【解决方案1】:

    fsync 只知道本地文件系统。它不可能确保任何连接的客户端都可以访问该文件。我建议你重写你的应用程序,而不是直接返回文件。从而完全避免了同步,实际上简化了客户端和服务器。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2010-10-10
      • 1970-01-01
      • 1970-01-01
      • 2010-10-08
      • 1970-01-01
      • 1970-01-01
      • 2010-09-21
      • 1970-01-01
      相关资源
      最近更新 更多