def write_file(path, fcont, uid=None, gid=None, atomic=False):
if not atomic:
return _write_file(path, fcont, uid, gid)
tmp_path = '{path}._tmp_.{pid}_{timestamp}'.format(
path=path,
pid=os.getpid(),
timestamp=timeutil.ns(),
)
_write_file(tmp_path, fcont, uid, gid)
try:
os.rename(tmp_path, path)
except EnvironmentError:
os.remove(tmp_path)
raise
评论列表
文章目录