Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Prevent inconsistent data in json files. #74

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 8 additions & 4 deletions backend.py
Original file line number Diff line number Diff line change
Expand Up @@ -136,18 +136,22 @@ def extract_tunnel(nodes):
batadv_graph = graph.merge_nodes(batadv_graph)
batadv_graph = graph.to_undirected(batadv_graph)

# write processed data to dest dir
with open(nodes_fn, 'w') as f:
# write processed data to temporary files in dest dir
# and rename them atomically to prevent inconsistent data
with open(nodes_fn + '.tmp', 'w') as f:
json.dump(nodedb, f)
os.rename(nodes_fn + '.tmp', nodes_fn)

graph_out = {'batadv': json_graph.node_link_data(batadv_graph),
'version': GRAPH_VERSION}

with open(graph_fn, 'w') as f:
with open(graph_fn + '.tmp', 'w') as f:
json.dump(graph_out, f)
os.rename(graph_fn + '.tmp', graph_fn)

with open(nodelist_fn, 'w') as f:
with open(nodelist_fn + 'tmp', 'w') as f:
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is a '.' missing in front of the tmp'

json.dump(export_nodelist(now, nodedb), f)
os.rename(nodelist_fn + '.tmp', nodelist_fn)

# optional rrd graphs (trigger with --rrd)
if params['rrd']:
Expand Down