Commit 91daebb9 authored by Joanne Hugé's avatar Joanne Hugé

recipe/librecipe: use atomic operation to create file

At multiple occasions empty wrappers were generated
when servers (ORS) were electrically unplugged, due to
IO caching, this required manual intervention.
parent b184be00
......@@ -113,10 +113,14 @@ class GenericBaseRecipe(object):
except OSError as e:
if e.errno != errno.ENOENT:
raise
with open(name, 'wb') as f:
tmp_file = ".%s.tmp" % name
with open(tmp_file, 'wb') as f:
if mode is not None:
os.fchmod(f.fileno(), mode)
f.write(content)
f.flush()
os.fsync(f.fileno())
os.replace(tmp_file, name)
return os.path.abspath(name)
def createExecutable(self, name, content, mode=0o700):
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment