forked from distributed-system-analysis/smallfile
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsync_files.py
38 lines (31 loc) · 1.16 KB
/
sync_files.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
#!/usr/bin/python
# -*- coding: utf-8 -*-
import os
import pickle
import shutil
import time
import smallfile
def write_sync_file(fpath, contents):
with open(fpath, 'w') as sgf:
sgf.write(contents)
sgf.flush()
os.fsync(sgf.fileno()) # file should close when you exit with block
def write_pickle(fpath, obj):
with open(fpath, 'wb') as result_file:
pickle.dump(obj, result_file)
result_file.flush()
os.fsync(result_file.fileno()) # or else reader may not see data
def create_top_dirs(master_invoke, is_multi_host):
if os.path.exists(master_invoke.network_dir):
shutil.rmtree(master_invoke.network_dir)
if is_multi_host:
# so all remote clients see that directory was recreated
time.sleep(2.1)
smallfile.ensure_dir_exists(master_invoke.network_dir)
for dlist in [master_invoke.src_dirs, master_invoke.dest_dirs]:
for d in dlist:
smallfile.ensure_dir_exists(d)
if is_multi_host:
# workaround to force cross-host synchronization
os.listdir(master_invoke.network_dir)
time.sleep(1.1) # lets NFS mount option actimeo=1 take effect