I have a server, written in Python, that just copies a requested file from internal storage to a Windows network share:
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 ''
When the client tries to open the file after the RPC call has returned, it sometimes fails, saying that the file isn't available:
class RCPClient():
def fetchFile(self, fileName):
filepath = server.fetchFile(targetDir, filename)
f = open(filePath) # Exception here
How come? Doesn't the fsync in the server ensure that the file is available? Is there a way to sync the folder on the network share in the client?
fsync only knows about local file-systems. It can't possibly ensure any connected client can access the file. I suggest you rewrite you application, and instead return the file directly. Thus avoiding the sync altogether, and actually simplifying client & server.